Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
entry->children_len = 1;
} else {
if (entry->children_offset + entry->children_len != pchild) {
entry->children_len = 1;
} else {
if (entry->children_offset + entry->children_len != pchild) {
printf("Inserting child %d while offset is %d[%d]\n",
pchild, entry->children_offset, entry->children_len);
abort();
printf("Inserting child %d while offset is %d[%d]\n",
pchild, entry->children_offset, entry->children_len);
abort();
-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;
const trie_entry_t *entry, int level)
{
static int max_depth = 0;
++leaves;
depth_sum += level;
}
++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);
+ }
for (int i = entry->children_offset ;
i < entry->children_offset + entry->children_len ; ++i) {
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);
}
if (level == 0) {
printf("Average char per node: %d\n", trie->c_len / trie->entries_len);
-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);
bool trie_lookup(const trie_t *trie, const char* key);
__attribute__((nonnull(1)))
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);
trie_insert(trie, "coucou chez vous");
trie_insert(trie, "debout !");
trie_compile(trie, false);
trie_insert(trie, "coucou chez vous");
trie_insert(trie, "debout !");
trie_compile(trie, false);
+ trie_inspect(trie, true);
#define ASSERT_TRUE(str) \
if (!trie_lookup(trie, str)) { \
#define ASSERT_TRUE(str) \
if (!trie_lookup(trie, str)) { \
*/
if (argc > 1) {
trie = create_trie_from_file(argv[1]);
*/
if (argc > 1) {
trie = create_trie_from_file(argv[1]);
+ trie_inspect(trie, false);
trie_delete(&trie);
}
return 0;
trie_delete(&trie);
}
return 0;