From e984c00379a8dfe9b5067431c9187c24bb9a0403 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 30 Jun 2015 12:25:05 -0400 Subject: [PATCH] Accessors --- treetrie.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/treetrie.h b/treetrie.h index a426635..76af74c 100644 --- a/treetrie.h +++ b/treetrie.h @@ -118,6 +118,23 @@ static inline tt_node_ptr_t tt_cons_node(tt_arena_t *a, return tt_arena_cons(a, TT_TAG_NODE, index, zero, one); } +static inline tt_node_ptr_t tt_left(tt_arena_t *a, tt_node_ptr_t p) { + return a->nodes[tt_ptr_idx(p)].a; +} + +static inline tt_node_ptr_t tt_right(tt_arena_t *a, tt_node_ptr_t p) { + return a->nodes[tt_ptr_idx(p)].b; +} + +#define TT_TAIL_TRIE(a,p) tt_left(a,p) +#define TT_BRANCH_WILDCARD(a,p) tt_left(a,p) +#define TT_BRANCH_OTHERS(a,p) tt_right(a,p) +#define TT_LEAF_TRIE(a,p) tt_left(a,p) +#define TT_LEAF_ATOM(a,p) ((tt_atom_t) tt_right(a,p)) +#define TT_NODE_INDEX(a,p) (a->headers[tt_ptr_idx(p)].inuse.index) +#define TT_NODE_ZERO(a,p) tt_left(a,p) +#define TT_NODE_ONE(a,p) tt_right(a,p) + #ifdef __cplusplus } #endif