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

Unified Diff: runtime/lib/collection_patch.dart

Issue 26832002: Add Set.lookup method to get the instance in the set. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
Index: runtime/lib/collection_patch.dart
diff --git a/runtime/lib/collection_patch.dart b/runtime/lib/collection_patch.dart
index 9f0c74fad4a7efd0bc94e22c91b32e61cbf21786..51934d052db5d296281966b41fa6769d39d0e31b 100644
--- a/runtime/lib/collection_patch.dart
+++ b/runtime/lib/collection_patch.dart
@@ -569,6 +569,17 @@ class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> {
return false;
}
+ E lookup(Object object) {
+ int index = _hashCode(object) & (_buckets.length - 1);
+ HashSetEntry entry = _buckets[index];
+ while (entry != null) {
+ var key = entry.key;
+ if (_equals(key, object)) return key;
+ entry = entry.next;
+ }
+ return null;
+ }
+
// Set.
void add(E element) {
@@ -724,6 +735,11 @@ class _CustomHashSet<E> extends _HashSet<E> {
return super.contains(element);
}
+ E lookup(Object element) {
+ if (!_validKey(element)) return null;
+ return super.lookup(element);
+ }
+
bool containsAll(Iterable<Object> elements) {
for (Object element in elements) {
if (!_validKey(element) || !this.contains(element)) return false;
@@ -1180,6 +1196,11 @@ class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> {
return super.contains(o);
}
+ E lookup(Object o) {
+ if (!_validKey(o)) return null;
+ return super.lookup(o);
+ }
+
bool remove(Object o) {
if (!_validKey(o)) return false;
return super.remove(o);
« no previous file with comments | « pkg/unmodifiable_collection/lib/unmodifiable_collection.dart ('k') | sdk/lib/_internal/lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698