rb.c

changeset 67
b53529762874
parent 66
42085c134e29
child 68
7a97a1769840
--- a/rb.c	Wed Mar 10 17:33:39 2004 +0100
+++ b/rb.c	Wed Mar 10 17:46:49 2004 +0100
@@ -183,13 +183,13 @@
   return rb_find_ikey_n(n, ikey, &fnd);
 }
  
-Rb_node rb_find_gkey_n(Rb_node n, void *key, Rb_compfn *fxn, int *fnd)
+Rb_node rb_find_gkey_n(Rb_node n, const void *key, Rb_compfn *fxn, int *fnd)
 {
   int cmp;
  
   *fnd = 0;
   if (!ishead(n)) {
-    fprintf(stderr, "rb_find_key_n called on non-head %p\n",
+    fprintf(stderr, "rb_find_gkey_n called on non-head %p\n",
             DONT_COMPLAIN n);
     exit(1);
   }
@@ -212,24 +212,40 @@
   }
 }
  
-Rb_node rb_find_gkey(Rb_node n, void *key, Rb_compfn *fxn)
+Rb_node rb_find_gkey(Rb_node n, const void *key, Rb_compfn *fxn)
 {
   int fnd;
   return rb_find_gkey_n(n, key, fxn, &fnd);
 }
 
-Rb_node rb_find_key_n(Rb_node n, char *key, int *fnd)
+Rb_node rb_find_key_n(Rb_node n, const char *key, int *fnd)
 {
   return rb_find_gkey_n(n, key, (Rb_compfn*)strcmp, fnd);
 }
  
-Rb_node rb_find_key(Rb_node n, char *key)
+Rb_node rb_find_key(Rb_node n, const char *key)
 {
   int fnd;
   return rb_find_gkey_n(n, key, (Rb_compfn*)strcmp, &fnd);
 }
 
-Rb_node rb_insert_b(Rb_node n, void *key, void *val)
+static int ptrcmp(const void *a, const void *b)
+{
+    return (a<b ? -1 : ((a==b) ? 0 : 1));
+}
+
+Rb_node rb_find_pkey_n(Rb_node n, const void *key, int *fnd)
+{
+  return rb_find_gkey_n(n, key, ptrcmp, fnd);
+}
+ 
+Rb_node rb_find_pkey(Rb_node n, const void *key)
+{
+  int fnd;
+  return rb_find_gkey_n(n, key, ptrcmp, &fnd);
+}
+
+Rb_node rb_insert_b(Rb_node n, const void *key, void *val)
 {
   Rb_node newleft, newright, newnode, list, p;
  
@@ -581,12 +597,12 @@
   return n->v.val;
 }
  
-Rb_node rb_insert_a(Rb_node nd, void *key, void *val)
+Rb_node rb_insert_a(Rb_node nd, const void *key, void *val)
 {
   return rb_insert_b(nd->c.list.flink, key, val);
 }
 
-Rb_node rb_insert(Rb_node tree, char *key, void *val)
+Rb_node rb_insert(Rb_node tree, const char *key, void *val)
 {
   return rb_insert_b(rb_find_key(tree, key), key, val);
 }
@@ -596,9 +612,14 @@
   return rb_insert_b(rb_find_ikey(tree, ikey), (void *) ikey, val);
 }
 
-Rb_node rb_insertg(Rb_node tree, void *key, void *val, Rb_compfn *func)
+Rb_node rb_insertg(Rb_node tree, const void *key, void *val, Rb_compfn *func)
 {
   return rb_insert_b(rb_find_gkey(tree, key, func), key, val);
 }
 
+Rb_node rb_insertp(Rb_node tree, const void *key, void *val)
+{
+  return rb_insertg(tree, key, val, ptrcmp);
+}
 
+

mercurial