Chromium Code Reviews| 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 /** | |
| 8 * A [LinkedHashSet] is a hash-table based [Set] implementation. | |
| 9 * | |
| 10 * The `LinkedHashSet` also keep track of the order that elements were inserted | |
|
ngeoffray
2013/06/04 11:51:33
keep -> keeps
| |
| 11 * in, and iteration happens in first-to-last insertion order. | |
| 12 * | |
| 13 * The elements of a `LinkedHashSet` must have consistent [Object.operator==] | |
| 14 * and [Object.hashCode] implementations. This means that the `==` operator | |
| 15 * must define a stable equivalence relation on the elements (reflexive, | |
| 16 * anti-symmetric, trasitive, and consistent over time), and that `hashCode` | |
|
ngeoffray
2013/06/04 11:51:33
trasitive -> transitive
| |
| 17 * must be the same for objects that are considered equal by `==`. | |
| 18 * | |
| 19 * The set allows `null` as an element. | |
| 20 * | |
| 21 * Most simple operations on `HashSet` are done in constant time: [add], | |
| 22 * [contains], [remove], and [length]. | |
| 23 */ | |
| 7 class LinkedHashSet<E> extends _HashSetBase<E> { | 24 class LinkedHashSet<E> extends _HashSetBase<E> { |
| 8 | 25 |
| 9 external LinkedHashSet(); | 26 external LinkedHashSet(); |
| 10 | 27 |
| 11 factory LinkedHashSet.from(Iterable<E> iterable) { | 28 factory LinkedHashSet.from(Iterable<E> iterable) { |
| 12 return new LinkedHashSet<E>()..addAll(iterable); | 29 return new LinkedHashSet<E>()..addAll(iterable); |
| 13 } | 30 } |
| 14 | 31 |
| 15 // Iterable. | 32 // Iterable. |
| 33 | |
| 34 /** Return an iterator that iterates over elements in insertion order. */ | |
| 16 external Iterator<E> get iterator; | 35 external Iterator<E> get iterator; |
| 17 | 36 |
| 18 external int get length; | 37 external int get length; |
| 19 | 38 |
| 20 external bool get isEmpty; | 39 external bool get isEmpty; |
| 21 | 40 |
| 22 external bool get isNotEmpty; | 41 external bool get isNotEmpty; |
| 23 | 42 |
| 24 external bool contains(Object object); | 43 external bool contains(Object object); |
| 25 | 44 |
| 45 /** Perform an operation on each element in insertion order. */ | |
| 26 external void forEach(void action(E element)); | 46 external void forEach(void action(E element)); |
| 27 | 47 |
| 28 external E get first; | 48 external E get first; |
| 29 | 49 |
| 30 external E get last; | 50 external E get last; |
| 31 | 51 |
| 32 E get single { | 52 E get single { |
| 33 if (length == 1) return first; | 53 if (length == 1) return first; |
| 34 var message = (length == 0) ? "No Elements" : "Too many elements"; | 54 var message = (length == 0) ? "No Elements" : "Too many elements"; |
| 35 throw new StateError(message); | 55 throw new StateError(message); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 46 | 66 |
| 47 external void removeWhere(bool test(E element)); | 67 external void removeWhere(bool test(E element)); |
| 48 | 68 |
| 49 external void retainWhere(bool test(E element)); | 69 external void retainWhere(bool test(E element)); |
| 50 | 70 |
| 51 external void clear(); | 71 external void clear(); |
| 52 | 72 |
| 53 // Set. | 73 // Set. |
| 54 Set<E> _newSet() => new LinkedHashSet<E>(); | 74 Set<E> _newSet() => new LinkedHashSet<E>(); |
| 55 } | 75 } |
| OLD | NEW |