Add fixup for trie edge count too low, add stub for rebuilding trie

master
teknomunk 1 year ago
parent 34af1bef81
commit 2126183e06

@ -111,6 +111,15 @@ static bool trie_entry_load_from_file( const char* filename, struct trie_entry*
static void trie_entry_save( FILE* f, struct trie_entry* e )
{
for( int i = 0; i < e->edges.count; ++i ) {
struct edge* ed = &e->edges.items[i];
if( ed->count == 1 && !ed->value ) {
// Somehow the count on an edge was lower than the actual number of
// children. Don't save with invalid edge (implicit += 1 to edge count)
return;
}
}
// Selection Sort by edge
for( int i = 0; i < e->edges.count ; ++i ) {
int lowest = i;
@ -123,6 +132,7 @@ static void trie_entry_save( FILE* f, struct trie_entry* e )
}
}
if( lowest != i ) {
struct edge tmp;
memcpy( &tmp, &e->edges.items[i], sizeof(tmp) );
@ -212,6 +222,10 @@ static int prefix_match( const char* a, const char* b )
return res;
}
static void clean_trie_entry( struct trie_entry* e )
{
}
enum {
trie_entry_set_result_failed_to_add = 0,
trie_entry_set_result_updated_existing = 1,
@ -516,6 +530,17 @@ failed:
void ffdb_trie_clean( const char* filename )
{
struct trie_entry* root = NULL;
int result = 0;
root = load_root_node(filename);
if( !root ) { goto failed; }
cleanup:
trie_entry_free(root);
return;
failed:
goto cleanup;
}
struct string_array {
char** items;

Loading…
Cancel
Save