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

Unified Diff: sdk/lib/collection/hash_set.dart

Issue 12646005: Add Set.union, Set.difference. Change Set methods to expect Set. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « no previous file | sdk/lib/collection/linked_hash_set.dart » ('j') | sdk/lib/collection/linked_hash_set.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/hash_set.dart
diff --git a/sdk/lib/collection/hash_set.dart b/sdk/lib/collection/hash_set.dart
index 69080293a042a40849539d22dcd0c79410a73482..ea945bd68c16f2c16977d93cf3f7aec925756718 100644
--- a/sdk/lib/collection/hash_set.dart
+++ b/sdk/lib/collection/hash_set.dart
@@ -86,27 +86,52 @@ class HashSet<E> extends Collection<E> implements Set<E> {
}
// Set.
- bool isSubsetOf(Collection<E> collection) {
- Set otherSet;
- if (collection is Set) {
- otherSet = collection;
- } else {
- otherSet = collection.toSet();
+ bool isSubsetOf(Set<E> other) {
floitsch 2013/03/12 16:25:00 bool isSubsetOf(Set<E> other) => other.containsAll
Lasse Reichstein Nielsen 2013/03/13 13:01:42 The resason is the usual one: I don't want public,
+ if (length > other.length) return false;
+ for (E element in this) {
+ if (!other.contains(element)) return false;
}
- return otherSet.containsAll(this);
+ return true;
}
- bool containsAll(Collection<E> collection) {
- for (E element in collection) {
+ bool containsAll(Set<E> other) {
+ if (other.length > length) return false;
+ for (E element in other) {
if (!this.contains(element)) return false;
}
return true;
}
- Set<E> intersection(Collection<E> other) {
+ Set<E> intersection(Set<E> other) {
+ Set<E> smaller;
+ Set<E> larger;
+ if (length < other.length) {
+ smaller = this;
+ larger = other;
+ } else {
+ smaller = other;
+ larger = this;
+ }
Set<E> result = new HashSet<E>();
- for (E element in other) {
- if (this.contains(element)) {
+ for (E element in smaller) {
+ if (larger.contains(element)) {
+ result.add(element);
+ }
+ }
+ return result;
+ }
+
+ Set<E> union(Set<E> other) {
+ Set<E> result = new HashSet<E>();
+ result.addAll(this);
+ result.addAll(other);
+ return result;
+ }
+
+ Set<E> difference(Set<E> other) {
+ Set<E> result = new HashSet<E>();
+ for (E element in this) {
+ if (!other.contains(element)) {
result.add(element);
}
}
« no previous file with comments | « no previous file | sdk/lib/collection/linked_hash_set.dart » ('j') | sdk/lib/collection/linked_hash_set.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698