From: Florent Bruneau Date: Thu, 11 Sep 2008 11:58:41 +0000 (+0200) Subject: More informations in trie_inspect. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=87ce54fc19930cf850a3926199851ab99c808e92;p=apps%2Fpfixtools.git More informations in trie_inspect. Signed-off-by: Florent Bruneau --- diff --git a/common/trie.c b/common/trie.c index 2e3ada1..fd485ae 100644 --- a/common/trie.c +++ b/common/trie.c @@ -344,11 +344,17 @@ bool trie_lookup(const trie_t *trie, const char *key) static inline void trie_entry_inspect(const trie_t *trie, const trie_entry_t *entry, int level) { - static int c_sum = 0; - static int nodes = 0; + static int max_depth = 0; + static int leafs = 0; + static int depth_sum = 0; - ++nodes; - c_sum += entry->c_len; + if (trie_entry_is_leaf(entry)) { + if (level > max_depth) { + max_depth = level; + } + ++leafs; + depth_sum += level; + } for (int i = 0 ; i < level ; ++i) { fputs(" ", stdout); } @@ -371,7 +377,13 @@ static inline void trie_entry_inspect(const trie_t *trie, trie_entry_inspect(trie, &trie->entries[i], level + 1); } if (level == 0) { - printf("Mean char per node: %d\n", c_sum / nodes); + printf("Average char per node: %d\n", trie->c_len / trie->entries_len); + printf("Number of nodes: %d\n", trie->entries_len); + printf("Number of leafs: %d\n", leafs); + printf("Max depth: %d\n", max_depth); + printf("Average leaf depth: %d\n", depth_sum / leafs); + printf("Memory used: %d\n", (trie->entries_size * sizeof(trie_entry_t)) + + (trie->c_size) + sizeof(trie_t)); } } diff --git a/common/tst-trie.c b/common/tst-trie.c index 5e09079..4202261 100644 --- a/common/tst-trie.c +++ b/common/tst-trie.c @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) */ if (argc > 1) { trie = create_trie_from_file(argv[1]); -// trie_inspect(trie); + trie_inspect(trie); trie_delete(&trie); } return 0;