Fix ffdb_trie_list

master
teknomunk 1 year ago
parent 730c340d66
commit a71ffab0d0

@ -2,6 +2,7 @@
#include "json/json.h"
#include "collections/array.h"
#include "format.h"
#include <stdlib.h>
#include <string.h>
@ -29,6 +30,7 @@ struct trie_entry
int count;
} edges;
char* filename;
char* prefix;
};
static void trie_entry_free_composite( struct trie_entry* e )
{
@ -38,6 +40,7 @@ static void trie_entry_free_composite( struct trie_entry* e )
}
free(e->edges.items);
free(e->filename);
free(e->prefix);
}
static void trie_entry_free( struct trie_entry* e )
{
@ -310,6 +313,8 @@ static char* lookup_key( struct trie_entry* e, const char* key )
snprintf( filename, sizeof(filename), "%s%s", e->filename, ed->label );
struct trie_entry branch;
memset(&branch,0,sizeof(branch));
trie_entry_load_from_file( filename, &branch );
char* result = lookup_key( &branch, remaining );
trie_entry_free_composite(&branch);
@ -391,7 +396,9 @@ static void load_items( struct trie_entry* e, int offset, int limit, struct stri
// Load items from the branch
struct trie_entry branch;
memset(&branch,0,sizeof(branch));
trie_entry_load_from_file( filename, &branch );
branch.prefix = aformat( "%s%s", e->prefix, ed->label );
load_items( &branch, offset, branch_count, keys, values );
trie_entry_free_composite( &branch );
@ -400,7 +407,7 @@ static void load_items( struct trie_entry* e, int offset, int limit, struct stri
} else if( limit > 0 ) {
// leaf - include
if( keys ) {
char* str = strdup(ed->label);
char* str = aformat( "%s%s", e->prefix, ed->label );
array_append( keys, sizeof(str), &str );
}
if( values ) {
@ -415,6 +422,7 @@ static void load_items( struct trie_entry* e, int offset, int limit, struct stri
void ffdb_trie_list( const char* filename, int offset, int limit, void* keys_ptr, void* values_ptr )
{
struct trie_entry* root = load_root_node( filename );
root->prefix = strdup("");
load_items( root, offset, limit, keys_ptr, values_ptr );
trie_entry_free(root);
}

Loading…
Cancel
Save