APPEND/PREPEND commands
[rxpd] / psplay.c
index bd5ab69..9b26fa1 100644 (file)
--- a/psplay.c
+++ b/psplay.c
@@ -99,7 +99,7 @@ psplay_splay (PSplay* root, PSplay node)
               if (node == p->left)
                 {
                   // zigzig
-                  if (psplay_fast_prng()&0xFF >= PSPLAY_PROB_ZIGZIG)
+                  if ((psplay_fast_prng()&0xFF) >= PSPLAY_PROB_ZIGZIG)
                     return;
 
                   g->left = p->right;
@@ -116,7 +116,7 @@ psplay_splay (PSplay* root, PSplay node)
               else
                 {
                   // zigzag
-                  if (psplay_fast_prng()&0xFF >= PSPLAY_PROB_ZIGZAG)
+                  if ((psplay_fast_prng()&0xFF) >= PSPLAY_PROB_ZIGZAG)
                     return;
 
                   p->right = node->left;
@@ -137,7 +137,7 @@ psplay_splay (PSplay* root, PSplay node)
               if (node == p->left)
                 {
                   // zagzig
-                  if (psplay_fast_prng()&0xFF >= PSPLAY_PROB_ZIGZAG)
+                  if ((psplay_fast_prng()&0xFF) >= PSPLAY_PROB_ZIGZAG)
                     return;
 
                   p->left = node->right;
@@ -154,7 +154,7 @@ psplay_splay (PSplay* root, PSplay node)
               else
                 {
                   // zagzag
-                  if (psplay_fast_prng()&0xFF >= PSPLAY_PROB_ZIGZIG)
+                  if ((psplay_fast_prng()&0xFF) >= PSPLAY_PROB_ZIGZIG)
                     return;
 
                   g->right = p->left;
@@ -187,7 +187,7 @@ psplay_splay (PSplay* root, PSplay node)
         {
           if (p)
             {
-              if (psplay_fast_prng()&0xFF >= PSPLAY_PROB_ZIG)
+              if ((psplay_fast_prng()&0xFF) >= PSPLAY_PROB_ZIG)
                 return;
 
               if (node == p->left)
@@ -228,6 +228,7 @@ psplay_init (PSplay self, const void* key)
       self->key = key;
       self->up = self->left = self->right = NULL;
     }
+  return self;
 }
 
 void
@@ -458,18 +459,23 @@ psplay_walk (PSplayroot root, PSplay node, psplay_action_t action, int level, vo
   return 1;
 }
 
-psplay_delete_t psplay_print_node (PSplay node, const enum psplay_order_e which, int level, void* data)
+psplay_delete_t
+psplay_print_node (PSplay node, const enum psplay_order_e which, int level, void* data)
 {
-  static char* sp = "                                        ";
-  if (level>40) return;
-
   FILE* fh = data;
+  static char* sp = "                                        ";
+  if (level>40)
+    {
+      if (which == PSPLAY_PREORDER)
+        fprintf (fh, "%s ...\n", sp+40-level);
+      return PSPLAY_CONT;
+    }
 
   switch (which)
     {
     case PSPLAY_PREORDER:
       fprintf (fh, "%s%p\n", sp+40-level, node);
-      fprintf (fh, "%skey %p (%.4s)\n", sp+40-level, node->key, node->key?node->key:"NULL");
+      fprintf (fh, "%skey %p (%.4s)\n", sp+40-level, (char*)node->key, node->key?(char*)node->key:"NULL");
       fprintf (fh, "%sup %p\n", sp+40-level, node->up);
       fprintf (fh, "%sleft %p\n", sp+40-level, node->left);
       break;
@@ -513,19 +519,19 @@ main ()
   psplay_dump (&root, stdout);
 
   PSplay f = psplay_find (&root, "baz");
-  printf ("found %p (%.4s)\n", f, f->key?f->key:"NULL");
+  printf ("found %p (%.4s)\n", f, f->key?(char*)f->key:"NULL");
   psplay_dump (&root, stdout);
 
   f = psplay_find (&root, "test");
-  printf ("found %p (%.4s)\n", f, f->key?f->key:"NULL");
+  printf ("found %p (%.4s)\n", f, f->key?(char*)f->key:"NULL");
   psplay_dump (&root, stdout);
 
   f = psplay_find (&root, "test");
-  printf ("found %p (%.4s)\n", f, f->key?f->key:"NULL");
+  printf ("found %p (%.4s)\n", f, f->key?(char*)f->key:"NULL");
   psplay_dump (&root, stdout);
 
   f = psplay_find (&root, "foo");
-  printf ("found %p (%.4s)\n", f, f->key?f->key:"NULL");
+  printf ("found %p (%.4s)\n", f, f->key?(char*)f->key:"NULL");
   psplay_dump (&root, stdout);