| 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 IterableBase<E> implements Set<E> { | 8 abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> { |
| 9 // Set. | 9 // Set. |
| 10 bool containsAll(Iterable<E> other) { | 10 bool containsAll(Iterable<E> other) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 retainSet = objectsToRetain; | 49 retainSet = objectsToRetain; |
| 50 } else { | 50 } else { |
| 51 retainSet = objectsToRetain.toSet(); | 51 retainSet = objectsToRetain.toSet(); |
| 52 } | 52 } |
| 53 retainWhere(retainSet.contains); | 53 retainWhere(retainSet.contains); |
| 54 } | 54 } |
| 55 | 55 |
| 56 String toString() => ToString.iterableToString(this); | 56 String toString() => ToString.iterableToString(this); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** |
| 60 * A [HashSet] is a hash-table based [Set] implementation. |
| 61 * |
| 62 * The elements of a `HashSet` must have consistent [Object.operator==] |
| 63 * and [Object.hashCode] implementations. This means that the `==` operator |
| 64 * must define a stable equivalence relation on the elements (reflexive, |
| 65 * anti-symmetric, transitive, and consistent over time), and that `hashCode` |
| 66 * must be the same for objects that are considered equal by `==`. |
| 67 * |
| 68 * The set allows `null` as an element. |
| 69 * |
| 70 * Most simple operations on `HashSet` are done in constant time: [add], |
| 71 * [contains], [remove], and [length]. |
| 72 */ |
| 59 class HashSet<E> extends _HashSetBase<E> { | 73 class HashSet<E> extends _HashSetBase<E> { |
| 60 external HashSet(); | 74 external HashSet(); |
| 61 | 75 |
| 62 factory HashSet.from(Iterable<E> iterable) { | 76 factory HashSet.from(Iterable<E> iterable) { |
| 63 return new HashSet<E>()..addAll(iterable); | 77 return new HashSet<E>()..addAll(iterable); |
| 64 } | 78 } |
| 65 | 79 |
| 66 // Iterable. | 80 // Iterable. |
| 67 external Iterator<E> get iterator; | 81 external Iterator<E> get iterator; |
| 68 | 82 |
| 69 external int get length; | 83 external int get length; |
| 70 | 84 |
| 71 external bool get isEmpty; | 85 external bool get isEmpty; |
| 72 | 86 |
| 73 external bool get isNotEmpty; | 87 external bool get isNotEmpty; |
| 74 | 88 |
| 75 external bool contains(Object object); | 89 external bool contains(Object object); |
| 76 | 90 |
| 77 // Collection. | 91 // Set. |
| 78 external void add(E element); | 92 external void add(E element); |
| 79 | 93 |
| 80 external void addAll(Iterable<E> objects); | 94 external void addAll(Iterable<E> objects); |
| 81 | 95 |
| 82 external bool remove(Object object); | 96 external bool remove(Object object); |
| 83 | 97 |
| 84 external void removeAll(Iterable objectsToRemove); | 98 external void removeAll(Iterable objectsToRemove); |
| 85 | 99 |
| 86 external void removeWhere(bool test(E element)); | 100 external void removeWhere(bool test(E element)); |
| 87 | 101 |
| 88 external void retainWhere(bool test(E element)); | 102 external void retainWhere(bool test(E element)); |
| 89 | 103 |
| 90 external void clear(); | 104 external void clear(); |
| 91 | 105 |
| 92 // Set. | |
| 93 Set<E> _newSet() => new HashSet<E>(); | 106 Set<E> _newSet() => new HashSet<E>(); |
| 94 } | 107 } |
| OLD | NEW |