Chromium Code Reviews| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 SplayTreeMap([int compare(K key1, K key2)]) | 248 SplayTreeMap([int compare(K key1, K key2)]) |
| 249 : _comparator = (compare == null) ? Comparable.compare : compare; | 249 : _comparator = (compare == null) ? Comparable.compare : compare; |
| 250 | 250 |
| 251 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) => | 251 factory SplayTreeMap.from(Map<K, V> other, [int compare(K key1, K key2)]) => |
| 252 new SplayTreeMap(compare)..addAll(other); | 252 new SplayTreeMap(compare)..addAll(other); |
| 253 | 253 |
| 254 int _compare(K key1, K key2) => _comparator(key1, key2); | 254 int _compare(K key1, K key2) => _comparator(key1, key2); |
| 255 | 255 |
| 256 SplayTreeMap._internal(); | 256 SplayTreeMap._internal(); |
| 257 | 257 |
| 258 V operator [](K key) { | 258 V operator [](Object key) { |
| 259 if (key == null) throw new ArgumentError(key); | 259 if (key == null) throw new ArgumentError(key); |
| 260 if (key is! K) return null; | |
|
Lasse Reichstein Nielsen
2013/06/18 14:13:08
Per earlier discussion, could we keep this as "K"?
floitsch
2013/06/20 15:52:50
As discussed in person: leaving as is.
| |
| 260 if (_root != null) { | 261 if (_root != null) { |
| 261 int comp = _splay(key); | 262 int comp = _splay(key); |
| 262 if (comp == 0) { | 263 if (comp == 0) { |
| 263 _SplayTreeMapNode mapRoot = _root; | 264 _SplayTreeMapNode mapRoot = _root; |
| 264 return mapRoot.value; | 265 return mapRoot.value; |
| 265 } | 266 } |
| 266 } | 267 } |
| 267 return null; | 268 return null; |
| 268 } | 269 } |
| 269 | 270 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 } | 331 } |
| 331 | 332 |
| 332 int get length { | 333 int get length { |
| 333 return _count; | 334 return _count; |
| 334 } | 335 } |
| 335 | 336 |
| 336 void clear() { | 337 void clear() { |
| 337 _clear(); | 338 _clear(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 bool containsKey(K key) { | 341 bool containsKey(Object key) { |
| 341 return _splay(key) == 0; | 342 return key is K && _splay(key) == 0; |
| 342 } | 343 } |
| 343 | 344 |
| 344 bool containsValue(V value) { | 345 bool containsValue(Object value) { |
| 345 bool found = false; | 346 bool found = false; |
| 346 int initialSplayCount = _splayCount; | 347 int initialSplayCount = _splayCount; |
| 347 bool visit(_SplayTreeMapNode node) { | 348 bool visit(_SplayTreeMapNode node) { |
| 348 while (node != null) { | 349 while (node != null) { |
| 349 if (node.value == value) return true; | 350 if (node.value == value) return true; |
| 350 if (initialSplayCount != _splayCount) { | 351 if (initialSplayCount != _splayCount) { |
| 351 throw new ConcurrentModificationError(this); | 352 throw new ConcurrentModificationError(this); |
| 352 } | 353 } |
| 353 if (node.right != null && visit(node.right)) return true; | 354 if (node.right != null && visit(node.right)) return true; |
| 354 node = node.left; | 355 node = node.left; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { | 537 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { |
| 537 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); | 538 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); |
| 538 V _getValue(_SplayTreeMapNode node) => node.value; | 539 V _getValue(_SplayTreeMapNode node) => node.value; |
| 539 } | 540 } |
| 540 | 541 |
| 541 class _SplayTreeNodeIterator<K> | 542 class _SplayTreeNodeIterator<K> |
| 542 extends _SplayTreeIterator<_SplayTreeNode<K>> { | 543 extends _SplayTreeIterator<_SplayTreeNode<K>> { |
| 543 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); | 544 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); |
| 544 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; | 545 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; |
| 545 } | 546 } |
| OLD | NEW |