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 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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 HashSetEntry entry = _buckets[index]; | 564 HashSetEntry entry = _buckets[index]; |
565 while (entry != null) { | 565 while (entry != null) { |
566 if (_equals(entry.key, object)) return true; | 566 if (_equals(entry.key, object)) return true; |
567 entry = entry.next; | 567 entry = entry.next; |
568 } | 568 } |
569 return false; | 569 return false; |
570 } | 570 } |
571 | 571 |
572 // Set. | 572 // Set. |
573 | 573 |
574 void add(E element) { | 574 bool add(E element) { |
575 int hashCode = _hashCode(element); | 575 int hashCode = _hashCode(element); |
576 int index = hashCode & (_buckets.length - 1); | 576 int index = hashCode & (_buckets.length - 1); |
577 HashSetEntry entry = _buckets[index]; | 577 HashSetEntry entry = _buckets[index]; |
578 while (entry != null) { | 578 while (entry != null) { |
579 if (_equals(entry.key, element)) return; | 579 if (_equals(entry.key, element)) return false; |
580 entry = entry.next; | 580 entry = entry.next; |
581 } | 581 } |
582 _addEntry(element, hashCode, index); | 582 _addEntry(element, hashCode, index); |
| 583 return true; |
583 } | 584 } |
584 | 585 |
585 void addAll(Iterable<E> objects) { | 586 void addAll(Iterable<E> objects) { |
586 int ctr = 0; | 587 int ctr = 0; |
587 for (E object in objects) { | 588 for (E object in objects) { |
588 ctr++; | 589 ctr++; |
589 add(object); | 590 add(object); |
590 } | 591 } |
591 } | 592 } |
592 | 593 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 return false; | 1229 return false; |
1229 } | 1230 } |
1230 _LinkedHashSetEntry entry = _next; | 1231 _LinkedHashSetEntry entry = _next; |
1231 _current = entry.key; | 1232 _current = entry.key; |
1232 _next = entry._nextEntry; | 1233 _next = entry._nextEntry; |
1233 return true; | 1234 return true; |
1234 } | 1235 } |
1235 | 1236 |
1236 E get current => _current; | 1237 E get current => _current; |
1237 } | 1238 } |
OLD | NEW |