Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: sdk/lib/collection/maps.dart

Issue 18072004: Add fromIterable(s) constructors in SplayTreeMap and LinkedHashMap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed long line. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/collection/linked_hash_map.dart ('k') | sdk/lib/collection/splay_tree.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.collection; 5 part of dart.collection;
6 6
7 /* 7 /*
8 * Helper class which implements complex [Map] operations 8 * Helper class which implements complex [Map] operations
9 * in term of basic ones ([Map.keys], [Map.operator []], 9 * in term of basic ones ([Map.keys], [Map.operator []],
10 * [Map.operator []=] and [Map.remove].) Not all methods are 10 * [Map.operator []=] and [Map.remove].) Not all methods are
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 * directly as a key or value, or indirectly through other collections 70 * directly as a key or value, or indirectly through other collections
71 * or maps, the contained reference is rendered as [:'{...}':]. This 71 * or maps, the contained reference is rendered as [:'{...}':]. This
72 * prevents the infinite regress that would otherwise occur. So, for example, 72 * prevents the infinite regress that would otherwise occur. So, for example,
73 * calling this method on a map whose sole entry maps the string key 'me' 73 * calling this method on a map whose sole entry maps the string key 'me'
74 * to a reference to the map would return [:'{me: {...}}':]. 74 * to a reference to the map would return [:'{me: {...}}':].
75 * 75 *
76 * A typical implementation of a map's [toString] method will 76 * A typical implementation of a map's [toString] method will
77 * simply return the results of this method applied to the collection. 77 * simply return the results of this method applied to the collection.
78 */ 78 */
79 static String mapToString(Map m) => ToString.mapToString(m); 79 static String mapToString(Map m) => ToString.mapToString(m);
80
81 static _id(x) => x;
82
83 /**
84 * Fills a map with key/value pairs computed from [iterable].
85 *
86 * This method is used by Map classes in the named constructor fromIterable.
87 */
88 static void _fillMapWithMappedIterable(Map map, Iterable iterable,
89 key(element), value(element)) {
90 if (key == null) key = _id;
91 if (value == null) value = _id;
92
93 for (var element in iterable) {
94 map[key(element)] = value(element);
95 }
96 }
97
98 /**
99 * Fills a map by associating the [keys] to [values].
100 *
101 * This method is used by Map classes in the named constructor fromIterables.
102 */
103 static void _fillMapWithIterables(Map map, Iterable keys,
104 Iterable values) {
105 Iterator keyIterator = keys.iterator;
106 Iterator valueIterator = values.iterator;
107
108 bool hasNextKey = keyIterator.moveNext();
109 bool hasNextValue = valueIterator.moveNext();
110
111 while (hasNextKey && hasNextValue) {
112 map[keyIterator.current] = valueIterator.current;
113 hasNextKey = keyIterator.moveNext();
114 hasNextValue = valueIterator.moveNext();
115 }
116
117 if (hasNextKey || hasNextValue) {
118 throw new ArgumentError("Iterables do not have same length.");
119 }
120 }
80 } 121 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/linked_hash_map.dart ('k') | sdk/lib/collection/splay_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698