| 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 } | 778 } |
| 779 | 779 |
| 780 E lookup(Object object) { | 780 E lookup(Object object) { |
| 781 if (!_validKey(object)) return null; | 781 if (!_validKey(object)) return null; |
| 782 int comp = _splay(object); | 782 int comp = _splay(object); |
| 783 if (comp != 0) return null; | 783 if (comp != 0) return null; |
| 784 return _root.key; | 784 return _root.key; |
| 785 } | 785 } |
| 786 | 786 |
| 787 Set<E> intersection(Set<E> other) { | 787 Set<E> intersection(Set<E> other) { |
| 788 Set<E> result = new SplayTreeSet<E>(_compare, _validKey); | 788 Set<E> result = new SplayTreeSet<E>(_comparator, _validKey); |
| 789 for (E element in this) { | 789 for (E element in this) { |
| 790 if (other.contains(element)) result.add(element); | 790 if (other.contains(element)) result.add(element); |
| 791 } | 791 } |
| 792 return result; | 792 return result; |
| 793 } | 793 } |
| 794 | 794 |
| 795 Set<E> difference(Set<E> other) { | 795 Set<E> difference(Set<E> other) { |
| 796 Set<E> result = new SplayTreeSet<E>(_compare, _validKey); | 796 Set<E> result = new SplayTreeSet<E>(_comparator, _validKey); |
| 797 for (E element in this) { | 797 for (E element in this) { |
| 798 if (!other.contains(element)) result.add(element); | 798 if (!other.contains(element)) result.add(element); |
| 799 } | 799 } |
| 800 return result; | 800 return result; |
| 801 } | 801 } |
| 802 | 802 |
| 803 Set<E> union(Set<E> other) { | 803 Set<E> union(Set<E> other) { |
| 804 return _clone()..addAll(other); | 804 return _clone()..addAll(other); |
| 805 } | 805 } |
| 806 | 806 |
| 807 SplayTreeSet<E> _clone() { | 807 SplayTreeSet<E> _clone() { |
| 808 var set = new SplayTreeSet<E>(_compare, _validKey); | 808 var set = new SplayTreeSet<E>(_comparator, _validKey); |
| 809 set._count = _count; | 809 set._count = _count; |
| 810 set._root = _cloneNode(_root); | 810 set._root = _cloneNode(_root); |
| 811 return set; | 811 return set; |
| 812 } | 812 } |
| 813 | 813 |
| 814 _SplayTreeNode<E> _cloneNode(_SplayTreeNode<E> node) { | 814 _SplayTreeNode<E> _cloneNode(_SplayTreeNode<E> node) { |
| 815 if (node == null) return null; | 815 if (node == null) return null; |
| 816 return new _SplayTreeNode<E>(node.key)..left = _cloneNode(node.left) | 816 return new _SplayTreeNode<E>(node.key)..left = _cloneNode(node.left) |
| 817 ..right = _cloneNode(node.right); | 817 ..right = _cloneNode(node.right); |
| 818 } | 818 } |
| 819 | 819 |
| 820 bool containsAll(Iterable<Object> other) { | 820 bool containsAll(Iterable<Object> other) { |
| 821 for (var element in other) { | 821 for (var element in other) { |
| 822 if (!this.contains(element)) return false; | 822 if (!this.contains(element)) return false; |
| 823 } | 823 } |
| 824 return true; | 824 return true; |
| 825 } | 825 } |
| 826 | 826 |
| 827 void clear() { _clear(); } | 827 void clear() { _clear(); } |
| 828 |
| 829 Set<E> toSet() => _clone(); |
| 828 } | 830 } |
| OLD | NEW |