|
|
|
@ -62,7 +62,6 @@ static void trie_entry_free_composite( struct trie_entry* e )
|
|
|
|
|
if( e->dirty ) {
|
|
|
|
|
trie_entry_save_to_file( e->filename, e );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( int i = 0; i < e->edges.count; ++i ) {
|
|
|
|
|
free(e->edges.items[i].label);
|
|
|
|
|
free(e->edges.items[i].value);
|
|
|
|
@ -309,17 +308,17 @@ static void trie_entry_break_at( struct trie_entry* e, int* break_at )
|
|
|
|
|
printf( "\t\te->root->filename = %s\n", e->root->filename );
|
|
|
|
|
//printf( "\t\te->file_root->prefix = %s\n", e->file_root->prefix );
|
|
|
|
|
|
|
|
|
|
char* new_filename = aformat( "%s%s", e->root->filename, ed->child_trie->prefix );
|
|
|
|
|
struct trie_entry* broken_e = ed->child_trie;
|
|
|
|
|
|
|
|
|
|
char* new_filename = aformat( "%s%s", e->root->filename, broken_e->prefix );
|
|
|
|
|
printf( "\t\tnew_filename = %s\n", new_filename );
|
|
|
|
|
printf( "\t\ted->count = %d\n", ed->count );
|
|
|
|
|
|
|
|
|
|
ed->child_trie->filename = new_filename;
|
|
|
|
|
ed->child_trie->dirty = true;
|
|
|
|
|
ed->child_trie->file_root = ed->child_trie;
|
|
|
|
|
fixup_consolidated_trie( ed->child_trie );
|
|
|
|
|
trie_entry_save_to_file( ed->child_trie->filename, ed->child_trie );
|
|
|
|
|
|
|
|
|
|
e->file_root->dirty = true;
|
|
|
|
|
broken_e->filename = new_filename;
|
|
|
|
|
broken_e->file_root = broken_e;
|
|
|
|
|
fixup_consolidated_trie( broken_e );
|
|
|
|
|
trie_entry_save_to_file( broken_e->filename, broken_e );
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
} else {
|
|
|
|
|
trie_entry_break_at( ed->child_trie, break_at );
|
|
|
|
|
}
|
|
|
|
@ -448,7 +447,7 @@ static int trie_entry_add_new_edge( struct trie_entry* e, const char* key, const
|
|
|
|
|
ed2->count = 1;
|
|
|
|
|
ed2->child_trie = NULL;
|
|
|
|
|
|
|
|
|
|
e->file_root->dirty = true;
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
|
|
|
|
|
return trie_entry_set_result_added_new;
|
|
|
|
|
}
|
|
|
|
@ -463,7 +462,7 @@ static int trie_entry_delete_existing( struct trie_entry* e, struct edge* ed, co
|
|
|
|
|
free(tmp.label);
|
|
|
|
|
}
|
|
|
|
|
e->edges.count -= 1;
|
|
|
|
|
e->file_root->dirty = true;
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
return trie_entry_set_result_deleted_existing;
|
|
|
|
|
}
|
|
|
|
|
static int trie_entry_update_existing( struct trie_entry* e, struct edge* ed, const char* key, const char* value, int parent_count )
|
|
|
|
@ -474,7 +473,7 @@ static int trie_entry_update_existing( struct trie_entry* e, struct edge* ed, co
|
|
|
|
|
return trie_entry_delete_existing( e, ed, key, parent_count );
|
|
|
|
|
}
|
|
|
|
|
ed->value = strdup(value);
|
|
|
|
|
e->file_root->dirty = true;
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
|
|
|
|
|
return trie_entry_set_result_updated_existing;
|
|
|
|
|
}
|
|
|
|
@ -592,13 +591,13 @@ static int trie_entry_traverse_existing_edge( struct trie_entry* e, struct edge*
|
|
|
|
|
trie_entry_free(ed->child_trie);
|
|
|
|
|
ed->child_trie = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
printf( "deleting (2) %s\n", branch->filename );
|
|
|
|
|
remove( branch->filename );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Propigate dirty flag to parent if inline entry
|
|
|
|
|
if( needs_freed ) {
|
|
|
|
|
trie_entry_free(branch);
|
|
|
|
|
}
|
|
|
|
@ -847,6 +846,7 @@ static void fixup_consolidated_trie( struct trie_entry* e )
|
|
|
|
|
static struct trie_entry* trie_entry_load_and_try_consolidate( const char* filename, struct trie_entry* e, struct edge* ed, bool* needs_freed )
|
|
|
|
|
{
|
|
|
|
|
assert( e->file_root );
|
|
|
|
|
assert( e->file_root->filename );
|
|
|
|
|
assert( e->root );
|
|
|
|
|
assert( e->prefix );
|
|
|
|
|
|
|
|
|
@ -854,7 +854,7 @@ static struct trie_entry* trie_entry_load_and_try_consolidate( const char* filen
|
|
|
|
|
DEBUG_printf( "size=%lu, filename=%s\n", s, e->file_root->filename );
|
|
|
|
|
|
|
|
|
|
if( s < 4096 ) {
|
|
|
|
|
DEBUG_printf( "trie entry is %ld bytes, and has file child (%s), candidate for merge\n", s, filename );
|
|
|
|
|
DEBUG_printf( "trie entry %s is %ld bytes, and has file child (%s), candidate for merge\n", e->file_root->filename, s, filename );
|
|
|
|
|
|
|
|
|
|
ed->child_trie = malloc(sizeof(struct trie_entry));
|
|
|
|
|
memset(ed->child_trie,0,sizeof(struct trie_entry));
|
|
|
|
@ -871,8 +871,6 @@ static struct trie_entry* trie_entry_load_and_try_consolidate( const char* filen
|
|
|
|
|
ed->count += ed->child_trie->edges.items[i].count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//e->file_root->dirty = true;
|
|
|
|
|
//DEBUG_printf( "marking %s for Saving\n", e->file_root->filename );
|
|
|
|
|
trie_entry_save_to_file( e->file_root->filename, e->file_root );
|
|
|
|
|
|
|
|
|
|
DEBUG_printf( "deleting (1) %s\n", filename );
|
|
|
|
@ -954,10 +952,12 @@ static void load_items( struct trie_entry* e, int offset, int limit, struct stri
|
|
|
|
|
}
|
|
|
|
|
} else if( limit > 0 ) {
|
|
|
|
|
// leaf - include
|
|
|
|
|
DEBUG_printf( "Loading from '%s', offset=%d\n", e->prefix, offset );
|
|
|
|
|
char* key = aformat( "%s%s", e->prefix, ed->label );
|
|
|
|
|
DEBUG_printf( "Loading item %s=%s from '%s', offset=%d\n", key, ed->value, e->prefix, offset );
|
|
|
|
|
if( keys ) {
|
|
|
|
|
char* str = aformat( "%s%s", e->prefix, ed->label );
|
|
|
|
|
array_append( keys, sizeof(str), &str );
|
|
|
|
|
array_append( keys, sizeof(key), &key );
|
|
|
|
|
} else {
|
|
|
|
|
free(key);
|
|
|
|
|
}
|
|
|
|
|
if( values ) {
|
|
|
|
|
char* str = strdup( ed->value );
|
|
|
|
@ -965,6 +965,10 @@ static void load_items( struct trie_entry* e, int offset, int limit, struct stri
|
|
|
|
|
}
|
|
|
|
|
limit -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( limit == 0 ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DEBUG_printf( "Out of edges in '%s'\n", e->prefix );
|
|
|
|
|
}
|
|
|
|
|