chiark / gitweb /
@@@ tweak mdw/splay.mess
authorMark Wooding <mdw@distorted.org.uk>
Sat, 29 Mar 2025 19:17:45 +0000 (19:17 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 30 Mar 2025 02:47:48 +0000 (03:47 +0100)
Makefile.am
avl-path.c
avl-splitjoin.c
bt-rm.c
bt-set.c
bt.h
rb.h
t/commontest.in
t/soak
t/tests.at
t/treetest.c

index faaccbd53199adb75bf4711a77bf1bfcfdc99e94..d43be71958a0b6e6742a819c9d9716de25702926 100644 (file)
@@ -117,6 +117,9 @@ SUBDIRS                     += t
 dist-hook::
        echo $(VERSION) >$(distdir)/RELEASE
 
+## Additional documentation.
+EXTRA_DIST             += README.org
+
 ## Build tools.
 EXTRA_DIST             += config/auto-version
 EXTRA_DIST             += config/confsubst
index 37228d5cbefab8d7630d413cf3dede24b378b3f6..772cbc79dfb011e625db5eb58bf67192e99b6549 100644 (file)
@@ -233,8 +233,8 @@ void xyla_avl_replace(const struct xyla_avl_path *path,
   old_node = AVL_NODE(*path->p[k]); XYLA__ASSERT(old_node);
 
   node->bt = old_node->bt;
-  node->avl.f = (node->avl.f&~XYLA_AVLF_BALMASK) |
-               (old_node->avl.f&XYLA_AVLF_BALMASK);
+  node->avl.f =
+    (node->avl.f&~XYLA_AVLF_BALMASK) | (old_node->avl.f&XYLA_AVLF_BALMASK);
 }
 
 void xyla_avl_ripple(struct xyla_bt_nodecls *cls,
index a66c4d04e33a3d86fdded872fb55df455a397126..151ef2eae9acf9e0c09188b911027889b1fbff6e 100644 (file)
@@ -435,7 +435,7 @@ int xyla_avl_split(struct xyla_bt_nodecls *cls,
       case XYLA_AVLBAL_LBIAS: lht = ht - 1; rht = ht - 2; break;
       case XYLA_AVLBAL_EVEN: lht = rht = ht - 1; break;
       case XYLA_AVLBAL_RBIAS: lht = ht - 2; rht = ht - 1; break;
-      default: XYLA__ASSERT(0);
+      default: XYLA__ASSERT(0); lht = rht = -1; break;
     }
 
     /* Clear the split node's links, so that it's a standalone singleton
@@ -538,7 +538,7 @@ int xyla_avl_split(struct xyla_bt_nodecls *cls,
        case XYLA_AVLBAL_LBIAS: subht = ht - 1; ht++; break;
        case XYLA_AVLBAL_EVEN: subht = ht; ht++; break;
        case XYLA_AVLBAL_RBIAS: subht = ht + 1; ht += 2; break;
-       default: XYLA__ASSERT(0);
+       default: XYLA__ASSERT(0); subht = -1; break;
       }
       xyla_avl_join(cls, &right, &rht,
                    &right, rht, &parent->bt, &sub, subht);
@@ -548,7 +548,7 @@ int xyla_avl_split(struct xyla_bt_nodecls *cls,
        case XYLA_AVLBAL_LBIAS: subht = ht + 1; ht += 2; break;
        case XYLA_AVLBAL_EVEN: subht = ht; ht++; break;
        case XYLA_AVLBAL_RBIAS: subht = ht - 1; ht++; break;
-       default: XYLA__ASSERT(0);
+       default: XYLA__ASSERT(0); subht = -1; break;
       }
       xyla_avl_join(cls, &left, &lht,
                    &sub, subht, &parent->bt, &left, lht);
@@ -639,7 +639,7 @@ int xyla_avl_splitroot(struct xyla_bt_node **left_out, int *lht_out,
        case XYLA_AVLBAL_LBIAS: lht = ht - 1; rht = ht - 2; break;
        case XYLA_AVLBAL_EVEN: lht = rht = ht - 1; break;
        case XYLA_AVLBAL_RBIAS: lht = ht - 2; rht = ht - 1; break;
-       default: XYLA__ASSERT(0);
+       default: XYLA__ASSERT(0); lht = rht = -1; break;
       }
       if (lht_out) *lht_out = lht;
       if (rht_out) *rht_out = rht;
diff --git a/bt-rm.c b/bt-rm.c
index 5d4764e1d349c3d99692e7fb8dd6b3b674f04796..2fade3f928fc8e5a50d96d1da90f55b7bf6c372a 100644 (file)
--- a/bt-rm.c
+++ b/bt-rm.c
@@ -25,7 +25,6 @@
 
 /*----- Header files ------------------------------------------------------*/
 
-#include "lib.h"
 #include "bt.h"
 
 /*----- Main code ---------------------------------------------------------*/
index 8ee6ed342daea6a63bf8703f181b38320f2f3a54..8f7bb852783b482e6a8e42ae01e351c9f79de153 100644 (file)
--- a/bt-set.c
+++ b/bt-set.c
@@ -76,8 +76,6 @@ int xyla_bt_unisect(struct xyla_bt_nodecls *cls,
 
   enum { RIGHT, JOIN };
 
-  XYLA__ASSERT(keyfn);
-
   /* This is an essentially recursive procedure based on the following
    * observations.  Let A and B be sets of ordered elements.
    *
@@ -302,8 +300,6 @@ int xyla_bt_diffsect(struct xyla_bt_nodecls *cls,
 
   enum { RIGHT, JOIN };
 
-  XYLA__ASSERT(keyfn);
-
   /* This is an essentially recursive procedure, similar to `xyla_bt_unisect'
    * above, based on the following observations.  Let A and B be sets of
    * ordered elements.
diff --git a/bt.h b/bt.h
index 645cb037b9506b082c145db34816ba82298b68e6..f3eebea0da6d4e396340d943fc03ee82ac3e788b 100644 (file)
--- a/bt.h
+++ b/bt.h
@@ -40,7 +40,7 @@
 #  endif
 #else
 #  ifndef XYLA__ASSERT
-#    define XYLA__ASSERT(x) do ; while (0)
+#    define XYLA__ASSERT(x) do (void)(x); while (0)
 #  endif
 #endif
 
@@ -282,7 +282,8 @@ extern void *xyla_bt_severfirst(struct xyla_bt_node **/*root*/);
 #ifdef XYLA_FREESTANDING
 #  define XYLA_BT_COPYPATH(newpath, path, k) do {                      \
      struct xyla_bt_node                                               \
-       ***_newpath = (newpath), **const *_path = (path);               \
+       ***_newpath = (newpath),                                                \
+       **const *_path = (path);                                                \
      int _i, _n = (k) + 1;                                             \
                                                                        \
      for (_i = 0; _i < _n; _i++) _newpath[_i] = _path[_i];             \
diff --git a/rb.h b/rb.h
index b24ff6964fa819b4ef387a3a08afc200e0b5a123..dcfbd88b2f30281c1b9c4dfa804ca2d6ecdeda63 100644 (file)
--- a/rb.h
+++ b/rb.h
@@ -221,7 +221,6 @@ extern void *xyla_rb_prev(struct xyla_rb_riter */*rit*/);
    * It's probably better to use `xyla_bt_severfirst' for this task.
    */
 
-
 /*----- Paths -------------------------------------------------------------*/
 
 extern void *xyla_rb_current(const struct xyla_rb_path */*path*/);
index 226814121d86e09af73eb99c1e68e466efb036f7..17e4ddeee268db5aa9bd144ba405900c0ca605e3 100644 (file)
@@ -15,8 +15,7 @@
 
 :
 :;; iteration
-i
-j
+i j
 
 :
 :;; path motion and ascension
diff --git a/t/soak b/t/soak
index e43f42c61e8c919b29484c94ece78cf737ea9c1b..6d6031614880292da902e69259371cfc4c59ea3c 100755 (executable)
--- a/t/soak
+++ b/t/soak
@@ -148,14 +148,14 @@ class Options (object):
           dict(type = "int", metavar = "LIMIT",
                dest = "limit", default = None,
                help = "exclusive limit value to store in test trees")),
-         ("-s", "--seed",
-          dict(type = "string", metavar = "SEED",
-               dest = "seed", default = None,
-               help = "force initial seed")),
          ("-n", "--steps",
           dict(type = "int", metavar = "STEPS",
                dest = "nsteps", default = None,
                help = "number of steps to run before stopping")),
+         ("-s", "--seed",
+          dict(type = "string", metavar = "SEED",
+               dest = "seed", default = None,
+               help = "force initial seed")),
          ("-y", "--sync",
           dict(type = "int", metavar = "STEP",
                dest = "sync", default = None,
@@ -205,8 +205,8 @@ class State (object):
       me.cur = stack.pop()
       me.stack = stack
       if opts.seed is not None and me.seed != opts.seed:
-         raise ValueError("checkpointed seed `%s' /= "
-                          "command-line seed `%s'" % (me.seed, opts.seed))
+        raise ValueError("checkpointed seed `%s' /= "
+                         "command-line seed `%s'" % (me.seed, opts.seed))
       if opts.limit is not None and me.cur.limit != opts.limit:
         raise ValueError("checkpointed limit %d /= command-line limit %d" %
                          (me.cur.limit, opts.limit))
@@ -250,7 +250,7 @@ class State (object):
         OS.unlink(me._ckpt_file); OS.rename(new, me._ckpt_file)
   def clear_ckpt(me):
     try: OS.unlink(me._ckpt_file)
-    except IOError as err:
+    except OSError as err:
       if err.errno == E.ENOENT: pass
       else: raise
 
index c4f033931b02379a1eecdafd5d9fbf16bf296d42..72b399c6d4e07b5857e224200f3c3b3698366a02 100644 (file)
@@ -135,8 +135,8 @@ AT_CHECK([LTRUN TESTPROG_PATH/avltest in], [2],
        @%:@0x00000001 (n =   2)        (-) 4
        @%:@0x00000000 (n =   1)            (=) 3
 ],
-[XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000000 3> key not above lower bound
-XYLA-AVL @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000001 4> incorrect balance annotation `-' /= left 0 - 1 right
+[XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000000 3> key not above lower bound
+XYLA-AVL @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000001 4> incorrect balance annotation `-' /= left 0 - 1 right
 BUG: check failed: tree structure invalid (input pos = 19)
 ])
 AT_CLEANUP
@@ -152,10 +152,10 @@ AT_CHECK([LTRUN TESTPROG_PATH/rbtest in], [2],
        @%:@0x00000002 (n =   3)        ( ) 4
        @%:@0x00000001 (n =   1)                (*) 3
 ],
-[XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: root @%:@<node 0x00000002 4> is red
-XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: red @%:@<node 0x00000000 2> has red parent @%:@<node 0x00000002 4>
-XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000001 3> key not above lower bound
-XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000002 4> left black-height 0 /= 1 right black-height
+[XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: root @%:@<node @%:@0x00000002 4> is red
+XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: red @%:@<node @%:@0x00000000 2> has red parent @%:@<node @%:@0x00000002 4>
+XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000001 3> key not above lower bound
+XYLA-RB @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000002 4> left black-height 0 /= 1 right black-height
 BUG: check failed: tree structure invalid (input pos = 24)
 ])
 AT_CLEANUP
@@ -170,7 +170,7 @@ AT_CHECK([LTRUN TESTPROG_PATH/splaytest in], [2],
        @%:@0x00000001 (n =   2)        (*) 4
        @%:@0x00000000 (n =   1)            (*) 3
 ],
-[XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000000 3> key not above lower bound
+[XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000000 3> key not above lower bound
 BUG: check failed: tree structure invalid (input pos = 17)
 ])
 AT_CLEANUP
@@ -185,8 +185,8 @@ AT_CHECK([LTRUN TESTPROG_PATH/treaptest in], [2],
        @%:@0x00000001 (n =   2)        (*) 0x00000002$ 4
        @%:@0x00000000 (n =   1)            (*) 0x00000001$ 3
 ],
-[XYLA-TREAP @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000000 0x00000001$ 3> weight 1 < 2 weight of parent @%:@<node 0x00000001 0x00000002$ 4>
-XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node 0x00000000 0x00000001$ 3> key not above lower bound
+[XYLA-TREAP @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000000 0x00000001$ 3> weight 1 < 2 weight of parent @%:@<node @%:@0x00000001 0x00000002$ 4>
+XYLA-BT @%:@<root @<:@ADDR@:>@> BUG: @%:@<node @%:@0x00000000 0x00000001$ 3> key not above lower bound
 BUG: check failed: tree structure invalid (input pos = 23)
 ])
 AT_CLEANUP
index 7e323fd93f17f4e54a89f02f48591968c6e24135..a3a9ee79a662ff04a0a8049550d31a4c4af7c806 100644 (file)
@@ -88,7 +88,6 @@
 #define TREE_INITRITER tree__name(initriter)
 #define TREE_PREV tree__name(prev)
 #define TREE_CURRENT tree__name(current)
-#define TREE_COPYPATH tree__name(copypath)
 #define TREE_ROOTPATH tree__name(rootpath)
 #define TREE_UPPATH tree__name(uppath)
 #define TREE_LEFTPATH tree__name(leftpath)
 /*----- Preliminaries -----------------------------------------------------*/
 
 static FILE *in, *out;
-
 int stop = 0;
 
 #define BCAT_FAIL 1u
@@ -402,7 +400,8 @@ static void my_upd(struct xyla_bt_nodecls *cls, struct xyla_bt_node *node)
 {
   /* Update function to maintain node count. */
 
-  struct my_node *mynode = MY_NODE(node),
+  struct my_node
+    *mynode = MY_NODE(node),
     *left = MY_NODE(mynode->bt.left), *right = MY_NODE(mynode->bt.right);
 
   mynode->n = (left ? left->n : 0) + (right ? right->n : 0) + 1;
@@ -581,7 +580,7 @@ static void my_ident(struct xyla_bt_nodecls *cls,
 
   const struct my_node *my_node = CONST_MY_NODE(node);
 
-  fprintf(fp, "#<node 0x%08lx ", my_node->seq);
+  fprintf(fp, "#<node #0x%08lx ", my_node->seq);
 #if TREE == TREAP
   fprintf(fp, "0x%08lx$ ", (unsigned long)my_node->trp.wt);
 #endif
@@ -733,11 +732,7 @@ static size_t path_index(struct PATH *path)
   struct my_node *mynode, *myleft;
   size_t i = 0;
 
-#if TREE == SPLAY
-  mynode = path->f ? 0 : MY_SPLAY_NODE(path->node);
-#else
-  mynode = MY_NODE(*path->p[path->k]);
-#endif
+  mynode = TREE_CURRENT(path);
   if (mynode) {
     myleft = MY_NODE(mynode->bt.left);
     if (myleft) i += myleft->n;
@@ -837,7 +832,7 @@ static struct xyla_bt_node *read_tree(HELSE(int *ht_out, void))
       case -1: f = XYLA_AVLBAL_LBIAS; ht = lht + 1; break;
       case  0: f = XYLA_AVLBAL_EVEN; ht = lht + 1; break;
       case +1: f = XYLA_AVLBAL_RBIAS; ht = rht + 1; break;
-      default: bail(BCAT_ERR, "tree is not AVL"); ht = 0; break;
+      default: bail(BCAT_ERR, "tree is not AVL");
     }
   }
   node->my.avl.f = (node->my.avl.f&FLAGMASK) | f;
@@ -1013,7 +1008,7 @@ int main(int argc, char *argv[])
        i = read_int();
        do ch = getc(in); while (isspace(ch));
        if (ch == '-') j = read_int();
-       else { ungetc(ch, in); j = i; i = 1;    }
+       else { ungetc(ch, in); j = i; i = 1; }
        for (;;) {
          if (!TREE_PROBE(&mycls, &cur.root, my_ordnav, &i, &path)) {
            nodeu = make_node(i);
@@ -1203,8 +1198,7 @@ int main(int argc, char *argv[])
       case '/': /* split */
        if (sp > NSTACK - 2) bail(BCAT_ERR, "stack full");
        if (!(f&f_path)) bail(BCAT_ERR, "no path");
-       rc = TREE_SPLIT(&mycls,
-                       &stack[sp].root HARG(&stack[sp].ht),
+       rc = TREE_SPLIT(&mycls, &stack[sp].root HARG(&stack[sp].ht),
                        &btnode,
                        &cur.root HARG(&cur.ht),
                        &path);
@@ -1233,8 +1227,7 @@ int main(int argc, char *argv[])
       case '\\': /* difference/intersection */
        if (!sp) bail(BCAT_ERR, "stack empty");
        if (sp >= NSTACK) bail(BCAT_ERR, "stack full");
-       rc = TREE_DIFFSECT(&mycls,
-                          &cur.root HARG(&cur.ht),
+       rc = TREE_DIFFSECT(&mycls, &cur.root HARG(&cur.ht),
                           &stack[sp].root HARG(&stack[sp].ht),
                           &cur.root HARG(cur.ht),
                           &stack[sp - 1].root);
@@ -1303,8 +1296,7 @@ int main(int argc, char *argv[])
            putc('>', out);
          }
 #endif
-         putc(')', out);
-         putc('\n', out);
+         putc(')', out); putc('\n', out);
        }
        break;
 
@@ -1344,10 +1336,6 @@ int main(int argc, char *argv[])
        check_dump(&mycls, &cur.root HARG(cur.ht), CHKOUT_DUMP);
        break;
 
-      case 'S': /* seed */
-       seed = read_int();
-       break;
-
       case '!': /* check */
        check_dump(&mycls, &cur.root HARG(cur.ht), CHKOUT_NONE);
        break;
@@ -1364,6 +1352,10 @@ int main(int argc, char *argv[])
        node = 0; f &= ~(f_key | f_path | f_weight);
        break;
 
+      case 'S': /* seed */
+       seed = read_int();
+       break;
+
       case 'V': /* verbose */
        V( v = 0; )
        for (;;) {