| 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> extends _HashSetBase<E> { | 24 class LinkedHashSet<E> implements HashSet<E> { |
| 25 | 25 |
| 26 external LinkedHashSet(); | 26 external factory LinkedHashSet({ bool equals(E e1, E e2), |
| 27 int hashCode(E e), |
| 28 bool isValidKey(potentialKey) }); |
| 27 | 29 |
| 28 factory LinkedHashSet.from(Iterable<E> iterable) { | 30 factory LinkedHashSet.from(Iterable<E> iterable) { |
| 29 return new LinkedHashSet<E>()..addAll(iterable); | 31 return new LinkedHashSet<E>()..addAll(iterable); |
| 30 } | 32 } |
| 31 | |
| 32 // Iterable. | |
| 33 | |
| 34 /** Return an iterator that iterates over elements in insertion order. */ | |
| 35 external Iterator<E> get iterator; | |
| 36 | |
| 37 external int get length; | |
| 38 | |
| 39 external bool get isEmpty; | |
| 40 | |
| 41 external bool get isNotEmpty; | |
| 42 | |
| 43 external bool contains(Object object); | |
| 44 | |
| 45 /** Perform an operation on each element in insertion order. */ | |
| 46 external void forEach(void action(E element)); | |
| 47 | |
| 48 external E get first; | |
| 49 | |
| 50 external E get last; | |
| 51 | |
| 52 E get single { | |
| 53 if (length == 1) return first; | |
| 54 var message = (length == 0) ? "No Elements" : "Too many elements"; | |
| 55 throw new StateError(message); | |
| 56 } | |
| 57 | |
| 58 // Collection. | |
| 59 external void add(E element); | |
| 60 | |
| 61 external void addAll(Iterable<E> objects); | |
| 62 | |
| 63 external bool remove(Object object); | |
| 64 | |
| 65 external void removeAll(Iterable objectsToRemove); | |
| 66 | |
| 67 external void removeWhere(bool test(E element)); | |
| 68 | |
| 69 external void retainWhere(bool test(E element)); | |
| 70 | |
| 71 external void clear(); | |
| 72 | |
| 73 // Set. | |
| 74 Set<E> _newSet() => new LinkedHashSet<E>(); | |
| 75 } | 33 } |
| OLD | NEW |