| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ | 7 /** Common parts of [HashSet] and [LinkedHashSet] implementations. */ |
| 8 abstract class _HashSetBase<E> extends Collection<E> implements Set<E> { | 8 abstract class _HashSetBase<E> extends Collection<E> implements Set<E> { |
| 9 // Set. | 9 // Set. |
| 10 bool isSubsetOf(Collection<E> other) { | 10 bool isSubsetOf(Collection<E> other) { |
| 11 // Deprecated, and using old signature. | 11 // Deprecated, and using old signature. |
| 12 Set otherSet; | 12 Set otherSet; |
| 13 if (other is Set) { | 13 if (other is Set) { |
| 14 otherSet = other; | 14 otherSet = other; |
| 15 } else { | 15 } else { |
| 16 otherSet = other.toSet(); | 16 otherSet = other.toSet(); |
| 17 } | 17 } |
| 18 return otherSet.containsAll(this); | 18 return otherSet.containsAll(this); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool containsAll(Iterable<E> other) { | 21 bool containsAll(Iterable<E> other) { |
| 22 for (E object in other) { | 22 for (E object in other) { |
| 23 if (!this.contains(object)) return false; | 23 if (!this.contains(object)) return false; |
| 24 } | 24 } |
| 25 return true; | 25 return true; |
| 26 } | 26 } |
| 27 | 27 |
| 28 /** Create a new Set of the same type as this. */ |
| 29 Set _newSet(); |
| 30 |
| 28 Set<E> intersection(Set<E> other) { | 31 Set<E> intersection(Set<E> other) { |
| 29 Set<E> result = _newSet(); | 32 Set<E> result = _newSet(); |
| 30 if (other.length < this.length) { | 33 if (other.length < this.length) { |
| 31 for (E element in other) { | 34 for (E element in other) { |
| 32 if (this.contains(element)) result.add(element); | 35 if (this.contains(element)) result.add(element); |
| 33 } | 36 } |
| 34 } else { | 37 } else { |
| 35 for (E element in this) { | 38 for (E element in this) { |
| 36 if (other.contains(element)) result.add(element); | 39 if (other.contains(element)) result.add(element); |
| 37 } | 40 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 94 |
| 92 external void removeWhere(bool test(E element)); | 95 external void removeWhere(bool test(E element)); |
| 93 | 96 |
| 94 external void retainWhere(bool test(E element)); | 97 external void retainWhere(bool test(E element)); |
| 95 | 98 |
| 96 external void clear(); | 99 external void clear(); |
| 97 | 100 |
| 98 // Set. | 101 // Set. |
| 99 Set<E> _newSet() => new HashSet<E>(); | 102 Set<E> _newSet() => new HashSet<E>(); |
| 100 } | 103 } |
| OLD | NEW |