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

Unified Diff: corelib/src/implementation/splay_tree.dart

Issue 9455051: Add getMinimum, getMaximum, getPreceding and getSucceeding to SplayTree. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698