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

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

Issue 26280002: Set.add returns true if item has been added, otherwise false (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: again Created 7 years, 2 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void 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; 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 } 596 }
596 597
597 void addAll(Iterable<E> objects) { 598 void addAll(Iterable<E> objects) {
598 int ctr = 0; 599 int ctr = 0;
599 for (E object in objects) { 600 for (E object in objects) {
600 ctr++; 601 ctr++;
601 add(object); 602 add(object);
602 } 603 }
603 } 604 }
604 605
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 return false; 1253 return false;
1253 } 1254 }
1254 _LinkedHashSetEntry entry = _next; 1255 _LinkedHashSetEntry entry = _next;
1255 _current = entry.key; 1256 _current = entry.key;
1256 _next = entry._nextEntry; 1257 _next = entry._nextEntry;
1257 return true; 1258 return true;
1258 } 1259 }
1259 1260
1260 E get current => _current; 1261 E get current => _current;
1261 } 1262 }
OLDNEW
« no previous file with comments | « pkg/unmodifiable_collection/lib/unmodifiable_collection.dart ('k') | sdk/lib/_internal/lib/collection_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698