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 /** 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 static List _toStringList = new List(); | |
| 10 | |
| 9 // Set. | 11 // Set. |
| 10 bool containsAll(Iterable<Object> other) { | 12 bool containsAll(Iterable<Object> other) { |
| 11 for (Object object in other) { | 13 for (Object object in other) { |
| 12 if (!this.contains(object)) return false; | 14 if (!this.contains(object)) return false; |
| 13 } | 15 } |
| 14 return true; | 16 return true; |
| 15 } | 17 } |
| 16 | 18 |
| 17 /** Create a new Set of the same type as this. */ | 19 /** Create a new Set of the same type as this. */ |
| 18 Set _newSet(); | 20 Set _newSet(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 46 void retainAll(Iterable objectsToRetain) { | 48 void retainAll(Iterable objectsToRetain) { |
| 47 Set retainSet; | 49 Set retainSet; |
| 48 if (objectsToRetain is Set) { | 50 if (objectsToRetain is Set) { |
| 49 retainSet = objectsToRetain; | 51 retainSet = objectsToRetain; |
| 50 } else { | 52 } else { |
| 51 retainSet = objectsToRetain.toSet(); | 53 retainSet = objectsToRetain.toSet(); |
| 52 } | 54 } |
| 53 retainWhere(retainSet.contains); | 55 retainWhere(retainSet.contains); |
| 54 } | 56 } |
| 55 | 57 |
| 56 String toString() => ToString.iterableToString(this); | 58 String toString() { |
| 59 for(int i = 0; i < _toStringList.length; i++) { | |
| 60 if(identical(_toStringList[i], this)) | |
| 61 return '{...}'; | |
| 62 } | |
| 63 _toStringList.add(this); | |
| 64 String result = IterableMixinWorkaround.toStringIterable(this); | |
| 65 _toStringList.remove(this); | |
|
floitsch
2013/07/08 12:00:50
Same comments as before.
zarah
2013/07/08 14:35:15
Done.
| |
| 66 print(result); | |
|
floitsch
2013/07/08 12:00:50
Remove debug print.
zarah
2013/07/08 14:35:15
Done.
| |
| 67 return result; | |
| 68 } | |
| 57 } | 69 } |
| 58 | 70 |
| 59 /** | 71 /** |
| 60 * A [HashSet] is a hash-table based [Set] implementation. | 72 * A [HashSet] is a hash-table based [Set] implementation. |
| 61 * | 73 * |
| 62 * The elements of a `HashSet` must have consistent [Object.operator==] | 74 * The elements of a `HashSet` must have consistent [Object.operator==] |
| 63 * and [Object.hashCode] implementations. This means that the `==` operator | 75 * and [Object.hashCode] implementations. This means that the `==` operator |
| 64 * must define a stable equivalence relation on the elements (reflexive, | 76 * must define a stable equivalence relation on the elements (reflexive, |
| 65 * anti-symmetric, transitive, and consistent over time), and that `hashCode` | 77 * anti-symmetric, transitive, and consistent over time), and that `hashCode` |
| 66 * must be the same for objects that are considered equal by `==`. | 78 * must be the same for objects that are considered equal by `==`. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 external void removeAll(Iterable<Object> objectsToRemove); | 110 external void removeAll(Iterable<Object> objectsToRemove); |
| 99 | 111 |
| 100 external void removeWhere(bool test(E element)); | 112 external void removeWhere(bool test(E element)); |
| 101 | 113 |
| 102 external void retainWhere(bool test(E element)); | 114 external void retainWhere(bool test(E element)); |
| 103 | 115 |
| 104 external void clear(); | 116 external void clear(); |
| 105 | 117 |
| 106 Set<E> _newSet() => new HashSet<E>(); | 118 Set<E> _newSet() => new HashSet<E>(); |
| 107 } | 119 } |
| OLD | NEW |