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 | 9 |
10 // Set. | 10 // Set. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 Set retainSet = _newSet(); | 50 Set retainSet = _newSet(); |
51 for (Object o in objectsToRetain) { | 51 for (Object o in objectsToRetain) { |
52 if (isValidKey(o)) { | 52 if (isValidKey(o)) { |
53 retainSet.add(o); | 53 retainSet.add(o); |
54 } | 54 } |
55 } | 55 } |
56 retainWhere(retainSet.contains); | 56 retainWhere(retainSet.contains); |
57 } | 57 } |
58 | 58 |
59 List<E> toList({bool growable: true}) { | 59 List<E> toList({bool growable: true}) { |
60 List<E> result = new List<E>()..length = this.length; | 60 List<E> result = growable ? (new List<E>()..length = this.length) |
floitsch
2013/10/11 09:29:43
I would have preferred if this was in a separate C
Lasse Reichstein Nielsen
2013/10/11 20:25:37
Kept.
| |
61 : new List<E>(this.length); | |
61 int i = 0; | 62 int i = 0; |
62 for (E element in this) result[i++] = element; | 63 for (E element in this) result[i++] = element; |
63 return result; | 64 return result; |
64 } | 65 } |
65 | 66 |
66 Set<E> toSet() => _newSet()..addAll(this); | 67 Set<E> toSet() => _newSet()..addAll(this); |
67 | 68 |
68 // TODO(zarah) Remove this, and let it be inherited by IterableBase | |
69 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); | 69 String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}'); |
70 } | 70 } |
71 | 71 |
72 /** | 72 /** |
73 * A [HashSet] is a hash-table based [Set] implementation. | 73 * A [HashSet] is a hash-table based [Set] implementation. |
74 * | 74 * |
75 * The elements of a `HashSet` must have consistent equality | 75 * The elements of a `HashSet` must have consistent equality |
76 * and hashCode implementations. This means that the equals operation | 76 * and hashCode implementations. This means that the equals operation |
77 * must define a stable equivalence relation on the elements (reflexive, | 77 * must define a stable equivalence relation on the elements (reflexive, |
78 * anti-symmetric, transitive, and consistent over time), and that the hashCode | 78 * anti-symmetric, transitive, and consistent over time), and that the hashCode |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 /** | 122 /** |
123 * Create a hash set containing the elements of [iterable]. | 123 * Create a hash set containing the elements of [iterable]. |
124 * | 124 * |
125 * Creates a hash set as by `new HashSet<E>()` and adds each element of | 125 * Creates a hash set as by `new HashSet<E>()` and adds each element of |
126 * `iterable` to this set in the order they are iterated. | 126 * `iterable` to this set in the order they are iterated. |
127 */ | 127 */ |
128 factory HashSet.from(Iterable<E> iterable) { | 128 factory HashSet.from(Iterable<E> iterable) { |
129 return new HashSet<E>()..addAll(iterable); | 129 return new HashSet<E>()..addAll(iterable); |
130 } | 130 } |
131 } | 131 } |
OLD | NEW |