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

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

Issue 59073003: Version 0.8.10.4 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « dart/runtime/include/dart_api.h ('k') | dart/runtime/lib/growable_array.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 Iterator<E> get iterator => new _HashSetIterator<E>(this); 555 Iterator<E> get iterator => new _HashSetIterator<E>(this);
556 556
557 int get length => _elementCount; 557 int get length => _elementCount;
558 558
559 bool get isEmpty => _elementCount == 0; 559 bool get isEmpty => _elementCount == 0;
560 560
561 bool get isNotEmpty => _elementCount != 0; 561 bool get isNotEmpty => _elementCount != 0;
562 562
563 bool contains(Object object) { 563 bool contains(Object object) {
564 int index = _hashCode(object) & (_buckets.length - 1); 564 int index = _hashCode(object) & (_buckets.length - 1);
565 HashSetEntry entry = _buckets[index]; 565 _HashSetEntry entry = _buckets[index];
566 while (entry != null) { 566 while (entry != null) {
567 if (_equals(entry.key, object)) return true; 567 if (_equals(entry.key, object)) return true;
568 entry = entry.next; 568 entry = entry.next;
569 } 569 }
570 return false; 570 return false;
571 } 571 }
572 572
573 E lookup(Object object) { 573 E lookup(Object object) {
574 int index = _hashCode(object) & (_buckets.length - 1); 574 int index = _hashCode(object) & (_buckets.length - 1);
575 HashSetEntry entry = _buckets[index]; 575 _HashSetEntry entry = _buckets[index];
576 while (entry != null) { 576 while (entry != null) {
577 var key = entry.key; 577 var key = entry.key;
578 if (_equals(key, object)) return key; 578 if (_equals(key, object)) return key;
579 entry = entry.next; 579 entry = entry.next;
580 } 580 }
581 return null; 581 return null;
582 } 582 }
583 583
584 // Set. 584 // Set.
585 585
586 bool add(E element) { 586 bool add(E element) {
587 int hashCode = _hashCode(element); 587 int hashCode = _hashCode(element);
588 int index = hashCode & (_buckets.length - 1); 588 int index = hashCode & (_buckets.length - 1);
589 HashSetEntry entry = _buckets[index]; 589 _HashSetEntry entry = _buckets[index];
590 while (entry != null) { 590 while (entry != null) {
591 if (_equals(entry.key, element)) return false; 591 if (_equals(entry.key, element)) return false;
592 entry = entry.next; 592 entry = entry.next;
593 } 593 }
594 _addEntry(element, hashCode, index); 594 _addEntry(element, hashCode, index);
595 return true; 595 return true;
596 } 596 }
597 597
598 void addAll(Iterable<E> objects) { 598 void addAll(Iterable<E> objects) {
599 int ctr = 0; 599 int ctr = 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 } 634 }
635 } 635 }
636 636
637 void retainAll(Iterable<Object> objectsToRetain) { 637 void retainAll(Iterable<Object> objectsToRetain) {
638 super._retainAll(objectsToRetain, (o) => o is E); 638 super._retainAll(objectsToRetain, (o) => o is E);
639 } 639 }
640 640
641 void _filterWhere(bool test(E element), bool removeMatching) { 641 void _filterWhere(bool test(E element), bool removeMatching) {
642 int length = _buckets.length; 642 int length = _buckets.length;
643 for (int index = 0; index < length; index++) { 643 for (int index = 0; index < length; index++) {
644 HashSetEntry entry = _buckets[index]; 644 _HashSetEntry entry = _buckets[index];
645 HashSetEntry previous = null; 645 _HashSetEntry previous = null;
646 while (entry != null) { 646 while (entry != null) {
647 int modificationCount = _modificationCount; 647 int modificationCount = _modificationCount;
648 bool testResult = test(entry.key); 648 bool testResult = test(entry.key);
649 if (modificationCount != _modificationCount) { 649 if (modificationCount != _modificationCount) {
650 throw new ConcurrentModificationError(this); 650 throw new ConcurrentModificationError(this);
651 } 651 }
652 if (testResult == removeMatching) { 652 if (testResult == removeMatching) {
653 HashSetEntry next = entry.remove(); 653 _HashSetEntry next = entry.remove();
654 if (previous == null) { 654 if (previous == null) {
655 _buckets[index] = next; 655 _buckets[index] = next;
656 } else { 656 } else {
657 previous.next = next; 657 previous.next = next;
658 } 658 }
659 _elementCount--; 659 _elementCount--;
660 _modificationCount = 660 _modificationCount =
661 (_modificationCount + 1) & _MODIFICATION_COUNT_MASK; 661 (_modificationCount + 1) & _MODIFICATION_COUNT_MASK;
662 entry = next; 662 entry = next;
663 } else { 663 } else {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 return false; 1253 return false;
1254 } 1254 }
1255 _LinkedHashSetEntry entry = _next; 1255 _LinkedHashSetEntry entry = _next;
1256 _current = entry.key; 1256 _current = entry.key;
1257 _next = entry._nextEntry; 1257 _next = entry._nextEntry;
1258 return true; 1258 return true;
1259 } 1259 }
1260 1260
1261 E get current => _current; 1261 E get current => _current;
1262 } 1262 }
OLDNEW
« no previous file with comments | « dart/runtime/include/dart_api.h ('k') | dart/runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698