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) { |
11 if (equals == null) { | 11 if (equals == null) { |
12 return new _HashMap<K, V>(); | 12 return new _HashMap<K, V>(); |
13 } | 13 } |
14 hashCode = _defaultHashCode; | 14 hashCode = _defaultHashCode; |
15 } else { | 15 } else { |
16 if (identical(identityHashCode, hashCode) && | 16 if (identical(identityHashCode, hashCode) && |
17 identical(identical, equals)) { | 17 identical(identical, equals)) { |
18 return new _IdentityHashMap<K, V>(); | 18 return new _IdentityHashMap<K, V>(); |
19 } | 19 } |
20 if (equals == null) { | 20 if (equals == null) { |
21 equals = _defaultEquals; | 21 equals = _defaultEquals; |
22 } | 22 } |
23 } | 23 } |
24 } else { | 24 } else { |
25 if (hashCode == null) { | 25 if (hashCode == null) { |
26 hashCode = _defaultHashCode; | 26 hashCode = _defaultHashCode; |
27 } | 27 } |
28 if (equals == null) { | 28 if (equals == null) { |
29 equals = _defaultEquals; | 29 equals = _defaultEquals; |
30 } | 30 } |
31 } | 31 } |
32 return new _CustomHashMap<K, V>(equals, hashCode, isValidKey); | 32 return new _CustomHashMap<K, V>(equals, hashCode, isValidKey); |
33 } | 33 } |
34 | 34 |
35 /* patch */ factory HashMap.identity() = _IdentityHashMap<K, V>; | 35 @patch factory HashMap.identity() = _IdentityHashMap<K, V>; |
36 | 36 |
37 Set<K> _newKeySet(); | 37 Set<K> _newKeySet(); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 const int _MODIFICATION_COUNT_MASK = 0x3fffffff; | 41 const int _MODIFICATION_COUNT_MASK = 0x3fffffff; |
42 | 42 |
43 class _HashMap<K, V> implements HashMap<K, V> { | 43 class _HashMap<K, V> implements HashMap<K, V> { |
44 static const int _INITIAL_CAPACITY = 8; | 44 static const int _INITIAL_CAPACITY = 8; |
45 | 45 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 512 |
513 class _HashMapValueIterator<V> extends _HashMapIterator<V> { | 513 class _HashMapValueIterator<V> extends _HashMapIterator<V> { |
514 _HashMapValueIterator(HashMap map) : super(map); | 514 _HashMapValueIterator(HashMap map) : super(map); |
515 V get current { | 515 V get current { |
516 _HashMapEntry entry = _entry; | 516 _HashMapEntry entry = _entry; |
517 return (entry == null) ? null : entry.value; | 517 return (entry == null) ? null : entry.value; |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 @patch class HashSet<E> { | 521 @patch class HashSet<E> { |
522 /* @patch */ factory HashSet({ bool equals(E e1, E e2), | 522 @patch factory HashSet({ bool equals(E e1, E e2), |
523 int hashCode(E e), | 523 int hashCode(E e), |
524 bool isValidKey(potentialKey) }) { | 524 bool isValidKey(potentialKey) }) { |
525 if (isValidKey == null) { | 525 if (isValidKey == null) { |
526 if (hashCode == null) { | 526 if (hashCode == null) { |
527 if (equals == null) { | 527 if (equals == null) { |
528 return new _HashSet<E>(); | 528 return new _HashSet<E>(); |
529 } | 529 } |
530 hashCode = _defaultHashCode; | 530 hashCode = _defaultHashCode; |
531 } else { | 531 } else { |
532 if (identical(identityHashCode, hashCode) && | 532 if (identical(identityHashCode, hashCode) && |
533 identical(identical, equals)) { | 533 identical(identical, equals)) { |
534 return new _IdentityHashSet<E>(); | 534 return new _IdentityHashSet<E>(); |
535 } | 535 } |
536 if (equals == null) { | 536 if (equals == null) { |
537 equals = _defaultEquals; | 537 equals = _defaultEquals; |
538 } | 538 } |
539 } | 539 } |
540 } else { | 540 } else { |
541 if (hashCode == null) { | 541 if (hashCode == null) { |
542 hashCode = _defaultHashCode; | 542 hashCode = _defaultHashCode; |
543 } | 543 } |
544 if (equals == null) { | 544 if (equals == null) { |
545 equals = _defaultEquals; | 545 equals = _defaultEquals; |
546 } | 546 } |
547 } | 547 } |
548 return new _CustomHashSet<E>(equals, hashCode, isValidKey); | 548 return new _CustomHashSet<E>(equals, hashCode, isValidKey); |
549 } | 549 } |
550 | 550 |
551 /* @patch */ factory HashSet.identity() = _IdentityHashSet<E>; | 551 @patch factory HashSet.identity() = _IdentityHashSet<E>; |
552 } | 552 } |
553 | 553 |
554 class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> { | 554 class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> { |
555 static const int _INITIAL_CAPACITY = 8; | 555 static const int _INITIAL_CAPACITY = 8; |
556 | 556 |
557 List<_HashSetEntry> _buckets = new List(_INITIAL_CAPACITY); | 557 List<_HashSetEntry> _buckets = new List(_INITIAL_CAPACITY); |
558 int _elementCount = 0; | 558 int _elementCount = 0; |
559 int _modificationCount = 0; | 559 int _modificationCount = 0; |
560 | 560 |
561 bool _equals(e1, e2) => e1 == e2; | 561 bool _equals(e1, e2) => e1 == e2; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 */ | 903 */ |
904 @patch class LinkedHashMap<K, V> { | 904 @patch class LinkedHashMap<K, V> { |
905 /// Holds a double-linked list of entries in insertion order. | 905 /// Holds a double-linked list of entries in insertion order. |
906 /// The fields have the same name as the ones in [_LinkedHashMapEntry], | 906 /// The fields have the same name as the ones in [_LinkedHashMapEntry], |
907 /// and this map is itself used as the head entry of the list. | 907 /// and this map is itself used as the head entry of the list. |
908 /// Set to `this` when initialized, representing the empty list (containing | 908 /// Set to `this` when initialized, representing the empty list (containing |
909 /// only the head entry itself). | 909 /// only the head entry itself). |
910 var _nextEntry; | 910 var _nextEntry; |
911 var _previousEntry; | 911 var _previousEntry; |
912 | 912 |
913 /* @patch */ factory LinkedHashMap({ bool equals(K key1, K key2), | 913 @patch factory LinkedHashMap({ bool equals(K key1, K key2), |
914 int hashCode(K key), | 914 int hashCode(K key), |
915 bool isValidKey(potentialKey) }) { | 915 bool isValidKey(potentialKey) }) { |
916 if (isValidKey == null) { | 916 if (isValidKey == null) { |
917 if (hashCode == null) { | 917 if (hashCode == null) { |
918 if (equals == null) { | 918 if (equals == null) { |
919 return new _InternalLinkedHashMap<K, V>(); | 919 return new _InternalLinkedHashMap<K, V>(); |
920 } | 920 } |
921 hashCode = _defaultHashCode; | 921 hashCode = _defaultHashCode; |
922 } else { | 922 } else { |
923 if (identical(identityHashCode, hashCode) && | 923 if (identical(identityHashCode, hashCode) && |
924 identical(identical, equals)) { | 924 identical(identical, equals)) { |
925 return new _CompactLinkedIdentityHashMap<K, V>(); | 925 return new _CompactLinkedIdentityHashMap<K, V>(); |
926 } | 926 } |
927 if (equals == null) { | 927 if (equals == null) { |
928 equals = _defaultEquals; | 928 equals = _defaultEquals; |
929 } | 929 } |
930 } | 930 } |
931 } else { | 931 } else { |
932 if (hashCode == null) { | 932 if (hashCode == null) { |
933 hashCode = _defaultHashCode; | 933 hashCode = _defaultHashCode; |
934 } | 934 } |
935 if (equals == null) { | 935 if (equals == null) { |
936 equals = _defaultEquals; | 936 equals = _defaultEquals; |
937 } | 937 } |
938 } | 938 } |
939 return new _CompactLinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); | 939 return new _CompactLinkedCustomHashMap<K, V>(equals, hashCode, isValidKey); |
940 } | 940 } |
941 | 941 |
942 /* @patch */ factory LinkedHashMap.identity() = | 942 @patch factory LinkedHashMap.identity() = |
943 _CompactLinkedIdentityHashMap<K, V>; | 943 _CompactLinkedIdentityHashMap<K, V>; |
944 } | 944 } |
945 | 945 |
946 @patch class LinkedHashSet<E> { | 946 @patch class LinkedHashSet<E> { |
947 /* @patch */ factory LinkedHashSet({ bool equals(E e1, E e2), | 947 @patch factory LinkedHashSet({ bool equals(E e1, E e2), |
948 int hashCode(E e), | 948 int hashCode(E e), |
949 bool isValidKey(potentialKey) }) { | 949 bool isValidKey(potentialKey) }) { |
950 if (isValidKey == null) { | 950 if (isValidKey == null) { |
951 if (hashCode == null) { | 951 if (hashCode == null) { |
952 if (equals == null) { | 952 if (equals == null) { |
953 return new _CompactLinkedHashSet<E>(); | 953 return new _CompactLinkedHashSet<E>(); |
954 } | 954 } |
955 hashCode = _defaultHashCode; | 955 hashCode = _defaultHashCode; |
956 } else { | 956 } else { |
957 if (identical(identityHashCode, hashCode) && | 957 if (identical(identityHashCode, hashCode) && |
958 identical(identical, equals)) { | 958 identical(identical, equals)) { |
959 return new _CompactLinkedIdentityHashSet<E>(); | 959 return new _CompactLinkedIdentityHashSet<E>(); |
960 } | 960 } |
961 if (equals == null) { | 961 if (equals == null) { |
962 equals = _defaultEquals; | 962 equals = _defaultEquals; |
963 } | 963 } |
964 } | 964 } |
965 } else { | 965 } else { |
966 if (hashCode == null) { | 966 if (hashCode == null) { |
967 hashCode = _defaultHashCode; | 967 hashCode = _defaultHashCode; |
968 } | 968 } |
969 if (equals == null) { | 969 if (equals == null) { |
970 equals = _defaultEquals; | 970 equals = _defaultEquals; |
971 } | 971 } |
972 } | 972 } |
973 return new _CompactLinkedCustomHashSet<E>(equals, hashCode, isValidKey); | 973 return new _CompactLinkedCustomHashSet<E>(equals, hashCode, isValidKey); |
974 } | 974 } |
975 | 975 |
976 /* @patch */ factory LinkedHashSet.identity() = | 976 @patch factory LinkedHashSet.identity() = |
977 _CompactLinkedIdentityHashSet<E>; | 977 _CompactLinkedIdentityHashSet<E>; |
978 } | 978 } |
OLD | NEW |