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

Unified Diff: sdk/lib/collection/splay_tree.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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/maps.dart ('k') | sdk/lib/core/map.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/splay_tree.dart
diff --git a/sdk/lib/collection/splay_tree.dart b/sdk/lib/collection/splay_tree.dart
index 84e61e10d4386e01a8e85514a643374b22ad59d9..7dac687f20874217751452209be66a4e82c23445 100644
--- a/sdk/lib/collection/splay_tree.dart
+++ b/sdk/lib/collection/splay_tree.dart
@@ -248,9 +248,50 @@ class SplayTreeMap<K, V> extends _SplayTree<K> implements Map<K, V> {
SplayTreeMap([int compare(K key1, K key2)])
: _comparator = (compare == null) ? Comparable.compare : compare;
+ /**
+ * Creates a [SplayTreeMap] that contains all key value pairs of [other].
+ */
factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) =>
new SplayTreeMap(compare)..addAll(other);
+ /**
+ * Creates a [SplayTreeMap] where the keys and values are computed from the
+ * [iterable].
+ *
+ * For each element of the [iterable] this constructor computes a key/value
+ * pair, by applying [key] and [value] respectively.
+ *
+ * The keys of the key/value pairs do not need to be unique. The last
+ * occurrence of a key will simply overwrite any previous value.
+ *
+ * If no values are specified for [key] and [value] the default is the
+ * identity function.
+ */
+ factory SplayTreeMap.fromIterable(Iterable<K> iterable,
+ {K key(element), V value(element), int compare(K key1, K key2)}) {
+ SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare);
+ Maps._fillMapWithMappedIterable(map, iterable, key, value);
+ return map;
+ }
+
+ /**
+ * Creates a [SplayTreeMap] associating the given [keys] to [values].
+ *
+ * This constructor iterates over [keys] and [values] and maps each element of
+ * [keys] to the corresponding element of [values].
+ *
+ * If [keys] contains the same object multiple times, the last occurrence
+ * overwrites the previous value.
+ *
+ * It is an error if the two [Iterable]s don't have the same length.
+ */
+ factory SplayTreeMap.fromIterables(Iterable<K> keys, Iterable<V> values,
+ [int compare(K key1, K key2)]) {
+ SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare);
+ Maps._fillMapWithIterables(map, keys, values);
+ return map;
+ }
+
int _compare(K key1, K key2) => _comparator(key1, key2);
SplayTreeMap._internal();
« no previous file with comments | « sdk/lib/collection/maps.dart ('k') | sdk/lib/core/map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698