# 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)
struct node {
#if USE_XYLA
- struct NODE _n;
+ TREE_NODEPFX;
#elif TREE == MLIB_SYM
struct sym_base _s;
#endif
#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;
}
# 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)
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)
# 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