Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: runtime/lib/collection_patch.dart

Issue 289353002: Add SetBase/SetMixin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated to not use cloneEmpty Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 patch class HashMap<K, V> { 5 patch class HashMap<K, V> {
6 /* patch */ factory HashMap({ bool equals(K key1, K key2), 6 /* patch */ factory HashMap({ bool equals(K key1, K key2),
7 int hashCode(K key), 7 int hashCode(K key),
8 bool isValidKey(potentialKey) }) { 8 bool isValidKey(potentialKey) }) {
9 if (isValidKey == null) { 9 if (isValidKey == null) {
10 if (hashCode == null) { 10 if (hashCode == null) {
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 627 }
628 628
629 bool remove(Object object) => _remove(object, _hashCode(object)); 629 bool remove(Object object) => _remove(object, _hashCode(object));
630 630
631 void removeAll(Iterable<Object> objectsToRemove) { 631 void removeAll(Iterable<Object> objectsToRemove) {
632 for (Object object in objectsToRemove) { 632 for (Object object in objectsToRemove) {
633 _remove(object, _hashCode(object)); 633 _remove(object, _hashCode(object));
634 } 634 }
635 } 635 }
636 636
637 void retainAll(Iterable<Object> objectsToRetain) {
638 super._retainAll(objectsToRetain, (o) => o is E);
639 }
640
641 void _filterWhere(bool test(E element), bool removeMatching) { 637 void _filterWhere(bool test(E element), bool removeMatching) {
642 int length = _buckets.length; 638 int length = _buckets.length;
643 for (int index = 0; index < length; index++) { 639 for (int index = 0; index < length; index++) {
644 _HashSetEntry entry = _buckets[index]; 640 _HashSetEntry entry = _buckets[index];
645 _HashSetEntry previous = null; 641 _HashSetEntry previous = null;
646 while (entry != null) { 642 while (entry != null) {
647 int modificationCount = _modificationCount; 643 int modificationCount = _modificationCount;
648 bool testResult = test(entry.key); 644 bool testResult = test(entry.key);
649 if (modificationCount != _modificationCount) { 645 if (modificationCount != _modificationCount) {
650 throw new ConcurrentModificationError(this); 646 throw new ConcurrentModificationError(this);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 746 }
751 747
752 void removeAll(Iterable<Object> elements) { 748 void removeAll(Iterable<Object> elements) {
753 for (Object element in elements) { 749 for (Object element in elements) {
754 if (_validKey(element)) { 750 if (_validKey(element)) {
755 super._remove(element, _hasher(element)); 751 super._remove(element, _hasher(element));
756 } 752 }
757 } 753 }
758 } 754 }
759 755
760 void retainAll(Iterable<Object> elements) {
761 super._retainAll(elements, _validKey);
762 }
763
764 bool _equals(e1, e2) => _equality(e1, e2); 756 bool _equals(e1, e2) => _equality(e1, e2);
765 int _hashCode(e) => _hasher(e); 757 int _hashCode(e) => _hasher(e);
766 758
767 HashSet<E> _newSet() => new _CustomHashSet<E>(_equality, _hasher, _validKey); 759 HashSet<E> _newSet() => new _CustomHashSet<E>(_equality, _hasher, _validKey);
768 } 760 }
769 761
770 class _HashSetEntry { 762 class _HashSetEntry {
771 final key; 763 final key;
772 final int hashCode; 764 final int hashCode;
773 _HashSetEntry next; 765 _HashSetEntry next;
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } 1210 }
1219 1211
1220 void removeAll(Iterable<Object> elements) { 1212 void removeAll(Iterable<Object> elements) {
1221 for (Object element in elements) { 1213 for (Object element in elements) {
1222 if (_validKey(element)) { 1214 if (_validKey(element)) {
1223 super._remove(element, _hasher(element)); 1215 super._remove(element, _hasher(element));
1224 } 1216 }
1225 } 1217 }
1226 } 1218 }
1227 1219
1228 void retainAll(Iterable<Object> elements) {
1229 super._retainAll(elements, _validKey);
1230 }
1231
1232 HashSet<E> _newSet() => 1220 HashSet<E> _newSet() =>
1233 new _LinkedCustomHashSet<E>(_equality, _hasher, _validKey); 1221 new _LinkedCustomHashSet<E>(_equality, _hasher, _validKey);
1234 } 1222 }
1235 1223
1236 class _LinkedHashSetIterator<E> implements Iterator<E> { 1224 class _LinkedHashSetIterator<E> implements Iterator<E> {
1237 final _LinkedHashSet _set; 1225 final _LinkedHashSet _set;
1238 final int _modificationCount; 1226 final int _modificationCount;
1239 var _next; 1227 var _next;
1240 E _current; 1228 E _current;
1241 1229
(...skipping 11 matching lines...) Expand all
1253 return false; 1241 return false;
1254 } 1242 }
1255 _LinkedHashSetEntry entry = _next; 1243 _LinkedHashSetEntry entry = _next;
1256 _current = entry.key; 1244 _current = entry.key;
1257 _next = entry._nextEntry; 1245 _next = entry._nextEntry;
1258 return true; 1246 return true;
1259 } 1247 }
1260 1248
1261 E get current => _current; 1249 E get current => _current;
1262 } 1250 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/collection_patch.dart » ('j') | sdk/lib/collection/hash_set.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698