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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/iterable.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/splay_tree.dart
diff --git a/sdk/lib/collection/splay_tree.dart b/sdk/lib/collection/splay_tree.dart
index 3eecd53db305bedd1b3a077b4a991ef7015804a4..1601fd5b9d79b7a7750d47dee6831e83d2980f3f 100644
--- a/sdk/lib/collection/splay_tree.dart
+++ b/sdk/lib/collection/splay_tree.dart
@@ -601,6 +601,13 @@ class _SplayTreeKeyIterable<K> extends IterableBase<K>
int get length => _tree._count;
bool get isEmpty => _tree._count == 0;
Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree);
+ Set<K> toSet() {
+ SplayTreeSet<K> set =
+ new SplayTreeSet<K>(_tree._comparator, _tree._validKey);
+ set._count = _tree._count;
+ set._root = set._copyNode(_tree._root);
+ return set;
+ }
}
class _SplayTreeValueIterable<K, V> extends IterableBase<V>
@@ -787,14 +794,16 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>, SetMixin<E> {
SplayTreeSet<E> _clone() {
var set = new SplayTreeSet<E>(_comparator, _validKey);
set._count = _count;
- set._root = _cloneNode(_root);
+ set._root = _copyNode(_root);
return set;
}
- _SplayTreeNode<E> _cloneNode(_SplayTreeNode<E> node) {
+ // Copies the structure of a SplayTree into a new similar structure.
+ // Works on _SplayTreeMapNode as well, but only copies the keys,
+ _SplayTreeNode<E> _copyNode(_SplayTreeNode<E> node) {
if (node == null) return null;
- return new _SplayTreeNode<E>(node.key)..left = _cloneNode(node.left)
- ..right = _cloneNode(node.right);
+ return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left)
+ ..right = _copyNode(node.right);
}
void clear() { _clear(); }
« 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