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

Unified Diff: sdk/lib/collection/splay_tree.dart

Issue 289353002: Add SetBase/SetMixin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated to not use cloneEmpty Created 6 years, 7 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
« sdk/lib/collection/set.dart ('K') | « sdk/lib/collection/set.dart ('k') | no next file » | 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 8e2f5930eff58f4928cc88bcafc1996a6ecf6151..52cd942b23245f33af8af6bf5ae16ae2a034f6dc 100644
--- a/sdk/lib/collection/splay_tree.dart
+++ b/sdk/lib/collection/splay_tree.dart
@@ -639,8 +639,7 @@ class _SplayTreeNodeIterator<K>
* method. Non-comparable objects (including `null`) will not work as an element
* in that case.
*/
-class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
- implements Set<E> {
+class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>, SetMixin<E> {
Comparator _comparator;
_Predicate _validKey;
@@ -683,18 +682,18 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
bool get isNotEmpty => _root != null;
E get first {
- if (_count == 0) throw new StateError("no such element");
+ if (_count == 0) throw IterableElementError.noElement();
return _first.key;
}
E get last {
- if (_count == 0) throw new StateError("no such element");
+ if (_count == 0) throw IterableElementError.noElement();
return _last.key;
}
E get single {
- if (_count == 0) throw new StateError("no such element");
- if (_count > 1) throw new StateError("too many elements");
+ if (_count == 0) throw IterableElementError.noElement();
+ if (_count > 1) throw IterableElementError.tooMany();
return _root.key;
}
@@ -730,9 +729,6 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
}
}
- /**
- * Removes all elements not in [elements].
- */
void retainAll(Iterable<Object> elements) {
// Build a set with the same sense of equality as this set.
SplayTreeSet<E> retainSet = new SplayTreeSet<E>(_comparator, _validKey);
@@ -753,30 +749,6 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
}
}
- void _filterWhere(bool test(E element), bool removeMatching) {
- _SplayTreeNodeIterator it = new _SplayTreeNodeIterator(this);
- while (it.moveNext()) {
- _SplayTreeNode node = it.current;
- int modificationCount = _modificationCount;
- bool matches = test(node.key);
- if (modificationCount != _modificationCount) {
- throw new ConcurrentModificationError(this);
- }
- if (matches == removeMatching) {
- _remove(node.key);
- it = new _SplayTreeNodeIterator.startAt(this, node.key);
- }
- }
- }
-
- void removeWhere(bool test(E element)) {
- _filterWhere(test, true);
- }
-
- void retainWhere(bool test(E element)) {
- _filterWhere(test, false);
- }
-
E lookup(Object object) {
if (!_validKey(object)) return null;
int comp = _splay(object);
@@ -784,28 +756,8 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
return _root.key;
}
- Set<E> intersection(Set<E> other) {
- Set<E> result = new SplayTreeSet<E>(_compare, _validKey);
- for (E element in this) {
- if (other.contains(element)) result.add(element);
- }
- return result;
- }
-
- Set<E> difference(Set<E> other) {
- Set<E> result = new SplayTreeSet<E>(_compare, _validKey);
- for (E element in this) {
- if (!other.contains(element)) result.add(element);
- }
- return result;
- }
-
- Set<E> union(Set<E> other) {
- return _clone()..addAll(other);
- }
-
SplayTreeSet<E> _clone() {
- var set = new SplayTreeSet<E>(_compare, _validKey);
+ var set = new SplayTreeSet<E>(_comparator, _validKey);
set._count = _count;
set._root = _cloneNode(_root);
return set;
@@ -817,12 +769,7 @@ class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>
..right = _cloneNode(node.right);
}
- bool containsAll(Iterable<Object> other) {
- for (var element in other) {
- if (!this.contains(element)) return false;
- }
- return true;
- }
-
void clear() { _clear(); }
+
+ Set<E> toSet() => _clone();
}
« sdk/lib/collection/set.dart ('K') | « sdk/lib/collection/set.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698