union_set + example; step, no example yet

This commit is contained in:
Tony Garnock-Jones 2015-07-15 18:02:55 -04:00
parent 928027744e
commit 132f5b4218
3 changed files with 59 additions and 0 deletions

24
main.c
View File

@ -387,6 +387,30 @@ int main(int argc, char *argv[]) {
tt_drop(&a, d);
}
printf("\n============================================================ B\n");
{
tt_node_ptr_t A = tt_grab(&a, MAKE_PATH(&a, TT_EMPTY_DICT, {TT_BOS, 'A', TT_WILD, TT_EOS}));
printf("\nA node: %u/%u\n", tt_ptr_idx(A), tt_ptr_tag(A));
tt_arena_flush(&a);
tt_dump_arena_dot_styled("A", A, &a, TT_STYLE_TEXT_LABELS);
tt_dump_routingtable(&a, A, 0);
tt_node_ptr_t B = tt_grab(&a, MAKE_PATH(&a, TT_EMPTY_DICT, {TT_BOS, TT_WILD, 'B', TT_EOS}));
printf("\nB node: %u/%u\n", tt_ptr_idx(B), tt_ptr_tag(B));
tt_dump_arena_dot_styled("B", B, &a, TT_STYLE_TEXT_LABELS);
tt_dump_routingtable(&a, B, 0);
tt_node_ptr_t C = tt_trie_union_set(&a, A, B);
tt_arena_flush(&a);
tt_dump_arena_dot_styled("Cpredrop", C, &a, TT_STYLE_TEXT_LABELS);
tt_drop(&a, A);
tt_drop(&a, B);
printf("\nC node: %u/%u\n", tt_ptr_idx(C), tt_ptr_tag(C));
tt_arena_flush(&a);
tt_dump_arena_dot_styled("Cpostdrop", C, &a, TT_STYLE_TEXT_LABELS);
putchar('\n');
tt_dump_routingtable(&a, C, 0);
tt_drop(&a, C);
}
tt_arena_flush(&a);
tt_dump_arena_dot_styled("afterAll", TT_NO_PTR, &a, TT_STYLE_TEXT_LABELS); /* expect a_set and b_set here */

31
route.c
View File

@ -327,6 +327,17 @@ tt_node_ptr_t tt_trie_union_map(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r
return tt_trie_combine(a, r1, r2, 1, 1, 1, 1, NULL, f_union_map);
}
tt_node_ptr_t tt_trie_union_set(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r2) {
tt_node_ptr_t emptyset = tt_grab(a, RET_IF_NO_PTR(tt_cons_ok(a, TT_EMPTY_DICT)));
tt_node_ptr_t result;
tt_node_ptr_t f_union_map(void *f_context, tt_node_ptr_t r1, tt_node_ptr_t r2) {
return tt_grab(a, emptyset);
}
result = tt_trie_combine(a, r1, r2, 1, 1, 1, 1, NULL, f_union_map);
tt_drop(a, emptyset);
return result;
}
tt_node_ptr_t tt_trie_subtract_set(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r2) {
tt_node_ptr_t f_subtract_set(void *f_context, tt_node_ptr_t r1, tt_node_ptr_t r2) {
return TT_EMPTY;
@ -334,6 +345,26 @@ tt_node_ptr_t tt_trie_subtract_set(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_
return tt_trie_combine(a, r1, r2, 0, 1, 1, 0, NULL, f_subtract_set);
}
tt_node_ptr_t tt_trie_step(tt_arena_t *a, tt_node_ptr_t r, tt_atom_t key) {
if (TT_EMPTY_P(r)) {
return r;
}
switch (tt_ptr_tag(r)) {
case TT_TAG_OK:
return TT_EMPTY;
case TT_TAG_TAIL:
return (key == TT_EOS) ? TT_TAIL_TRIE(a,r) : r;
case TT_TAG_BRANCH:
return rlookup(a, r, key);
default:
assert(0);
}
}
tt_node_ptr_t tt_trie_relabel(tt_arena_t *a,
tt_node_ptr_t r,
void *f_context,

View File

@ -27,8 +27,12 @@ extern tt_node_ptr_t tt_trie_combine(tt_arena_t *a,
/* N.B. Returns a tt_grab'd result. */
extern tt_node_ptr_t tt_trie_union_map(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r2);
extern tt_node_ptr_t tt_trie_union_set(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r2);
extern tt_node_ptr_t tt_trie_subtract_set(tt_arena_t *a, tt_node_ptr_t r1, tt_node_ptr_t r2);
/* ungrab'd */
extern tt_node_ptr_t tt_trie_step(tt_arena_t *a, tt_node_ptr_t r, tt_atom_t key);
/* ungrab'd */
extern tt_node_ptr_t tt_trie_relabel(tt_arena_t *a,
tt_node_ptr_t r,