[PATCH] STree_Find and STree_MaxDepth

Introduce two new helper functions:

STree_Find will return a pointer to the stree_node matching the given
string.

STree_MaxDepth just gives an upper bound on the depth of a particular R-B
tree. Since the number of entries is cached, this is trivial.

diff -urN a/common/shell.c head/common/shell.c
--- a/common/shell.c	2006-02-19 15:48:53.000000000 +1030
+++ head/common/shell.c	2006-02-19 15:32:53.000000000 +1030
@@ -215,6 +215,40 @@
     return result;
 }
 
+struct stree_node *
+STree_Find(struct stree_root *root, const char *s)
+{
+    struct rb_node **p = &root->root.rb_node;
+    struct rb_node *parent = NULL;
+    struct stree_node *ret = NULL;
+    struct stree_node *node;
+    int cmp;
+
+    while (*p) {
+	parent = *p;
+	node = stree_entry(parent);
+	cmp = strcasecmp(s, node->string);
+	if (cmp < 0)
+	    p = &(*p)->rb_left;
+	else if (cmp > 0)
+	    p = &(*p)->rb_right;
+	else {
+	    ret = node;
+	    break;
+	}
+    }
+
+    return ret;
+}
+
+/* An R-B Tree with n entries has a maximum height of 2log(n +1) */
+int
+STree_MaxDepth(struct stree_root *root)
+{
+    return 2 * Q_log2(root->entries + 1);
+}
+
+
 const char **completions_list = NULL;
 static int num_completions = 0;
 
diff -urN a/include/shell.h head/include/shell.h
--- a/include/shell.h	2006-02-19 15:48:53.000000000 +1030
+++ head/include/shell.h	2006-02-19 15:30:38.000000000 +1030
@@ -54,6 +54,8 @@
 qboolean STree_InsertAlloc(struct stree_root *root, const char *s,
 			   struct stree_node *n);
 char *STree_MaxMatch(struct stree_root *root, const char *pfx);
+struct stree_node *STree_Find(struct stree_root *root, const char *s);
+int STree_MaxDepth(struct stree_root *root);
 
 /*
  * Set up some basic completion helpers
