|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "json/json.h"
|
|
|
|
#include "json/json.h"
|
|
|
|
#include "collections/array.h"
|
|
|
|
#include "collections/array.h"
|
|
|
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
@ -29,6 +30,7 @@ struct trie_entry
|
|
|
|
int count;
|
|
|
|
int count;
|
|
|
|
} edges;
|
|
|
|
} edges;
|
|
|
|
char* filename;
|
|
|
|
char* filename;
|
|
|
|
|
|
|
|
char* prefix;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
static void trie_entry_free_composite( struct trie_entry* e )
|
|
|
|
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->edges.items);
|
|
|
|
free(e->filename);
|
|
|
|
free(e->filename);
|
|
|
|
|
|
|
|
free(e->prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void trie_entry_free( struct trie_entry* e )
|
|
|
|
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 );
|
|
|
|
snprintf( filename, sizeof(filename), "%s%s", e->filename, ed->label );
|
|
|
|
|
|
|
|
|
|
|
|
struct trie_entry branch;
|
|
|
|
struct trie_entry branch;
|
|
|
|
|
|
|
|
memset(&branch,0,sizeof(branch));
|
|
|
|
|
|
|
|
|
|
|
|
trie_entry_load_from_file( filename, &branch );
|
|
|
|
trie_entry_load_from_file( filename, &branch );
|
|
|
|
char* result = lookup_key( &branch, remaining );
|
|
|
|
char* result = lookup_key( &branch, remaining );
|
|
|
|
trie_entry_free_composite(&branch);
|
|
|
|
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
|
|
|
|
// Load items from the branch
|
|
|
|
struct trie_entry branch;
|
|
|
|
struct trie_entry branch;
|
|
|
|
|
|
|
|
memset(&branch,0,sizeof(branch));
|
|
|
|
trie_entry_load_from_file( filename, &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 );
|
|
|
|
load_items( &branch, offset, branch_count, keys, values );
|
|
|
|
trie_entry_free_composite( &branch );
|
|
|
|
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 ) {
|
|
|
|
} else if( limit > 0 ) {
|
|
|
|
// leaf - include
|
|
|
|
// leaf - include
|
|
|
|
if( keys ) {
|
|
|
|
if( keys ) {
|
|
|
|
char* str = strdup(ed->label);
|
|
|
|
char* str = aformat( "%s%s", e->prefix, ed->label );
|
|
|
|
array_append( keys, sizeof(str), &str );
|
|
|
|
array_append( keys, sizeof(str), &str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( values ) {
|
|
|
|
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 )
|
|
|
|
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 );
|
|
|
|
struct trie_entry* root = load_root_node( filename );
|
|
|
|
|
|
|
|
root->prefix = strdup("");
|
|
|
|
load_items( root, offset, limit, keys_ptr, values_ptr );
|
|
|
|
load_items( root, offset, limit, keys_ptr, values_ptr );
|
|
|
|
trie_entry_free(root);
|
|
|
|
trie_entry_free(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|