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

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

Issue 2467113003: Make EfficientLength extend Iterable. (Closed)
Patch Set: Reverted, prepare to reland. Make new test not break web-testing framework. Created 4 years, 1 month 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
« no previous file with comments | « sdk/lib/collection/queue.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 typedef bool _Predicate<T>(T value); 7 typedef bool _Predicate<T>(T value);
8 8
9 /** 9 /**
10 * A node in a splay tree. It holds the sorting key and the left 10 * A node in a splay tree. It holds the sorting key and the left
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 _rebuildWorkList(_currentNode); 600 _rebuildWorkList(_currentNode);
601 } 601 }
602 _currentNode = _workList.removeLast(); 602 _currentNode = _workList.removeLast();
603 _findLeftMostDescendent(_currentNode.right); 603 _findLeftMostDescendent(_currentNode.right);
604 return true; 604 return true;
605 } 605 }
606 606
607 T _getValue(_SplayTreeNode<K> node); 607 T _getValue(_SplayTreeNode<K> node);
608 } 608 }
609 609
610 class _SplayTreeKeyIterable<K> extends Iterable<K> 610 class _SplayTreeKeyIterable<K> extends EfficientLengthIterable<K> {
611 implements EfficientLength {
612 _SplayTree<K, _SplayTreeNode<K>> _tree; 611 _SplayTree<K, _SplayTreeNode<K>> _tree;
613 _SplayTreeKeyIterable(this._tree); 612 _SplayTreeKeyIterable(this._tree);
614 int get length => _tree._count; 613 int get length => _tree._count;
615 bool get isEmpty => _tree._count == 0; 614 bool get isEmpty => _tree._count == 0;
616 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); 615 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree);
617 616
618 Set<K> toSet() { 617 Set<K> toSet() {
619 SplayTreeSet<K> set = 618 SplayTreeSet<K> set =
620 new SplayTreeSet<K>(_tree._comparator, _tree._validKey); 619 new SplayTreeSet<K>(_tree._comparator, _tree._validKey);
621 set._count = _tree._count; 620 set._count = _tree._count;
622 set._root = set._copyNode(_tree._root); 621 set._root = set._copyNode(_tree._root);
623 return set; 622 return set;
624 } 623 }
625 } 624 }
626 625
627 class _SplayTreeValueIterable<K, V> extends Iterable<V> 626 class _SplayTreeValueIterable<K, V> extends EfficientLengthIterable<V> {
628 implements EfficientLength {
629 SplayTreeMap<K, V> _map; 627 SplayTreeMap<K, V> _map;
630 _SplayTreeValueIterable(this._map); 628 _SplayTreeValueIterable(this._map);
631 int get length => _map._count; 629 int get length => _map._count;
632 bool get isEmpty => _map._count == 0; 630 bool get isEmpty => _map._count == 0;
633 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); 631 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map);
634 } 632 }
635 633
636 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K, K> { 634 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K, K> {
637 _SplayTreeKeyIterator(_SplayTree<K, _SplayTreeNode<K>> map): super(map); 635 _SplayTreeKeyIterator(_SplayTree<K, _SplayTreeNode<K>> map): super(map);
638 K _getValue(_SplayTreeNode<K> node) => node.key; 636 K _getValue(_SplayTreeNode<K> node) => node.key;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left) 847 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left)
850 ..right = _copyNode(node.right); 848 ..right = _copyNode(node.right);
851 } 849 }
852 850
853 void clear() { _clear(); } 851 void clear() { _clear(); }
854 852
855 Set<E> toSet() => _clone(); 853 Set<E> toSet() => _clone();
856 854
857 String toString() => IterableBase.iterableToFullString(this, '{', '}'); 855 String toString() => IterableBase.iterableToFullString(this, '{', '}');
858 } 856 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/queue.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698