From: Florent Bruneau Date: Thu, 11 Sep 2008 12:30:05 +0000 (+0200) Subject: Add show_content parameter to trie_inspect(). X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=12b47d65a20c3a3b6af86f828c77a77449d527c9;p=apps%2Fpfixtools.git Add show_content parameter to trie_inspect(). Signed-off-by: Florent Bruneau --- diff --git a/common/trie.c b/common/trie.c index 3ac0c69..dc84236 100644 --- a/common/trie.c +++ b/common/trie.c @@ -199,7 +199,6 @@ static inline void trie_entry_insert_child(trie_t *trie, trie_entry_t *entry, entry->children_len = 1; } else { if (entry->children_offset + entry->children_len != pchild) { - trie_inspect(trie); printf("Inserting child %d while offset is %d[%d]\n", pchild, entry->children_offset, entry->children_len); abort(); @@ -344,7 +343,7 @@ bool trie_lookup(const trie_t *trie, const char *key) /* Debug {{{1 */ -static inline void trie_entry_inspect(const trie_t *trie, +static inline void trie_entry_inspect(const trie_t *trie, bool show_content, const trie_entry_t *entry, int level) { static int max_depth = 0; @@ -358,26 +357,28 @@ static inline void trie_entry_inspect(const trie_t *trie, ++leaves; depth_sum += level; } - for (int i = 0 ; i < level ; ++i) { - fputs(" ", stdout); - } - if (entry->c_len == 0) { - fputs("(nil)", stdout); - } else { - const char *c = trie->c + entry->c_offset; - printf("(%d) ", entry->c_len); - for (int i = 0 ; i < entry->c_len ; ++i) { - if (c[i]) { - printf("%c ", c[i]); - } else { - fputs("\\0 ", stdout); + if (show_content) { + for (int i = 0 ; i < level ; ++i) { + fputs(" ", stdout); + } + if (entry->c_len == 0) { + fputs("(nil)", stdout); + } else { + const char *c = trie->c + entry->c_offset; + printf("(%d) ", entry->c_len); + for (int i = 0 ; i < entry->c_len ; ++i) { + if (c[i]) { + printf("%c ", c[i]); + } else { + fputs("\\0 ", stdout); + } } } + fputs("\n", stdout); } - fputs("\n", stdout); for (int i = entry->children_offset ; i < entry->children_offset + entry->children_len ; ++i) { - trie_entry_inspect(trie, &trie->entries[i], level + 1); + trie_entry_inspect(trie, show_content, &trie->entries[i], level + 1); } if (level == 0) { printf("Average char per node: %d\n", trie->c_len / trie->entries_len); @@ -390,7 +391,7 @@ static inline void trie_entry_inspect(const trie_t *trie, } } -void trie_inspect(const trie_t *trie) +void trie_inspect(const trie_t *trie, bool show_content) { - trie_entry_inspect(trie, trie->entries, 0); + trie_entry_inspect(trie, show_content, trie->entries, 0); } diff --git a/common/trie.h b/common/trie.h index c841fbd..c00a4af 100644 --- a/common/trie.h +++ b/common/trie.h @@ -53,6 +53,6 @@ __attribute__((nonnull(1,2))) bool trie_lookup(const trie_t *trie, const char* key); __attribute__((nonnull(1))) -void trie_inspect(const trie_t *trie); +void trie_inspect(const trie_t *trie, bool show_content); #endif diff --git a/common/tst-trie.c b/common/tst-trie.c index 77fd208..25f31c5 100644 --- a/common/tst-trie.c +++ b/common/tst-trie.c @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) trie_insert(trie, "coucou chez vous"); trie_insert(trie, "debout !"); trie_compile(trie, false); - trie_inspect(trie); + trie_inspect(trie, true); #define ASSERT_TRUE(str) \ if (!trie_lookup(trie, str)) { \ @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) */ if (argc > 1) { trie = create_trie_from_file(argv[1]); -// trie_inspect(trie); + trie_inspect(trie, false); trie_delete(&trie); } return 0;