+
+
+/* Debug {{{1
+ */
+
+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;
+
+ ++nodes;
+ c_sum += entry->c_len;
+ 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;
+ for (int i = 0 ; i < entry->c_len ; ++i) {
+ if (c[i]) {
+ printf("%c ", c[i]);
+ } else {
+ fputs("\\0 ", stdout);
+ }
+ }
+ }
+ fputs("\n", stdout);
+ for (int i = 0 ; i < entry->children_len ; ++i) {
+ trie_entry_inspect(trie, &trie->entries[entry->children[i]], level + 1);
+ }
+ if (level == 0) {
+ printf("Mean char per node: %d\n", c_sum / nodes);
+ }
+}
+
+void trie_inspect(const trie_t *trie)
+{
+ trie_entry_inspect(trie, trie->entries, 0);
+}