| Index: sdk/lib/collection/hash_map.dart
|
| diff --git a/sdk/lib/collection/hash_map.dart b/sdk/lib/collection/hash_map.dart
|
| index ab1f09cbdfc6b2e0c3c413bac73465a75e44ec56..2d08e35890696589b494681de77adc10dd5cd36c 100644
|
| --- a/sdk/lib/collection/hash_map.dart
|
| +++ b/sdk/lib/collection/hash_map.dart
|
| @@ -18,10 +18,48 @@ part of dart.collection;
|
| class HashMap<K, V> implements Map<K, V> {
|
| external HashMap();
|
|
|
| + static _id(x) => x;
|
| +
|
| factory HashMap.from(Map<K, V> other) {
|
| return new HashMap<K, V>()..addAll(other);
|
| }
|
|
|
| + factory HashMap.fromIterable(Iterable iterable,
|
| + {K key(element), V value(element)}) {
|
| + HashMap<K, V> map = new HashMap<K, V>();
|
| +
|
| + if (key == null) key = _id;
|
| + if (value == null) value = _id;
|
| +
|
| + for (var element in iterable) {
|
| + map[key(element)] = value(element);
|
| + }
|
| +
|
| + return map;
|
| + }
|
| +
|
| + factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
|
| + HashMap<K, V> map = new HashMap<K, V>();
|
| +
|
| + Iterator<K> keyIterator = keys.iterator;
|
| + Iterator<V> valueIterator = values.iterator;
|
| +
|
| + bool hasNextKey = keyIterator.moveNext();
|
| + bool hasNextValue = valueIterator.moveNext();
|
| +
|
| + while (hasNextKey && hasNextValue) {
|
| + map[keyIterator.current] = valueIterator.current;
|
| + hasNextKey = keyIterator.moveNext();
|
| + hasNextValue = valueIterator.moveNext();
|
| + }
|
| +
|
| + if (hasNextKey || hasNextValue) {
|
| + throw new ArgumentError("Iterables do not have same length.");
|
| + }
|
| +
|
| + return map;
|
| + }
|
| +
|
| external int get length;
|
| external bool get isEmpty;
|
| external bool get isNotEmpty;
|
|
|