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 /** | 7 /** |
8 * A [LinkedHashSet] is a hash-table based [Set] implementation. | 8 * A [LinkedHashSet] is a hash-table based [Set] implementation. |
9 * | 9 * |
10 * The `LinkedHashSet` also keep track of the order that elements were inserted | 10 * The `LinkedHashSet` also keep track of the order that elements were inserted |
11 * in, and iteration happens in first-to-last insertion order. | 11 * in, and iteration happens in first-to-last insertion order. |
12 * | 12 * |
13 * The elements of a `LinkedHashSet` must have consistent [Object.operator==] | 13 * The elements of a `LinkedHashSet` must have consistent [Object.operator==] |
14 * and [Object.hashCode] implementations. This means that the `==` operator | 14 * and [Object.hashCode] implementations. This means that the `==` operator |
15 * must define a stable equivalence relation on the elements (reflexive, | 15 * must define a stable equivalence relation on the elements (reflexive, |
16 * anti-symmetric, transitive, and consistent over time), and that `hashCode` | 16 * anti-symmetric, transitive, and consistent over time), and that `hashCode` |
17 * must be the same for objects that are considered equal by `==`. | 17 * must be the same for objects that are considered equal by `==`. |
18 * | 18 * |
19 * The set allows `null` as an element. | 19 * The set allows `null` as an element. |
20 * | 20 * |
21 * Most simple operations on `HashSet` are done in constant time: [add], | 21 * Most simple operations on `HashSet` are done in constant time: [add], |
22 * [contains], [remove], and [length]. | 22 * [contains], [remove], and [length]. |
23 */ | 23 */ |
24 class LinkedHashSet<E> implements HashSet<E> { | 24 class LinkedHashSet<E> implements HashSet<E> { |
25 | 25 |
26 external factory LinkedHashSet({ bool equals(E e1, E e2), | 26 external factory LinkedHashSet({ bool equals(E e1, E e2), |
27 int hashCode(E e), | 27 int hashCode(E e), |
28 bool isValidKey(potentialKey) }); | 28 bool isValidKey(potentialKey) }); |
29 | 29 |
| 30 /** |
| 31 * Creates an insertion-ordered identity-based set. |
| 32 * |
| 33 * Effectively a shorthand for: |
| 34 * |
| 35 * new LinkedHashSet(equals: identical, hashCode: identityHashCodeOf) |
| 36 */ |
| 37 external factory LinkedHashSet.identity(); |
| 38 |
| 39 |
30 factory LinkedHashSet.from(Iterable<E> iterable) { | 40 factory LinkedHashSet.from(Iterable<E> iterable) { |
31 return new LinkedHashSet<E>()..addAll(iterable); | 41 return new LinkedHashSet<E>()..addAll(iterable); |
32 } | 42 } |
33 } | 43 } |
OLD | NEW |