| 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 class HashSet<E> extends Collection<E> implements Set<E> { | 7 class HashSet<E> extends Collection<E> implements Set<E> { |
| 8 static const int _INITIAL_CAPACITY = 8; | 8 static const int _INITIAL_CAPACITY = 8; |
| 9 final _HashTable<E> _table; | 9 final _HashTable<E> _table; |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 for (Object object in objectsToRemove) { | 48 for (Object object in objectsToRemove) { |
| 49 _table._remove(object); | 49 _table._remove(object); |
| 50 _table._checkCapacity(); | 50 _table._checkCapacity(); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void retainAll(Iterable objectsToRetain) { | 54 void retainAll(Iterable objectsToRetain) { |
| 55 IterableMixinWorkaround.retainAll(this, objectsToRetain); | 55 IterableMixinWorkaround.retainAll(this, objectsToRetain); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void _filterMatching(bool test(E element), bool removeMatching) { | 58 void _filterWhere(bool test(E element), bool removeMatching) { |
| 59 int entrySize = _table._entrySize; | 59 int entrySize = _table._entrySize; |
| 60 int length = _table._table.length; | 60 int length = _table._table.length; |
| 61 for (int offset = 0; offset < length; offset += entrySize) { | 61 for (int offset = 0; offset < length; offset += entrySize) { |
| 62 Object entry = _table._table[offset]; | 62 Object entry = _table._table[offset]; |
| 63 if (!_table._isFree(entry)) { | 63 if (!_table._isFree(entry)) { |
| 64 E key = identical(entry, _NULL) ? null : entry; | 64 E key = identical(entry, _NULL) ? null : entry; |
| 65 int modificationCount = _table._modificationCount; | 65 int modificationCount = _table._modificationCount; |
| 66 bool shouldRemove = (removeMatching == test(key)); | 66 bool shouldRemove = (removeMatching == test(key)); |
| 67 _table._checkModification(modificationCount); | 67 _table._checkModification(modificationCount); |
| 68 if (shouldRemove) { | 68 if (shouldRemove) { |
| 69 _table._deleteEntry(offset); | 69 _table._deleteEntry(offset); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 _table._checkCapacity(); | 73 _table._checkCapacity(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void removeMatching(bool test(E element)) { | 76 void removeWhere(bool test(E element)) { |
| 77 _filterMatching(test, true); | 77 _filterWhere(test, true); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void retainMatching(bool test(E element)) { | 80 void retainWhere(bool test(E element)) { |
| 81 _filterMatching(test, false); | 81 _filterWhere(test, false); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void clear() { | 84 void clear() { |
| 85 _table._clear(); | 85 _table._clear(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Set. | 88 // Set. |
| 89 bool isSubsetOf(Collection<E> collection) { | 89 bool isSubsetOf(Collection<E> collection) { |
| 90 Set otherSet; | 90 Set otherSet; |
| 91 if (collection is Set) { | 91 if (collection is Set) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 for (E element in other) { | 108 for (E element in other) { |
| 109 if (this.contains(element)) { | 109 if (this.contains(element)) { |
| 110 result.add(element); | 110 result.add(element); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 | 115 |
| 116 String toString() => Collections.collectionToString(this); | 116 String toString() => Collections.collectionToString(this); |
| 117 } | 117 } |
| OLD | NEW |