OLD | NEW |
| (Empty) |
1 part of dart.collection; | |
2 typedef bool _Predicate<T>(T value); | |
3 class _SplayTreeNode<K> {final K key; | |
4 _SplayTreeNode<K> left; | |
5 _SplayTreeNode<K> right; | |
6 _SplayTreeNode(K this.key); | |
7 } | |
8 class _SplayTreeMapNode<K, V> extends _SplayTreeNode<K> {V value; | |
9 _SplayTreeMapNode(K key, V this.value) : super(key); | |
10 } | |
11 abstract class _SplayTree<K> {_SplayTreeNode<K> _root; | |
12 _SplayTreeNode<K> _dummy = new _SplayTreeNode<K>(null); | |
13 int _count = 0; | |
14 int _modificationCount = 0; | |
15 int _splayCount = 0; | |
16 int _compare(K key1, K key2); | |
17 int _splay(K key) { | |
18 if (_root == null) return -1; | |
19 _SplayTreeNode<K> left = _dummy; | |
20 _SplayTreeNode<K> right = _dummy; | |
21 _SplayTreeNode<K> current = _root; | |
22 int comp; | |
23 while (true) { | |
24 comp = _compare(current.key, key); | |
25 if (comp > 0) { | |
26 if (current.left == null) break; | |
27 comp = _compare(current.left.key, key); | |
28 if (comp > 0) { | |
29 _SplayTreeNode<K> tmp = current.left; | |
30 current.left = tmp.right; | |
31 tmp.right = current; | |
32 current = tmp; | |
33 if (current.left == null) break; | |
34 } | |
35 right.left = current; | |
36 right = current; | |
37 current = current.left; | |
38 } | |
39 else if (comp < 0) { | |
40 if (current.right == null) break; | |
41 comp = _compare(current.right.key, key); | |
42 if (comp < 0) { | |
43 _SplayTreeNode<K> tmp = current.right; | |
44 current.right = tmp.left; | |
45 tmp.left = current; | |
46 current = tmp; | |
47 if (current.right == null) break; | |
48 } | |
49 left.right = current; | |
50 left = current; | |
51 current = current.right; | |
52 } | |
53 else { | |
54 break; | |
55 } | |
56 } | |
57 left.right = current.left; | |
58 right.left = current.right; | |
59 current.left = _dummy.right; | |
60 current.right = _dummy.left; | |
61 _root = current; | |
62 _dummy.right = null; | |
63 _dummy.left = null; | |
64 _splayCount++; | |
65 return comp; | |
66 } | |
67 _SplayTreeNode<K> _splayMin(_SplayTreeNode<K> node) { | |
68 _SplayTreeNode current = node; | |
69 while (current.left != null) { | |
70 _SplayTreeNode left = current.left; | |
71 current.left = left.right; | |
72 left.right = current; | |
73 current = left; | |
74 } | |
75 return DEVC$RT.cast(current, DEVC$RT.type((_SplayTreeNode<dynamic> _) { | |
76 } | |
77 ), DEVC$RT.type((_SplayTreeNode<K> _) { | |
78 } | |
79 ), "CompositeCast", """line 151, column 12 of dart:collection/splay_tree.dart: "
"", current is _SplayTreeNode<K>, false); | |
80 } | |
81 _SplayTreeNode<K> _splayMax(_SplayTreeNode<K> node) { | |
82 _SplayTreeNode current = node; | |
83 while (current.right != null) { | |
84 _SplayTreeNode right = current.right; | |
85 current.right = right.left; | |
86 right.left = current; | |
87 current = right; | |
88 } | |
89 return DEVC$RT.cast(current, DEVC$RT.type((_SplayTreeNode<dynamic> _) { | |
90 } | |
91 ), DEVC$RT.type((_SplayTreeNode<K> _) { | |
92 } | |
93 ), "CompositeCast", """line 167, column 12 of dart:collection/splay_tree.dart: "
"", current is _SplayTreeNode<K>, false); | |
94 } | |
95 _SplayTreeNode _remove(K key) { | |
96 if (_root == null) return null; | |
97 int comp = _splay(key); | |
98 if (comp != 0) return null; | |
99 _SplayTreeNode result = _root; | |
100 _count--; | |
101 if (_root.left == null) { | |
102 _root = _root.right; | |
103 } | |
104 else { | |
105 _SplayTreeNode<K> right = _root.right; | |
106 _root = _splayMax(_root.left); | |
107 _root.right = right; | |
108 } | |
109 _modificationCount++; | |
110 return result; | |
111 } | |
112 void _addNewRoot(_SplayTreeNode<K> node, int comp) { | |
113 _count++; | |
114 _modificationCount++; | |
115 if (_root == null) { | |
116 _root = node; | |
117 return;} | |
118 if (comp < 0) { | |
119 node.left = _root; | |
120 node.right = _root.right; | |
121 _root.right = null; | |
122 } | |
123 else { | |
124 node.right = _root; | |
125 node.left = _root.left; | |
126 _root.left = null; | |
127 } | |
128 _root = node; | |
129 } | |
130 _SplayTreeNode get _first { | |
131 if (_root == null) return null; | |
132 _root = _splayMin(_root); | |
133 return _root; | |
134 } | |
135 _SplayTreeNode get _last { | |
136 if (_root == null) return null; | |
137 _root = _splayMax(_root); | |
138 return _root; | |
139 } | |
140 void _clear() { | |
141 _root = null; | |
142 _count = 0; | |
143 _modificationCount++; | |
144 } | |
145 } | |
146 class SplayTreeMap<K, V> extends _SplayTree<K> implements Map<K, V> {Comparator
<K> _comparator; | |
147 _Predicate<Object> _validKey; | |
148 SplayTreeMap([int compare(K key1, K key2), bool isValidKey(Object potentialKey)
]) : _comparator = ((__x12) => DEVC$RT.cast(__x12, dynamic, DEVC$RT.type((Compar
ator<K> _) { | |
149 } | |
150 ), "CompositeCast", """line 265, column 23 of dart:collection/splay_tree.dart: "
"", __x12 is Comparator<K>, false))((compare == null) ? Comparable.compare : com
pare), _validKey = (isValidKey != null) ? isValidKey : ((v) => v is K); | |
151 factory SplayTreeMap.from(Map other, [int compare(K key1, K key2), bool isValid
Key(Object potentialKey)]) { | |
152 SplayTreeMap<K, V> result = new SplayTreeMap<K, V>(); | |
153 other.forEach((k, v) { | |
154 result[DEVC$RT.cast(k, dynamic, K, "CompositeCast", """line 275, column 35 of da
rt:collection/splay_tree.dart: """, k is K, false)] = DEVC$RT.cast(v, dynamic, V
, "CompositeCast", """line 275, column 40 of dart:collection/splay_tree.dart: ""
", v is V, false); | |
155 } | |
156 ); | |
157 return result; | |
158 } | |
159 factory SplayTreeMap.fromIterable(Iterable iterable, { | |
160 K key(element), V value(element), int compare(K key1, K key2), bool isValidKey(O
bject potentialKey)} | |
161 ) { | |
162 SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare, isValidKey); | |
163 Maps._fillMapWithMappedIterable(map, iterable, key, value); | |
164 return map; | |
165 } | |
166 factory SplayTreeMap.fromIterables(Iterable<K> keys, Iterable<V> values, [int c
ompare(K key1, K key2), bool isValidKey(Object potentialKey)]) { | |
167 SplayTreeMap<K, V> map = new SplayTreeMap<K, V>(compare, isValidKey); | |
168 Maps._fillMapWithIterables(map, keys, values); | |
169 return map; | |
170 } | |
171 int _compare(K key1, K key2) => _comparator(key1, key2); | |
172 SplayTreeMap._internal(); | |
173 V operator [](Object key) { | |
174 if (key == null) throw new ArgumentError(key); | |
175 if (!_validKey(key)) return null; | |
176 if (_root != null) { | |
177 int comp = _splay(DEVC$RT.cast(key, Object, K, "CompositeCast", """line 328, col
umn 25 of dart:collection/splay_tree.dart: """, key is K, false)); | |
178 if (comp == 0) { | |
179 _SplayTreeMapNode mapRoot = DEVC$RT.cast(_root, DEVC$RT.type((_SplayTreeNode<K>
_) { | |
180 } | |
181 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
182 } | |
183 ), "AssignmentCast", """line 330, column 37 of dart:collection/splay_tree.dart:
""", _root is _SplayTreeMapNode<dynamic, dynamic>, true); | |
184 return DEVC$RT.cast(mapRoot.value, dynamic, V, "CompositeCast", """line 331, co
lumn 16 of dart:collection/splay_tree.dart: """, mapRoot.value is V, false); | |
185 } | |
186 } | |
187 return null; | |
188 } | |
189 V remove(Object key) { | |
190 if (!_validKey(key)) return null; | |
191 _SplayTreeMapNode mapRoot = ((__x13) => DEVC$RT.cast(__x13, DEVC$RT.type((_Spla
yTreeNode<dynamic> _) { | |
192 } | |
193 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
194 } | |
195 ), "AssignmentCast", """line 339, column 33 of dart:collection/splay_tree.dart:
""", __x13 is _SplayTreeMapNode<dynamic, dynamic>, true))(_remove(DEVC$RT.cast(k
ey, Object, K, "CompositeCast", """line 339, column 41 of dart:collection/splay_
tree.dart: """, key is K, false))); | |
196 if (mapRoot != null) return DEVC$RT.cast(mapRoot.value, dynamic, V, "CompositeC
ast", """line 340, column 33 of dart:collection/splay_tree.dart: """, mapRoot.va
lue is V, false); | |
197 return null; | |
198 } | |
199 void operator []=(K key, V value) { | |
200 if (key == null) throw new ArgumentError(key); | |
201 int comp = _splay(key); | |
202 if (comp == 0) { | |
203 _SplayTreeMapNode mapRoot = DEVC$RT.cast(_root, DEVC$RT.type((_SplayTreeNode<K>
_) { | |
204 } | |
205 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
206 } | |
207 ), "AssignmentCast", """line 350, column 35 of dart:collection/splay_tree.dart:
""", _root is _SplayTreeMapNode<dynamic, dynamic>, true); | |
208 mapRoot.value = value; | |
209 return;} | |
210 _addNewRoot(new _SplayTreeMapNode<K, dynamic>(key, value), comp); | |
211 } | |
212 V putIfAbsent(K key, V ifAbsent()) { | |
213 if (key == null) throw new ArgumentError(key); | |
214 int comp = _splay(key); | |
215 if (comp == 0) { | |
216 _SplayTreeMapNode mapRoot = DEVC$RT.cast(_root, DEVC$RT.type((_SplayTreeNode<K>
_) { | |
217 } | |
218 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
219 } | |
220 ), "AssignmentCast", """line 362, column 35 of dart:collection/splay_tree.dart:
""", _root is _SplayTreeMapNode<dynamic, dynamic>, true); | |
221 return DEVC$RT.cast(mapRoot.value, dynamic, V, "CompositeCast", """line 363, co
lumn 14 of dart:collection/splay_tree.dart: """, mapRoot.value is V, false); | |
222 } | |
223 int modificationCount = _modificationCount; | |
224 int splayCount = _splayCount; | |
225 V value = ifAbsent(); | |
226 if (modificationCount != _modificationCount) { | |
227 throw new ConcurrentModificationError(this); | |
228 } | |
229 if (splayCount != _splayCount) { | |
230 comp = _splay(key); | |
231 assert (comp != 0);} | |
232 _addNewRoot(new _SplayTreeMapNode<K, dynamic>(key, value), comp); | |
233 return value; | |
234 } | |
235 void addAll(Map<K, V> other) { | |
236 other.forEach((K key, V value) { | |
237 this[key] = value; | |
238 } | |
239 ); | |
240 } | |
241 bool get isEmpty { | |
242 return (_root == null); | |
243 } | |
244 bool get isNotEmpty => !isEmpty; | |
245 void forEach(void f(K key, V value)) { | |
246 Iterator<_SplayTreeNode<K>> nodes = new _SplayTreeNodeIterator<K>(this); | |
247 while (nodes.moveNext()) { | |
248 _SplayTreeMapNode<K, V> node = DEVC$RT.cast(nodes.current, DEVC$RT.type((_SplayT
reeNode<K> _) { | |
249 } | |
250 ), DEVC$RT.type((_SplayTreeMapNode<K, V> _) { | |
251 } | |
252 ), "CompositeCast", """line 394, column 38 of dart:collection/splay_tree.dart: "
"", nodes.current is _SplayTreeMapNode<K, V>, false); | |
253 f(node.key, node.value); | |
254 } | |
255 } | |
256 int get length { | |
257 return _count; | |
258 } | |
259 void clear() { | |
260 _clear(); | |
261 } | |
262 bool containsKey(Object key) { | |
263 return _validKey(key) && _splay(DEVC$RT.cast(key, Object, K, "CompositeCast", ""
"line 408, column 37 of dart:collection/splay_tree.dart: """, key is K, false))
== 0; | |
264 } | |
265 bool containsValue(Object value) { | |
266 bool found = false; | |
267 int initialSplayCount = _splayCount; | |
268 bool visit(_SplayTreeMapNode node) { | |
269 while (node != null) { | |
270 if (node.value == value) return true; | |
271 if (initialSplayCount != _splayCount) { | |
272 throw new ConcurrentModificationError(this); | |
273 } | |
274 if (node.right != null && visit(DEVC$RT.cast(node.right, DEVC$RT.type((_SplayTr
eeNode<dynamic> _) { | |
275 } | |
276 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
277 } | |
278 ), "ImplicitCast", """line 420, column 41 of dart:collection/splay_tree.dart: ""
", node.right is _SplayTreeMapNode<dynamic, dynamic>, true))) return true; | |
279 node = DEVC$RT.cast(node.left, DEVC$RT.type((_SplayTreeNode<dynamic> _) { | |
280 } | |
281 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
282 } | |
283 ), "ImplicitCast", """line 421, column 16 of dart:collection/splay_tree.dart: ""
", node.left is _SplayTreeMapNode<dynamic, dynamic>, true); | |
284 } | |
285 return false; | |
286 } | |
287 return visit(DEVC$RT.cast(_root, DEVC$RT.type((_SplayTreeNode<K> _) { | |
288 } | |
289 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
290 } | |
291 ), "ImplicitCast", """line 425, column 18 of dart:collection/splay_tree.dart: ""
", _root is _SplayTreeMapNode<dynamic, dynamic>, true)); | |
292 } | |
293 Iterable<K> get keys => new _SplayTreeKeyIterable<K>(this); | |
294 Iterable<V> get values => new _SplayTreeValueIterable<K, V>(this); | |
295 String toString() { | |
296 return Maps.mapToString(this); | |
297 } | |
298 K firstKey() { | |
299 if (_root == null) return null; | |
300 return DEVC$RT.cast(_first.key, dynamic, K, "CompositeCast", """line 441, colum
n 12 of dart:collection/splay_tree.dart: """, _first.key is K, false); | |
301 } | |
302 K lastKey() { | |
303 if (_root == null) return null; | |
304 return DEVC$RT.cast(_last.key, dynamic, K, "CompositeCast", """line 449, column
12 of dart:collection/splay_tree.dart: """, _last.key is K, false); | |
305 } | |
306 K lastKeyBefore(K key) { | |
307 if (key == null) throw new ArgumentError(key); | |
308 if (_root == null) return null; | |
309 int comp = _splay(key); | |
310 if (comp < 0) return _root.key; | |
311 _SplayTreeNode<K> node = _root.left; | |
312 if (node == null) return null; | |
313 while (node.right != null) { | |
314 node = node.right; | |
315 } | |
316 return node.key; | |
317 } | |
318 K firstKeyAfter(K key) { | |
319 if (key == null) throw new ArgumentError(key); | |
320 if (_root == null) return null; | |
321 int comp = _splay(key); | |
322 if (comp > 0) return _root.key; | |
323 _SplayTreeNode<K> node = _root.right; | |
324 if (node == null) return null; | |
325 while (node.left != null) { | |
326 node = node.left; | |
327 } | |
328 return node.key; | |
329 } | |
330 } | |
331 abstract class _SplayTreeIterator<T> implements Iterator<T> {final _SplayTree _
tree; | |
332 final List<_SplayTreeNode> _workList = <_SplayTreeNode> []; | |
333 int _modificationCount; | |
334 int _splayCount; | |
335 _SplayTreeNode _currentNode; | |
336 _SplayTreeIterator(_SplayTree tree) : _tree = tree, _modificationCount = tree._
modificationCount, _splayCount = tree._splayCount { | |
337 _findLeftMostDescendent(tree._root); | |
338 } | |
339 _SplayTreeIterator.startAt(_SplayTree tree, var startKey) : _tree = tree, _modi
ficationCount = tree._modificationCount { | |
340 if (tree._root == null) return; int compare = tree._splay(startKey); | |
341 _splayCount = tree._splayCount; | |
342 if (compare < 0) { | |
343 _findLeftMostDescendent(tree._root.right); | |
344 } | |
345 else { | |
346 _workList.add(tree._root); | |
347 } | |
348 } | |
349 T get current { | |
350 if (_currentNode == null) return null; | |
351 return _getValue(DEVC$RT.cast(_currentNode, DEVC$RT.type((_SplayTreeNode<dynami
c> _) { | |
352 } | |
353 ), DEVC$RT.type((_SplayTreeMapNode<dynamic, dynamic> _) { | |
354 } | |
355 ), "ImplicitCast", """line 545, column 22 of dart:collection/splay_tree.dart: ""
", _currentNode is _SplayTreeMapNode<dynamic, dynamic>, true)); | |
356 } | |
357 void _findLeftMostDescendent(_SplayTreeNode node) { | |
358 while (node != null) { | |
359 _workList.add(node); | |
360 node = node.left; | |
361 } | |
362 } | |
363 void _rebuildWorkList(_SplayTreeNode currentNode) { | |
364 assert (!_workList.isEmpty); _workList.clear(); | |
365 if (currentNode == null) { | |
366 _findLeftMostDescendent(_tree._root); | |
367 } | |
368 else { | |
369 _tree._splay(currentNode.key); | |
370 _findLeftMostDescendent(_tree._root.right); | |
371 assert (!_workList.isEmpty);} | |
372 } | |
373 bool moveNext() { | |
374 if (_modificationCount != _tree._modificationCount) { | |
375 throw new ConcurrentModificationError(_tree); | |
376 } | |
377 if (_workList.isEmpty) { | |
378 _currentNode = null; | |
379 return false; | |
380 } | |
381 if (_tree._splayCount != _splayCount && _currentNode != null) { | |
382 _rebuildWorkList(_currentNode); | |
383 } | |
384 _currentNode = _workList.removeLast(); | |
385 _findLeftMostDescendent(_currentNode.right); | |
386 return true; | |
387 } | |
388 T _getValue(_SplayTreeMapNode node); | |
389 } | |
390 class _SplayTreeKeyIterable<K> extends IterableBase<K> implements EfficientLeng
th {_SplayTree<K> _tree; | |
391 _SplayTreeKeyIterable(this._tree); | |
392 int get length => _tree._count; | |
393 bool get isEmpty => _tree._count == 0; | |
394 Iterator<K> get iterator => new _SplayTreeKeyIterator<K>(_tree); | |
395 Set<K> toSet() { | |
396 var setOrMap = _tree; | |
397 SplayTreeSet<K> set = new SplayTreeSet<K>(DEVC$RT.cast(setOrMap._comparator, dy
namic, DEVC$RT.type((__CastType14<K> _) { | |
398 } | |
399 ), "CompositeCast", """line 610, column 29 of dart:collection/splay_tree.dart: "
"", setOrMap._comparator is __CastType14<K>, false), DEVC$RT.cast(setOrMap._vali
dKey, dynamic, __CastType17, "CompositeCast", """line 610, column 51 of dart:col
lection/splay_tree.dart: """, setOrMap._validKey is __CastType17, false)); | |
400 set._count = _tree._count; | |
401 set._root = set._copyNode(_tree._root); | |
402 return set; | |
403 } | |
404 } | |
405 class _SplayTreeValueIterable<K, V> extends IterableBase<V> implements Efficien
tLength {SplayTreeMap<K, V> _map; | |
406 _SplayTreeValueIterable(this._map); | |
407 int get length => _map._count; | |
408 bool get isEmpty => _map._count == 0; | |
409 Iterator<V> get iterator => new _SplayTreeValueIterator<K, V>(_map); | |
410 } | |
411 class _SplayTreeKeyIterator<K> extends _SplayTreeIterator<K> {_SplayTreeKeyIter
ator(_SplayTree<K> map) : super(map); | |
412 K _getValue(_SplayTreeNode node) => DEVC$RT.cast(node.key, dynamic, K, "Composi
teCast", """line 628, column 39 of dart:collection/splay_tree.dart: """, node.ke
y is K, false); | |
413 } | |
414 class _SplayTreeValueIterator<K, V> extends _SplayTreeIterator<V> {_SplayTreeVa
lueIterator(SplayTreeMap<K, V> map) : super(map); | |
415 V _getValue(_SplayTreeMapNode node) => DEVC$RT.cast(node.value, dynamic, V, "Co
mpositeCast", """line 633, column 42 of dart:collection/splay_tree.dart: """, no
de.value is V, false); | |
416 } | |
417 class _SplayTreeNodeIterator<K> extends _SplayTreeIterator<_SplayTreeNode<K>> {
_SplayTreeNodeIterator(_SplayTree<K> tree) : super(tree); | |
418 _SplayTreeNodeIterator.startAt(_SplayTree<K> tree, var startKey) : super.startA
t(tree, startKey); | |
419 _SplayTreeNode<K> _getValue(_SplayTreeNode node) => DEVC$RT.cast(node, DEVC$RT.
type((_SplayTreeNode<dynamic> _) { | |
420 } | |
421 ), DEVC$RT.type((_SplayTreeNode<K> _) { | |
422 } | |
423 ), "CompositeCast", """line 641, column 55 of dart:collection/splay_tree.dart: "
"", node is _SplayTreeNode<K>, false); | |
424 } | |
425 class SplayTreeSet<E> extends _SplayTree<E> with IterableMixin<E>, SetMixin<E>
{Comparator<E> _comparator; | |
426 _Predicate<Object> _validKey; | |
427 SplayTreeSet([int compare(E key1, E key2), bool isValidKey(Object potentialKey)
]) : _comparator = ((__x19) => DEVC$RT.cast(__x19, dynamic, DEVC$RT.type((Compar
ator<E> _) { | |
428 } | |
429 ), "CompositeCast", """line 691, column 23 of dart:collection/splay_tree.dart: "
"", __x19 is Comparator<E>, false))((compare == null) ? Comparable.compare : com
pare), _validKey = (isValidKey != null) ? isValidKey : ((v) => v is E); | |
430 factory SplayTreeSet.from(Iterable elements, [int compare(E key1, E key2), bool
isValidKey(Object potentialKey)]) { | |
431 SplayTreeSet<E> result = new SplayTreeSet<E>(compare, isValidKey); | |
432 for (final E element in DEVC$RT.cast(elements, DEVC$RT.type((Iterable<dynamic>
_) { | |
433 } | |
434 ), DEVC$RT.type((Iterable<E> _) { | |
435 } | |
436 ), "CompositeCast", """line 705, column 29 of dart:collection/splay_tree.dart: "
"", elements is Iterable<E>, false)) { | |
437 result.add(element); | |
438 } | |
439 return result; | |
440 } | |
441 int _compare(E e1, E e2) => _comparator(e1, e2); | |
442 Iterator<E> get iterator => new _SplayTreeKeyIterator<E>(this); | |
443 int get length => _count; | |
444 bool get isEmpty => _root == null; | |
445 bool get isNotEmpty => _root != null; | |
446 E get first { | |
447 if (_count == 0) throw IterableElementError.noElement(); | |
448 return DEVC$RT.cast(_first.key, dynamic, E, "CompositeCast", """line 723, colum
n 12 of dart:collection/splay_tree.dart: """, _first.key is E, false); | |
449 } | |
450 E get last { | |
451 if (_count == 0) throw IterableElementError.noElement(); | |
452 return DEVC$RT.cast(_last.key, dynamic, E, "CompositeCast", """line 728, column
12 of dart:collection/splay_tree.dart: """, _last.key is E, false); | |
453 } | |
454 E get single { | |
455 if (_count == 0) throw IterableElementError.noElement(); | |
456 if (_count > 1) throw IterableElementError.tooMany(); | |
457 return _root.key; | |
458 } | |
459 bool contains(Object object) { | |
460 return _validKey(object) && _splay(DEVC$RT.cast(object, Object, E, "CompositeCas
t", """line 739, column 40 of dart:collection/splay_tree.dart: """, object is E,
false)) == 0; | |
461 } | |
462 bool add(E element) { | |
463 int compare = _splay(element); | |
464 if (compare == 0) return false; | |
465 _addNewRoot(new _SplayTreeNode<E>(element), compare); | |
466 return true; | |
467 } | |
468 bool remove(Object object) { | |
469 if (!_validKey(object)) return false; | |
470 return _remove(DEVC$RT.cast(object, Object, E, "CompositeCast", """line 751, co
lumn 20 of dart:collection/splay_tree.dart: """, object is E, false)) != null; | |
471 } | |
472 void addAll(Iterable<E> elements) { | |
473 for (E element in elements) { | |
474 int compare = _splay(element); | |
475 if (compare != 0) { | |
476 _addNewRoot(new _SplayTreeNode<E>(element), compare); | |
477 } | |
478 } | |
479 } | |
480 void removeAll(Iterable<Object> elements) { | |
481 for (Object element in elements) { | |
482 if (_validKey(element)) _remove(DEVC$RT.cast(element, Object, E, "CompositeCast"
, """line 765, column 39 of dart:collection/splay_tree.dart: """, element is E,
false)); | |
483 } | |
484 } | |
485 void retainAll(Iterable<Object> elements) { | |
486 SplayTreeSet<E> retainSet = new SplayTreeSet<E>(_comparator, _validKey); | |
487 int modificationCount = _modificationCount; | |
488 for (Object object in elements) { | |
489 if (modificationCount != _modificationCount) { | |
490 throw new ConcurrentModificationError(this); | |
491 } | |
492 if (_validKey(object) && _splay(DEVC$RT.cast(object, Object, E, "CompositeCast"
, """line 779, column 39 of dart:collection/splay_tree.dart: """, object is E, f
alse)) == 0) retainSet.add(_root.key); | |
493 } | |
494 if (retainSet._count != _count) { | |
495 _root = retainSet._root; | |
496 _count = retainSet._count; | |
497 _modificationCount++; | |
498 } | |
499 } | |
500 E lookup(Object object) { | |
501 if (!_validKey(object)) return null; | |
502 int comp = _splay(DEVC$RT.cast(object, Object, E, "CompositeCast", """line 791,
column 23 of dart:collection/splay_tree.dart: """, object is E, false)); | |
503 if (comp != 0) return null; | |
504 return _root.key; | |
505 } | |
506 Set<E> intersection(Set<Object> other) { | |
507 Set<E> result = new SplayTreeSet<E>(_comparator, _validKey); | |
508 for (E element in this) { | |
509 if (other.contains(element)) result.add(element); | |
510 } | |
511 return result; | |
512 } | |
513 Set<E> difference(Set<Object> other) { | |
514 Set<E> result = new SplayTreeSet<E>(_comparator, _validKey); | |
515 for (E element in this) { | |
516 if (!other.contains(element)) result.add(element); | |
517 } | |
518 return result; | |
519 } | |
520 Set<E> union(Set<E> other) { | |
521 return _clone()..addAll(other); | |
522 } | |
523 SplayTreeSet<E> _clone() { | |
524 var set = new SplayTreeSet<E>(_comparator, _validKey); | |
525 set._count = _count; | |
526 set._root = _copyNode(_root); | |
527 return set; | |
528 } | |
529 _SplayTreeNode<E> _copyNode(_SplayTreeNode<E> node) { | |
530 if (node == null) return null; | |
531 return new _SplayTreeNode<E>(node.key)..left = _copyNode(node.left)..right = _c
opyNode(node.right); | |
532 } | |
533 void clear() { | |
534 _clear(); | |
535 } | |
536 Set<E> toSet() => _clone(); | |
537 String toString() => IterableBase.iterableToFullString(this, '{', '}'); | |
538 } | |
539 typedef int __CastType14<K>(K __u15, K __u16); | |
540 typedef bool __CastType17(Object __u18); | |
OLD | NEW |