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

Unified Diff: dart/frog/leg/lib/hash_map_set.dart

Issue 9537009: Create mock versions set and sort implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 | « dart/frog/leg/lib/dual_pivot_quicksort.dart ('k') | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/hash_map_set.dart
diff --git a/dart/frog/leg/lib/hash_map_set.dart b/dart/frog/leg/lib/hash_map_set.dart
index c538951fff31beb62674103b8c7517339c0c8ded..7605cb9a74fad45492abe1c30482ff6ecf456dca 100644
--- a/dart/frog/leg/lib/hash_map_set.dart
+++ b/dart/frog/leg/lib/hash_map_set.dart
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// TODO(ahe): Remove this file and use the shared one.
+
// Hash map implementation with open addressing and quadratic probing.
class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> {
@@ -156,14 +158,13 @@ class HashMapImplementation<K extends Hashable, V> implements HashMap<K, V> {
// [key] can be either of type [K] or [_DeletedKeySentinel].
Object key = oldKeys[i];
// If there is no key, we don't need to deal with the current slot.
- if (key === null || key === _DELETED_KEY) {
- continue;
+ if (key !== null && key !== _DELETED_KEY) {
+ V value = oldValues[i];
+ // Insert the {key, value} pair in their new slot.
+ int newIndex = _probeForAdding(key);
+ _keys[newIndex] = key;
+ _values[newIndex] = value;
}
- V value = oldValues[i];
- // Insert the {key, value} pair in their new slot.
- int newIndex = _probeForAdding(key);
- _keys[newIndex] = key;
- _values[newIndex] = value;
}
_numberOfDeleted = 0;
}
@@ -307,32 +308,36 @@ class HashSetImplementation<E extends Hashable> implements HashSet<E> {
}
void addAll(Collection<E> collection) {
+ var self = this;
ahe 2012/02/29 12:37:21 I should be able to remove all the "self" referenc
collection.forEach(void _(E value) {
- add(value);
+ self.add(value);
});
}
Set<E> intersection(Collection<E> collection) {
+ var self = this;
Set<E> result = new Set<E>();
collection.forEach(void _(E value) {
- if (contains(value)) result.add(value);
+ if (self.contains(value)) result.add(value);
});
return result;
}
bool isSubsetOf(Collection<E> other) {
- return new Set<E>.from(other).containsAll(this);
+ return new Set.from(other).containsAll(this);
}
void removeAll(Collection<E> collection) {
+ var self = this;
collection.forEach(void _(E value) {
- remove(value);
+ self.remove(value);
});
}
bool containsAll(Collection<E> collection) {
+ var self = this;
return collection.every(bool _(E value) {
- return contains(value);
+ return self.contains(value);
});
}
« no previous file with comments | « dart/frog/leg/lib/dual_pivot_quicksort.dart ('k') | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698