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

Unified Diff: runtime/lib/immutable_map.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « runtime/lib/growable_array.dart ('k') | runtime/lib/integers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/immutable_map.dart
diff --git a/runtime/lib/immutable_map.dart b/runtime/lib/immutable_map.dart
index aa33a6dcbbc07df1807fdcdd29d2c76997eccd48..82f54580e4490a66e346b3f206475b8a93fdb8c8 100644
--- a/runtime/lib/immutable_map.dart
+++ b/runtime/lib/immutable_map.dart
@@ -35,22 +35,12 @@ class ImmutableMap<K, V> implements Map<K, V> {
}
}
- Collection<K> get keys {
- int numKeys = length;
- List<K> list = new List<K>(numKeys);
- for (int i = 0; i < numKeys; i++) {
- list[i] = kvPairs_[i*2];
- }
- return list;
+ Iterable<K> get keys {
+ return new _ImmutableMapKeyIterable<K>(this);
}
- Collection<V> get values {
- int numValues = length;
- List<V> list = new List<V>(numValues);
- for (int i = 0; i < numValues; i++) {
- list[i] = kvPairs_[i*2 + 1];
- }
- return list;
+ Iterable<V> get values {
+ return new _ImmutableMapValueIterable<V>(this);
}
bool containsKey(K key) {
@@ -92,3 +82,64 @@ class ImmutableMap<K, V> implements Map<K, V> {
}
}
+class _ImmutableMapKeyIterable<E> extends Iterable<E> {
+ final ImmutableMap _map;
+ _ImmutableMapKeyIterable(this._map);
+
+ Iterator<E> get iterator {
+ return new _ImmutableMapKeyIterator<E>(_map);
+ }
+}
+
+class _ImmutableMapValueIterable<E> extends Iterable<E> {
+ final ImmutableMap _map;
+ _ImmutableMapValueIterable(this._map);
+
+ Iterator<E> get iterator {
+ return new _ImmutableMapValueIterator<E>(_map);
+ }
+}
+
+class _ImmutableMapKeyIterator<E> implements Iterator<E> {
+ ImmutableMap _map;
+ int _index = -1;
+ E _current;
+
+ _ImmutableMapKeyIterator(this._map);
+
+ bool moveNext() {
+ int newIndex = _index + 1;
+ if (newIndex < _map.length) {
+ _index = newIndex;
+ _current = _map.kvPairs_[newIndex * 2];
+ return true;
+ }
+ _current = null;
+ _index = _map.length;
+ return false;
+ }
+
+ E get current => _current;
+}
+
+class _ImmutableMapValueIterator<E> implements Iterator<E> {
+ ImmutableMap _map;
+ int _index = -1;
+ E _current;
+
+ _ImmutableMapValueIterator(this._map);
+
+ bool moveNext() {
+ int newIndex = _index + 1;
+ if (newIndex < _map.length) {
+ _index = newIndex;
+ _current = _map.kvPairs_[newIndex * 2 + 1];
+ return true;
+ }
+ _current = null;
+ _index = _map.length;
+ return false;
+ }
+
+ E get current => _current;
+}
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | runtime/lib/integers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698