Skip to content

Commit

Permalink
Change Set.difference API to accept Set<Object>.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitschG committed Oct 20, 2016
1 parent 941b0c8 commit 6beb1fd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,7 @@
## 1.21.0
### Core library changes

* `dart:core`: `Set.difference` now takes a `Set<Object>` as argument.

### Language

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/helpers/debug_collection.dart
Expand Up @@ -261,7 +261,7 @@ class DebugSet<E> extends DebugIterable<E> implements Set<E> {

Set<E> union(Set<E> other) => set.union(other);

Set<E> difference(Set<E> other) => set.difference(other);
Set<E> difference(Set<Object> other) => set.difference(other);

void clear() => set.clear();

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/helpers/expensive_set.dart
Expand Up @@ -101,7 +101,7 @@ class ExpensiveSet<E> extends IterableBase<E> implements Set<E> {
return _newSet()..addAll(this)..addAll(other);
}

Set<E> difference(Set<E> other) {
Set<E> difference(Set<Object> other) {
Set<E> result = _newSet();
for (E element in this) {
if (!other.contains(element)) result.add(element);
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/util/emptyset.dart
Expand Up @@ -32,7 +32,7 @@ class ImmutableEmptySet<E> extends IterableBase<E> implements Set<E> {

Set<E> union(Set<E> other) => new Set.from(other);
Set<E> intersection(Set<E> other) => this;
Set<E> difference(Set<E> other) => this;
Set<E> difference(Set<Object> other) => this;
Set<E> toSet() => new Set();
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/util/setlet.dart
Expand Up @@ -250,7 +250,7 @@ class Setlet<E> extends IterableBase<E> implements Set<E> {
Setlet<E> intersection(Set<E> other) =>
new Setlet<E>.from(this.where((e) => other.contains(e)));

Setlet<E> difference(Set<E> other) =>
Setlet<E> difference(Set<Object> other) =>
new Setlet<E>.from(this.where((e) => !other.contains(e)));

Setlet<E> toSet() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/core/set.dart
Expand Up @@ -185,7 +185,7 @@ abstract class Set<E> extends Iterable<E> implements EfficientLength {
* That is, the returned set contains all the elements of this [Set] that
* are not elements of [other] according to `other.contains`.
*/
Set<E> difference(Set<E> other);
Set<E> difference(Set<Object> other);

/**
* Removes all elements in the set.
Expand Down
11 changes: 11 additions & 0 deletions tests/corelib/set_test.dart
Expand Up @@ -166,6 +166,17 @@ void testInts(Set create()) {
}
Expect.isTrue(twice.difference(thrice).difference(twice).isEmpty);

// Test Set.difference with non-element type.
Set diffSet = create()..addAll([0, 1, 2, 499, 999]);
Set<Object> objectSet = new Set<Object>();
objectSet.add("foo");
objectSet.add(499);
Set diffResult = diffSet.difference(objectSet);
Expect.equals(4, diffResult.length);
for (int value in [0, 1, 2, 999]) {
Expect.isTrue(diffResult.contains(value));
}

// Test Set.addAll.
List list = new List(10);
for (int i = 0; i < 10; i++) {
Expand Down

0 comments on commit 6beb1fd

Please sign in to comment.