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

Unified Diff: sdk/lib/_internal/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
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/collection_patch.dart
diff --git a/sdk/lib/_internal/lib/collection_patch.dart b/sdk/lib/_internal/lib/collection_patch.dart
index 7d6313c42dfd6466c8d4cac242a995d3be1f577c..7c32ebf532a38a65bc8b967092000ac0b1c934cf 100644
--- a/sdk/lib/_internal/lib/collection_patch.dart
+++ b/sdk/lib/_internal/lib/collection_patch.dart
@@ -987,6 +987,18 @@ class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> {
}
}
+ E lookup(Object object) {
+ if (_isStringElement(object) || _isNumericElement(object)) {
+ return this.contains(object) ? object : null;
+ }
+ var rest = _rest;
+ if (rest == null) return null;
+ var bucket = _getBucket(rest, object);
+ var index = _findBucketIndex(bucket, object);
+ if (index < 0) return null;
+ return bucket[index];
+ }
+
// Collection.
void add(E element) {
if (_isStringElement(element)) {
@@ -1251,6 +1263,11 @@ class _CustomHashSet<E> extends _HashSet<E> {
return super.contains(object);
}
+ E lookup(Object object) {
+ if (!_validKey(object)) return null;
+ return super.lookup(object);
+ }
+
bool remove(Object object) {
if (!_validKey(object)) return false;
return super.remove(object);
@@ -1401,6 +1418,19 @@ class _LinkedHashSet<E> extends _HashSetBase<E> implements LinkedHashSet<E> {
}
}
+ E lookup(Object object) {
+ if (_isStringElement(object) || _isNumericElement(object)) {
+ return this.contains(object) ? object : null;
+ } else {
+ var rest = _rest;
+ if (rest == null) return null;
+ var bucket = _getBucket(rest, object);
+ var index = _findBucketIndex(bucket, object);
+ if (index < 0) return null;
+ return bucket[index]._element;
+ }
+ }
+
void forEach(void action(E element)) {
LinkedHashSetCell cell = _first;
int modifications = _modifications;
@@ -1690,6 +1720,11 @@ class _LinkedCustomHashSet<E> extends _LinkedHashSet<E> {
return super.contains(object);
}
+ E lookup(Object object) {
+ if (!_validKey(object)) return null;
+ return super.lookup(object);
+ }
+
bool remove(Object object) {
if (!_validKey(object)) return false;
return super.remove(object);
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698