chiark / gitweb /
Makefile, chain.c: Track upstream changes to Xyla.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 30 Mar 2025 20:02:51 +0000 (21:02 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 30 Mar 2025 21:48:44 +0000 (22:48 +0100)
Makefile
chain.c

index b0d633aa2913e9bb4849190439c1427ff7589d33..00f3fc3325c461d796a661415d0675cd654bed86 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -83,7 +83,7 @@ VPATH                  =
 
 TREELIBS               += xyla
 xyla_VARIANTS           = avl rb splay treap
-XYLADIR                         = $(HOME)/src/libxyla
+XYLADIR                         = $(HOME)/src/xyla
 xyla_LIBS               = $(XYLADIR)/build/.libs/libxyla.a
 xyla_CFLAGS             = -I$(XYLADIR)
 xyla-avl_CFLAGS                 = -DTREE=XYLA_AVL
diff --git a/chain.c b/chain.c
index 707097b2344a9e219e929c99001f92e12ea696f9..36bd8525e98f4155c920c762dc38723d012839bd 100644 (file)
--- a/chain.c
+++ b/chain.c
 #  include "avl.h"
 #  define USE_XYLA 1
 #  define WANT_HEIGHT 1
+#  define TREE__NAME(name) XYLA_AVL_##name
 #  define tree__name(name) xyla_avl_##name
+#  define T avl
 #elif TREE == XYLA_RB
 #  include "rb.h"
 #  define USE_XYLA 1
 #  define WANT_HEIGHT 1
+#  define TREE__NAME(name) XYLA_RB_##name
 #  define tree__name(name) xyla_rb_##name
+#  define T rb
 #elif TREE == XYLA_SPLAY
 #  include "splay.h"
 #  define USE_XYLA 1
+#  undef WANT_HEIGHT
+#  define TREE__NAME(name) XYLA_SPLAY_##name
 #  define tree__name(name) xyla_splay_##name
+#  define T spl
 #elif TREE == XYLA_TREAP
 #  include "treap.h"
 #  define USE_XYLA 1
+#  undef WANT_HEIGHT
+#  define TREE__NAME(name) XYLA_TREAP_##name
 #  define tree__name(name) xyla_treap_##name
+#  define T trp
 #elif TREE == QPTRIE_QP
 #  include <stdbool.h>
 #  include <stdint.h>
 #  define NODE tree__name(node)
 #  define PATH tree__name(path)
 #  define ITER tree__name(iter)
+#  define TREE_NODEPFX TREE__NAME(NODEPFX)
+#  define TREE_NODEUSFX TREE__NAME(NODEUSFX)
 #  define TREE_CHECK tree__name(check)
 #  define TREE_LOOKUP tree__name(lookup)
 #  define TREE_PROBE tree__name(probe)
@@ -162,7 +174,7 @@ struct word { const char *p; size_t n; } word;
 
 struct node {
 #if USE_XYLA
-  struct NODE _n;
+  TREE_NODEPFX;
 #elif TREE == MLIB_SYM
   struct sym_base _s;
 #endif
@@ -206,8 +218,10 @@ static int compare_words(const struct word *a, const struct word *b)
 
 #if USE_XYLA
 
-static int word_nav(struct xyla_bst_nodecls *cls,
-                   const struct xyla_bst_node *nn, void *arg)
+union nodeu { struct node node; TREE_NODEUSFX; };
+
+static int word_nav(struct xyla_bt_nodecls *cls,
+                   const struct xyla_bt_node *nn, void *arg)
 {
   const struct word *k = arg;
   const struct node *node = (struct node *)nn;
@@ -216,14 +230,15 @@ static int word_nav(struct xyla_bst_nodecls *cls,
 }
 
 #  define DECLS                                                                \
-       struct xyla_bst_node *root = 0;                                 \
+       struct xyla_bt_node *root = 0;                                  \
+       union nodeu *nodeu;                                             \
        struct PATH path;                                               \
        struct ITER it
 
 #  define INIT do ; while (0)
 
 #  if TREE == XYLA_TREAP
-#    define EXTRA_NODE_SETUP do { node->_n.wt = rand(); } while (0)
+#    define EXTRA_NODE_SETUP do { node->trp.wt = rand(); } while (0)
 #  endif
 #  ifndef EXTRA_NODE_SETUP
 #    define EXTRA_NODE_SETUP do ; while (0)
@@ -234,12 +249,13 @@ static int word_nav(struct xyla_bst_nodecls *cls,
          free(node); node = 0;                                         \
        } else {                                                        \
          EXTRA_NODE_SETUP;                                             \
-         TREE_INSERT(0, &path, &node->_n);                             \
+         nodeu = (union nodeu *)node;                                  \
+         TREE_INSERT(0, &path, &nodeu->T);                             \
        }                                                               \
    } while (0)
 
 #  define ITERATE                                                      \
-       for (TREE_INITITER(&root, &it); node = TREE_NEXT(&it), node; )
+       for (TREE_INITITER(root, &it); node = TREE_NEXT(&it), node; )
 
 #  if TREE == XYLA_SPLAY
 #    define FOCUS do { xyla_splay_splay(0, &path); } while (0)
@@ -250,31 +266,32 @@ static int word_nav(struct xyla_bst_nodecls *cls,
 #  define LOOKUP TREE_LOOKUP(0, &root, word_nav, &word)
 
 #  define FREE do {                                                    \
-       while (node = xyla_bst_severfirst(&root), node) free(node);     \
+       while (node = xyla_bt_severfirst(&root), node) free(node);      \
    } while (0)
 
 #  ifndef WANT_CHECKS
 #    define CHECK do ; while (0)
 #  else
 
-static const void *word_key(struct xyla_bst_nodecls *cls,
-                           const struct xyla_bst_node *nn)
+static const void *word_key(struct xyla_bt_nodecls *cls,
+                           const struct xyla_bt_node *nn)
   { struct node *node = (struct node *)nn; return (&node->w); }
 
-static void word_ident(struct xyla_bst_nodecls *cls,
-                      const struct xyla_bst_node *nn, FILE *fp)
+static void word_ident(struct xyla_bt_nodecls *cls,
+                      const struct xyla_bt_node *nn, FILE *fp)
   { struct node *node = (struct node *)nn; fprintf(fp, "`%s'", node->w.p); }
 
-static const struct xyla_bst_ordnodeops word_ops = {
-  { 0, xyla_bst_chkorder, sizeof(struct xyla_bst_ordinfo), word_ident },
-  { word_nav, word_key }
+static const struct xyla_bt_chkops word_ops = {
+  { sizeof(word_ops), 0 },
+  { word_nav, word_key },
+  { xyla_bt_chkorder, sizeof(struct xyla_bt_ordinfo), word_ident }
 };
-struct xyla_bst_nodecls word_cls = { &word_ops.node };
+struct xyla_bt_nodecls word_cls = { &word_ops.node };
 
 #    define CHECK do {                                                 \
-       if (TREE_CHECK(&word_cls, &root HARG(-1), 0))                   \
+       if (TREE_CHECK(&word_cls, &root, stderr, 0 HARG(-1), 0))        \
          bail("check failed");                                         \
-      } while (0)
+     } while (0)
 #  endif
 
 #elif USE_QPTRIE