| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A node in a splay tree. It holds the sorting key and the left | 8 * A node in a splay tree. It holds the sorting key and the left |
| 9 * and right children in the tree. | 9 * and right children in the tree. |
| 10 */ | 10 */ |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 * | 234 * |
| 235 * The map is based on a self-balancing binary tree. It allows most operations | 235 * The map is based on a self-balancing binary tree. It allows most operations |
| 236 * in amortized logarithmic time. | 236 * in amortized logarithmic time. |
| 237 * | 237 * |
| 238 * Keys of the map are compared using the `compare` function passed in | 238 * Keys of the map are compared using the `compare` function passed in |
| 239 * the constructor. If that is omitted, the objects are assumed to be | 239 * the constructor. If that is omitted, the objects are assumed to be |
| 240 * [Comparable], and are compared using their [Comparable.compareTo] | 240 * [Comparable], and are compared using their [Comparable.compareTo] |
| 241 * method. This also means that `null` is *not* allowed as a key. | 241 * method. This also means that `null` is *not* allowed as a key. |
| 242 */ | 242 */ |
| 243 class SplayTreeMap<K, V> extends _SplayTree<K> implements Map<K, V> { | 243 class SplayTreeMap<K, V> extends _SplayTree<K> implements Map<K, V> { |
| 244 // TODO(ngeoffray): Restore type when feature is implemented in dart2js | 244 Comparator<K> _comparator; |
| 245 // checked mode. http://dartbug.com/7733 | |
| 246 Function /* Comparator<K> */_comparator; | |
| 247 | 245 |
| 248 SplayTreeMap([int compare(K key1, K key2)]) | 246 SplayTreeMap([int compare(K key1, K key2)]) |
| 249 : _comparator = (compare == null) ? Comparable.compare : compare; | 247 : _comparator = (compare == null) ? Comparable.compare : compare; |
| 250 | 248 |
| 251 /** | 249 /** |
| 252 * Creates a [SplayTreeMap] that contains all key value pairs of [other]. | 250 * Creates a [SplayTreeMap] that contains all key value pairs of [other]. |
| 253 */ | 251 */ |
| 254 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) => | 252 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) => |
| 255 new SplayTreeMap(compare)..addAll(other); | 253 new SplayTreeMap(compare)..addAll(other); |
| 256 | 254 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { | 576 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { |
| 579 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); | 577 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); |
| 580 V _getValue(_SplayTreeMapNode node) => node.value; | 578 V _getValue(_SplayTreeMapNode node) => node.value; |
| 581 } | 579 } |
| 582 | 580 |
| 583 class _SplayTreeNodeIterator<K> | 581 class _SplayTreeNodeIterator<K> |
| 584 extends _SplayTreeIterator<_SplayTreeNode<K>> { | 582 extends _SplayTreeIterator<_SplayTreeNode<K>> { |
| 585 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); | 583 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); |
| 586 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; | 584 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; |
| 587 } | 585 } |
| OLD | NEW |