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

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

Issue 451633003: Make Iterable.toSet say that it returns a Set with the same equality as the Iterable's contains met… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 6 years, 2 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
« no previous file with comments | « runtime/lib/collection_patch.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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 T _getValue(_SplayTreeNode node); 594 T _getValue(_SplayTreeNode node);
595 } 595 }
596 596
597 class _SplayTreeKeyIterable<K> extends IterableBase<K> 597 class _SplayTreeKeyIterable<K> extends IterableBase<K>
598 implements EfficientLength { 598 implements EfficientLength {
599 _SplayTree<K> _tree; 599 _SplayTree<K> _tree;
600 _SplayTreeKeyIterable(this._tree); 600 _SplayTreeKeyIterable(this._tree);
601 int get length => _tree._count; 601 int get length => _tree._count;
602 bool get isEmpty => _tree._count == 0; 602 bool get isEmpty => _tree._count == 0;
603 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); 603 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree);
604 Set<K> toSet() {
605 SplayTreeSet<K> set =
606 new SplayTreeSet<K>(_tree._comparator, _tree._validKey);
607 set._count = _tree._count;
608 set._root = set._copyNode(_tree._root);
609 return set;
610 }
604 } 611 }
605 612
606 class _SplayTreeValueIterable<K, V> extends IterableBase<V> 613 class _SplayTreeValueIterable<K, V> extends IterableBase<V>
607 implements EfficientLength { 614 implements EfficientLength {
608 SplayTreeMap<K, V> _map; 615 SplayTreeMap<K, V> _map;
609 _SplayTreeValueIterable(this._map); 616 _SplayTreeValueIterable(this._map);
610 int get length => _map._count; 617 int get length => _map._count;
611 bool get isEmpty => _map._count == 0; 618 bool get isEmpty => _map._count == 0;
612 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); 619 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map);
613 } 620 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 return result; 787 return result;
781 } 788 }
782 789
783 Set<E> union(Set<E> other) { 790 Set<E> union(Set<E> other) {
784 return _clone()..addAll(other); 791 return _clone()..addAll(other);
785 } 792 }
786 793
787 SplayTreeSet<E> _clone() { 794 SplayTreeSet<E> _clone() {
788 var set = new SplayTreeSet<E>(_comparator, _validKey); 795 var set = new SplayTreeSet<E>(_comparator, _validKey);
789 set._count = _count; 796 set._count = _count;
790 set._root = _cloneNode(_root); 797 set._root = _copyNode(_root);
791 return set; 798 return set;
792 } 799 }
793 800
794 _SplayTreeNode<E> _cloneNode(_SplayTreeNode<E> node) { 801 // Copies the structure of a SplayTree into a new similar structure.
802 // Works on _SplayTreeMapNode as well, but only copies the keys,
803 _SplayTreeNode<E> _copyNode(_SplayTreeNode<E> node) {
795 if (node == null) return null; 804 if (node == null) return null;
796 return new _SplayTreeNode<E>(node.key)..left = _cloneNode(node.left) 805 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left)
797 ..right = _cloneNode(node.right); 806 ..right = _copyNode(node.right);
798 } 807 }
799 808
800 void clear() { _clear(); } 809 void clear() { _clear(); }
801 810
802 Set<E> toSet() => _clone(); 811 Set<E> toSet() => _clone();
803 812
804 String toString() => IterableBase.iterableToFullString(this, '{', '}'); 813 String toString() => IterableBase.iterableToFullString(this, '{', '}');
805 } 814 }
OLDNEW
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698