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

Side by Side Diff: sdk/lib/collection/splay_tree.dart

Issue 12391010: Make HashSet.length constant time. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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) 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 _findLeftMostDescendent(_currentNode.right); 467 _findLeftMostDescendent(_currentNode.right);
468 return true; 468 return true;
469 } 469 }
470 470
471 T _getValue(_SplayTreeNode node); 471 T _getValue(_SplayTreeNode node);
472 } 472 }
473 473
474 class _SplayTreeKeyIterable<K> extends Iterable<K> { 474 class _SplayTreeKeyIterable<K> extends Iterable<K> {
475 _SplayTree<K> _tree; 475 _SplayTree<K> _tree;
476 _SplayTreeKeyIterable(this._tree); 476 _SplayTreeKeyIterable(this._tree);
477 int get length => _tree._count;
478 bool get isEmpty => _tree._count == 0;
477 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); 479 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree);
478 } 480 }
479 481
480 class _SplayTreeValueIterable<K, V> extends Iterable<V> { 482 class _SplayTreeValueIterable<K, V> extends Iterable<V> {
481 SplayTreeMap<K, V> _map; 483 SplayTreeMap<K, V> _map;
482 _SplayTreeValueIterable(this._map); 484 _SplayTreeValueIterable(this._map);
485 int get length => _map._count;
486 bool get isEmpty => _map._count == 0;
483 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); 487 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map);
484 } 488 }
485 489
486 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K> { 490 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K> {
487 _SplayTreeKeyIterator(_SplayTree<K> map): super(map); 491 _SplayTreeKeyIterator(_SplayTree<K> map): super(map);
488 K _getValue(_SplayTreeNode node) => node.key; 492 K _getValue(_SplayTreeNode node) => node.key;
489 } 493 }
490 494
491 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> { 495 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> {
492 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map); 496 _SplayTreeValueIterator(SplayTreeMap<K, V> map): super(map);
493 V _getValue(_SplayTreeMapNode node) => node.value; 497 V _getValue(_SplayTreeMapNode node) => node.value;
494 } 498 }
495 499
496 class _SplayTreeNodeIterator<K> 500 class _SplayTreeNodeIterator<K>
497 extends _SplayTreeIterator<_SplayTreeNode<K>> { 501 extends _SplayTreeIterator<_SplayTreeNode<K>> {
498 _SplayTreeNodeIterator(_SplayTree<K> map): super(map); 502 _SplayTreeNodeIterator(_SplayTree<K> map): super(map);
499 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node; 503 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => node;
500 } 504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698