aboutsummaryrefslogtreecommitdiff
path: root/trie.inc.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 15:44:22 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-26 15:44:22 +0100
commita5f815b5787043ae99cb20c42cf2dbc3c10777bd (patch)
treef3814fc1cf06b3132e488ac0f190f9a34e5eebb0 /trie.inc.h
parentWIP. (diff)
downloadcalp-a5f815b5787043ae99cb20c42cf2dbc3c10777bd.tar.gz
calp-a5f815b5787043ae99cb20c42cf2dbc3c10777bd.tar.xz
Fix KEYS(TRIE(T)).
Diffstat (limited to 'trie.inc.h')
-rw-r--r--trie.inc.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/trie.inc.h b/trie.inc.h
index 3481dec2..92bfb0f9 100644
--- a/trie.inc.h
+++ b/trie.inc.h
@@ -159,8 +159,13 @@ FMT_F(TRIE_NODE(TYPE)) {
FMT_F(TRIE(TYPE)) {
int seek = 0;
- fmtf("Trie: %p: {\n", self);
- seek += FMT(TRIE_NODE(TYPE))(self->root->child, buf + seek);
+ fmtf("Trie: %p: {", self);
+ if (EMPTY(TRIE(TYPE))(self)) {
+ fmtf(" [EMPTY] ");
+ } else {
+ fmtf("\n");
+ seek += FMT(TRIE_NODE(TYPE))(self->root->child, buf + seek);
+ }
fmtf("}");
return seek;
}
@@ -195,16 +200,18 @@ void KEYS(TRIE_NODE(TYPE)) (TRIE_NODE(TYPE)* node, LLIST(strbuf)* list, strbuf*
if (node->value != NULL) {
strbuf_append(path, node->c);
- PUSH(LLIST(strbuf))(list, path);
+ NEW(strbuf, c);
+ DEEP_COPY(strbuf)(c, path);
+ PUSH(LLIST(strbuf))(list, c);
strbuf_pop(path);
}
if (node->next != NULL) {
KEYS(TRIE_NODE(TYPE)) (node->next, list, path);
}
if (node->child != NULL) {
- strbuf_append(path, node->c);
+ if (node->c != '\0') strbuf_append(path, node->c);
KEYS(TRIE_NODE(TYPE)) (node->child, list, path);
- strbuf_pop(path);
+ if (node->c != '\0') strbuf_pop(path);
}
}