Chromium Code Reviews| Index: corelib/src/implementation/splay_tree.dart |
| =================================================================== |
| --- corelib/src/implementation/splay_tree.dart (revision 4522) |
| +++ corelib/src/implementation/splay_tree.dart (working copy) |
| @@ -238,4 +238,46 @@ |
| String toString() { |
| return Maps.mapToString(this); |
| } |
| + |
| + V getMinimum() { |
|
sra1
2012/02/24 22:21:14
Can we avoid the use of 'get' in the name of metho
Anders Johnsen
2012/02/27 06:22:27
I agree, firstKey/lastKey is way better. The user
|
| + if (_root === null) return null; |
| + SplayTreeNode<K, V> node = _root; |
|
sra1
2012/02/24 22:21:14
Should min and max splay the tree?
I.e. do you co
Anders Johnsen
2012/02/27 06:22:27
I'm fine with splaying the tree, makes sense! Adde
|
| + while (node.left !== null) { |
| + node = node.left; |
| + } |
| + return node.value; |
| + } |
| + |
| + V getMaximum() { |
| + if (_root === null) return null; |
| + SplayTreeNode<K, V> node = _root; |
| + while (node.right !== null) { |
| + node = node.right; |
| + } |
| + return node.value; |
| + } |
| + |
| + V getPreceding(K key) { |
|
sra1
2012/02/24 22:21:14
It feels slightly wrong that preceding and succeed
Anders Johnsen
2012/02/27 06:22:27
Again, yes, this should be keys. I was using the v
|
| + splay_(key); |
| + if (_root === null) return null; |
| + SplayTreeNode<K, V> node = _root; |
| + if (node.left === null) return null; |
| + node = node.left; |
| + while (node.right !== null) { |
| + node = node.right; |
| + } |
| + return node.value; |
| + } |
| + |
| + V getSucceeding(K key) { |
| + splay_(key); |
| + if (_root === null) return null; |
| + SplayTreeNode<K, V> node = _root; |
| + if (node.right === null) return null; |
| + node = node.right; |
| + while (node.left !== null) { |
| + node = node.left; |
| + } |
| + return node.value; |
| + } |
| } |