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 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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } | 593 } |
594 _currentNode = _workList.removeLast(); | 594 _currentNode = _workList.removeLast(); |
595 _findLeftMostDescendent(_currentNode.right); | 595 _findLeftMostDescendent(_currentNode.right); |
596 return true; | 596 return true; |
597 } | 597 } |
598 | 598 |
599 T _getValue(_SplayTreeNode node); | 599 T _getValue(_SplayTreeNode node); |
600 } | 600 } |
601 | 601 |
602 class _SplayTreeKeyIterable<K> extends Iterable<K> | 602 class _SplayTreeKeyIterable<K> extends Iterable<K> |
603 implements EfficientLengthIterable<K> { | 603 implements EfficientLength { |
604 _SplayTree<K> _tree; | 604 _SplayTree<K> _tree; |
605 _SplayTreeKeyIterable(this._tree); | 605 _SplayTreeKeyIterable(this._tree); |
606 int get length => _tree._count; | 606 int get length => _tree._count; |
607 bool get isEmpty => _tree._count == 0; | 607 bool get isEmpty => _tree._count == 0; |
608 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); | 608 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); |
609 | 609 |
610 Set<K> toSet() { | 610 Set<K> toSet() { |
611 var setOrMap = _tree; // Both have _comparator and _validKey. | 611 var setOrMap = _tree; // Both have _comparator and _validKey. |
612 SplayTreeSet<K> set = | 612 SplayTreeSet<K> set = |
613 new SplayTreeSet<K>(setOrMap._comparator, setOrMap._validKey); | 613 new SplayTreeSet<K>(setOrMap._comparator, setOrMap._validKey); |
614 set._count = _tree._count; | 614 set._count = _tree._count; |
615 set._root = set._copyNode(_tree._root); | 615 set._root = set._copyNode(_tree._root); |
616 return set; | 616 return set; |
617 } | 617 } |
618 } | 618 } |
619 | 619 |
620 class _SplayTreeValueIterable<K, V> extends Iterable<V> | 620 class _SplayTreeValueIterable<K, V> extends Iterable<V> |
621 implements EfficientLengthIterable<V> { | 621 implements EfficientLength { |
622 SplayTreeMap<K, V> _map; | 622 SplayTreeMap<K, V> _map; |
623 _SplayTreeValueIterable(this._map); | 623 _SplayTreeValueIterable(this._map); |
624 int get length => _map._count; | 624 int get length => _map._count; |
625 bool get isEmpty => _map._count == 0; | 625 bool get isEmpty => _map._count == 0; |
626 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); | 626 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); |
627 } | 627 } |
628 | 628 |
629 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K> { | 629 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K> { |
630 _SplayTreeKeyIterator(_SplayTree<K> map): super(map); | 630 _SplayTreeKeyIterator(_SplayTree<K> map): super(map); |
631 K _getValue(_SplayTreeNode node) => node.key; | 631 K _getValue(_SplayTreeNode node) => node.key; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left) | 829 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left) |
830 ..right = _copyNode(node.right); | 830 ..right = _copyNode(node.right); |
831 } | 831 } |
832 | 832 |
833 void clear() { _clear(); } | 833 void clear() { _clear(); } |
834 | 834 |
835 Set<E> toSet() => _clone(); | 835 Set<E> toSet() => _clone(); |
836 | 836 |
837 String toString() => IterableBase.iterableToFullString(this, '{', '}'); | 837 String toString() => IterableBase.iterableToFullString(this, '{', '}'); |
838 } | 838 } |
OLD | NEW |