X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Ftrie.c;fp=common%2Ftrie.c;h=f58bd30638bbcde224e1aea1903005eec37371a5;hb=3df18edc2580a1cc3e95d427337e5afef042a83d;hp=cb39cb205bcc486d0a9ccdef849d474d6a91273b;hpb=44d04c83a53af19faecb1620cf0f9ed53054da5c;p=apps%2Fpfixtools.git diff --git a/common/trie.c b/common/trie.c index cb39cb2..f58bd30 100644 --- a/common/trie.c +++ b/common/trie.c @@ -111,7 +111,11 @@ static inline bool trie_entry_match(const trie_t *trie, static inline bool trie_entry_prefix(const trie_t *trie, const trie_entry_t *entry, const char *key) { - return !!(strncmp(array_ptr(trie->c, entry->c_offset), key, entry->c_len) == 0); + int len = entry->c_len; + if (len > 0 && array_elt(trie->c, entry->c_offset + len - 1) == '\0') { + --len; + } + return !!(strncmp(array_ptr(trie->c, entry->c_offset), key, len) == 0); } static inline bool trie_entry_is_leaf(const trie_entry_t *entry) @@ -366,6 +370,11 @@ static inline void trie_entry_inspect(const trie_t *trie, bool show_content, static int leaves = 0; static int depth_sum = 0; + if (entry == array_ptr(trie->entries, 0)) { + max_depth = 0; + leaves = 0; + depth_sum = 0; + } if (trie_entry_is_leaf(entry)) { if (level > max_depth) { max_depth = level;