OK needs to contain a (dict) value.

This commit is contained in:
Tony Garnock-Jones 2015-07-01 13:51:14 -04:00
parent 233e4ffec8
commit d80ff03821
3 changed files with 19 additions and 7 deletions

4
main.c
View File

@ -34,7 +34,7 @@ int main0(int argc, char *argv[]) {
/* printf("======================================== LOOP ITERATION %d\n", outer); */
/* tt_dump_arena_summary(&a); */
for (i = 0; i < 1000000; i++) {
tt_node_ptr_t leaf = tt_cons_leaf(&a, TT_OK, 1001);
tt_node_ptr_t leaf = tt_cons_leaf(&a, TT_EMPTY, 1001);
tt_node_ptr_t curr = tt_cons_node(&a, 0, leaf, prev);
/* tt_dump_arena(&a); */
prev = curr;
@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
/* tt_dump_arena(&a); */
for (i = 0; i < 1000000; i++) {
tt_node_ptr_t next = tt_grab(&a, tt_dict_set(&a, curr, i, TT_OK));
tt_node_ptr_t next = tt_grab(&a, tt_dict_set(&a, curr, i, TT_EMPTY));
tt_drop(&a, curr);
curr = next;
/* printf("\nAfter i=%d...\n", i); */

View File

@ -295,6 +295,11 @@ void tt_dump_arena(tt_arena_t *a) {
tt_ptr_idx(a->nodes[n].a),
tt_ptr_tag(a->nodes[n].a));
break;
case TT_TAG_OK:
printf("ok %u/%u\n",
tt_ptr_idx(a->nodes[n].a),
tt_ptr_tag(a->nodes[n].a));
break;
case TT_TAG_BRANCH:
printf("branch %u/%u %u/%u\n",
tt_ptr_idx(a->nodes[n].a),
@ -355,7 +360,7 @@ void tt_arena_flush(tt_arena_t *a) {
static inline int heap_tag_p(tt_node_ptr_t p) {
tt_tag_t tag = tt_ptr_tag(p);
return tag != TT_TAG_SPECIAL && tag != TT_TAG_RESERVED0 && tag != TT_TAG_INVALID;
return tag != TT_TAG_SPECIAL && tag != TT_TAG_INVALID;
}
static void recycle_node(tt_arena_t *a, tt_node_ptr_t p) {

View File

@ -7,18 +7,20 @@ extern "C" {
typedef enum tt_tag_t {
TT_TAG_INVALID = 0, /* an invalid pointer - should only be used with 0 as index. */
/* Trie things */
TT_TAG_TAIL,
TT_TAG_OK,
TT_TAG_BRANCH,
/* Dict things */
TT_TAG_LEAF, /* node b points to atom, not node */
TT_TAG_NODE,
TT_TAG_DICT, /* node b is just an integer */
TT_TAG_RESERVED0, /* never used */
/* Generic things */
TT_TAG_SPECIAL, /* immediate special - all others are pointerlike */
} tt_tag_t;
typedef enum tt_special_idx_t {
TT_EMPTY_IDX, /* empty treetrie */
TT_OK_IDX, /* terminal marker */
TT_EMPTY_DICT_IDX, /* empty dict */
} tt_special_idx_t;
@ -29,12 +31,10 @@ typedef uint32_t tt_node_ptr_t; /* An index shifted left 2 with tag or'd in low
#define TT_NO_PTR ((tt_node_ptr_t) (0))
#define TT_EMPTY (tt_mkptr(TT_EMPTY_IDX, TT_TAG_SPECIAL))
#define TT_OK (tt_mkptr(TT_OK_IDX, TT_TAG_SPECIAL))
#define TT_EMPTY_DICT (tt_mkptr(TT_EMPTY_DICT_IDX, TT_TAG_SPECIAL))
#define TT_NO_PTR_P(x) ((x) == TT_NO_PTR)
#define TT_EMPTY_P(x) ((x) == TT_EMPTY)
#define TT_OK_P(x) ((x) == TT_OK)
#define TT_EMPTY_DICT_P(x) ((x) == TT_EMPTY_DICT)
#define RET_VAL_IF_NO_PTR(v,rv) \
@ -126,9 +126,15 @@ extern tt_node_ptr_t tt_grab(tt_arena_t *a, tt_node_ptr_t i);
extern void tt_drop(tt_arena_t *a, tt_node_ptr_t i);
static inline tt_node_ptr_t tt_cons_tail(tt_arena_t *a, tt_node_ptr_t p) {
/* p should point to a trie */
return tt_arena_cons(a, TT_TAG_TAIL, 0, p, TT_NO_PTR);
}
static inline tt_node_ptr_t tt_cons_ok(tt_arena_t *a, tt_node_ptr_t p) {
/* p should point to a dict */
return tt_arena_cons(a, TT_TAG_OK, 0, p, TT_NO_PTR);
}
static inline tt_node_ptr_t tt_cons_branch(tt_arena_t *a,
tt_node_ptr_t wildcard, /* trie */
tt_node_ptr_t others) /* dict */
@ -161,6 +167,7 @@ static inline tt_node_ptr_t tt_right(tt_arena_t *a, tt_node_ptr_t p) {
}
#define TT_TAIL_TRIE(a,p) tt_left(a,p)
#define TT_OK_DICT(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)