Better collapse()

This commit is contained in:
Tony Garnock-Jones 2015-07-15 13:24:42 -04:00
parent e776864b45
commit 928027744e
2 changed files with 17 additions and 9 deletions

2
main.c
View File

@ -346,6 +346,7 @@ int main(int argc, char *argv[]) {
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);
printf("(calling tt_trie_subtract_set now)\n");
tt_node_ptr_t C = tt_trie_subtract_set(&a, A, B);
tt_arena_flush(&a);
tt_dump_arena_dot_styled("Cpredrop", C, &a, TT_STYLE_TEXT_LABELS);
@ -354,6 +355,7 @@ int main(int argc, char *argv[]) {
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 | TT_STYLE_HIDE_DETAILS);
tt_dump_routingtable(&a, C, 0);
tt_replace(&a, &C, tt_trie_relabel_const(&a, C, a_set));
printf("\nC node post relabel: %u/%u\n", tt_ptr_idx(C), tt_ptr_tag(C));
tt_arena_flush(&a);

24
route.c
View File

@ -143,17 +143,17 @@ static inline tt_node_ptr_t expand(tt_arena_t *a, tt_node_ptr_t tailnode) {
}
static inline tt_node_ptr_t collapse(tt_arena_t *a, tt_node_ptr_t n) {
/* This is a hand-inlined version of rupdate followed by rlookup of
TT_EOS, effectively undoing expand(). */
if (tt_ptr_tag(n) == TT_TAG_BRANCH) {
tt_node_ptr_t w = TT_BRANCH_WILDCARD(a,n);
tt_node_ptr_t o = TT_BRANCH_OTHERS(a,n);
if (tt_ptr_tag(w) == TT_TAG_TAIL &&
tt_ptr_tag(o) == TT_TAG_DICT &&
TT_DICT_SIZE(a,o) == 1) {
tt_node_ptr_t root = TT_DICT_ROOT(a,o);
assert(tt_ptr_tag(root) == TT_TAG_LEAF);
if (TT_LEAF_ATOM(a,root) == TT_EOS &&
TT_LEAF_TRIE(a,root) == TT_TAIL_TRIE(a,w)) {
return w;
if (tt_ptr_tag(o) == TT_TAG_DICT) {
tt_node_ptr_t eos_trie = tt_dict_get(a, o, TT_EOS);
if (!TT_NO_PTR_P(eos_trie)) {
tt_node_ptr_t w = TT_BRANCH_WILDCARD(a,n);
if (tt_ptr_tag(w) == TT_TAG_TAIL && eos_trie == TT_TAIL_TRIE(a,w)) {
return rbranch(a, w, RET_IF_NO_PTR(tt_dict_remove(a, o, TT_EOS)));
}
}
}
}
@ -209,6 +209,12 @@ tt_node_ptr_t tt_trie_combine(tt_arena_t *a,
tt_drop(a, trie1);
return 0;
}
/* printf("descending into key %d, trie1 %u/%u trie2 %u/%u\n", */
/* key, */
/* tt_ptr_idx(trie1), */
/* tt_ptr_tag(trie1), */
/* tt_ptr_idx(trie2), */
/* tt_ptr_tag(trie2)); */
new_trie = g(trie1, trie2); /* already grabbed */
tt_drop(a, trie1);
tt_drop(a, trie2);