@@ -6,36 +6,38 @@ part of dart.collection;
6
6
7
7
typedef _Predicate <T > = bool Function (T value);
8
8
9
- class _SplayTreeNodeBase <K > {
10
- _SplayTreeNode <K >? left;
11
- _SplayTreeNode <K >? right;
12
- }
13
-
14
9
/// A node in a splay tree. It holds the sorting key and the left
15
10
/// and right children in the tree.
16
- class _SplayTreeNode <K > extends _SplayTreeNodeBase <K > {
17
- final K key;
11
+ class _SplayTreeNode <K > {
12
+ // The key is nullable to be able to create a dummy node.
13
+ final K ? _key;
18
14
19
- _SplayTreeNode (this .key);
20
- }
15
+ _SplayTreeNode <K >? left;
16
+ _SplayTreeNode <K >? right;
17
+
18
+ _SplayTreeNode (this ._key);
21
19
22
- class _DummySplayTreeNode <K > extends _SplayTreeNodeBase <K >
23
- implements _SplayTreeNode <K > {
24
- K get key => throw UnsupportedError ("" );
20
+ K get key {
21
+ // TODO(dartbug.com/40892): replace with '_key as K'
22
+ K ? localKey = _key;
23
+ return (localKey != null ) ? localKey : localKey as K ;
24
+ }
25
25
}
26
26
27
27
/// A node in a splay tree based map.
28
28
///
29
29
/// A [_SplayTreeNode] that also contains a value
30
30
class _SplayTreeMapNode <K , V > extends _SplayTreeNode <K > {
31
- V value;
32
- _SplayTreeMapNode (K key, this .value) : super (key);
33
- }
31
+ // The value is nullable to be able to create a dummy node.
32
+ V ? _value;
33
+
34
+ _SplayTreeMapNode (K ? key, this ._value) : super (key);
34
35
35
- class _DummySplayTreeMapNode <K , V > extends _DummySplayTreeNode <K >
36
- implements _SplayTreeMapNode <K , V > {
37
- V get value => throw UnsupportedError ("" );
38
- set value (V v) => throw UnsupportedError ("" );
36
+ V get value {
37
+ // TODO(dartbug.com/40892): replace with '_value as V'
38
+ V ? localValue = _value;
39
+ return (localValue != null ) ? localValue : localValue as V ;
40
+ }
39
41
}
40
42
41
43
/// A splay tree is a self-balancing binary search tree.
@@ -264,7 +266,7 @@ Comparator<K> _defaultCompare<K>() {
264
266
class SplayTreeMap <K , V > extends _SplayTree <K , _SplayTreeMapNode <K , V >>
265
267
with MapMixin <K , V > {
266
268
_SplayTreeMapNode <K , V >? _root;
267
- final _SplayTreeMapNode <K , V > _dummy = _DummySplayTreeMapNode <K , V >();
269
+ final _SplayTreeMapNode <K , V > _dummy = _SplayTreeMapNode <K , V >(null , null );
268
270
269
271
Comparator <K > _comparator;
270
272
_Predicate _validKey;
@@ -359,7 +361,7 @@ class SplayTreeMap<K, V> extends _SplayTree<K, _SplayTreeMapNode<K, V>>
359
361
// the key to the root of the tree.
360
362
int comp = _splay (key);
361
363
if (comp == 0 ) {
362
- _root! .value = value;
364
+ _root! ._value = value;
363
365
return ;
364
366
}
365
367
_addNewRoot (_SplayTreeMapNode (key, value), comp);
@@ -652,7 +654,7 @@ class _SplayTreeNodeIterator<K>
652
654
class SplayTreeSet <E > extends _SplayTree <E , _SplayTreeNode <E >>
653
655
with IterableMixin <E >, SetMixin <E > {
654
656
_SplayTreeNode <E >? _root;
655
- final _SplayTreeNode <E > _dummy = _DummySplayTreeNode <E >();
657
+ final _SplayTreeNode <E > _dummy = _SplayTreeNode <E >(null );
656
658
657
659
Comparator <E > _comparator;
658
660
_Predicate _validKey;
0 commit comments