|
|
|
@ -192,11 +192,11 @@ static int trie_entry_set( struct trie_entry* e, const char* key, const char* va
|
|
|
|
|
struct edge* ed;
|
|
|
|
|
int key_length = strlen(key);
|
|
|
|
|
|
|
|
|
|
printf( "key: %s\n", key );
|
|
|
|
|
//printf( "key: %s\n", key );
|
|
|
|
|
for( int i = 0; i < e->edges.count; ++i ) {
|
|
|
|
|
ed = &e->edges.items[i];
|
|
|
|
|
printf( "label[%d]: %s\n", i, ed->label );
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
//printf( "label[%d]: %s\n", i, ed->label );
|
|
|
|
|
//fflush(stdout);
|
|
|
|
|
|
|
|
|
|
prefix_len = prefix_match( key, ed->label );
|
|
|
|
|
if( prefix_len == strlen( ed->label ) ) {
|
|
|
|
@ -222,9 +222,8 @@ update_existing:
|
|
|
|
|
return trie_entry_set_result_updated_existing;
|
|
|
|
|
|
|
|
|
|
add_new_edge:
|
|
|
|
|
printf( "add_new_edge\n" );
|
|
|
|
|
//printf( "add_new_edge %s\n", key );
|
|
|
|
|
{
|
|
|
|
|
printf( "Adding edge %s\n", key );
|
|
|
|
|
e->edges.count += 1;
|
|
|
|
|
e->edges.items = realloc( e->edges.items, sizeof(struct edge) * e->edges.count );
|
|
|
|
|
|
|
|
|
@ -237,7 +236,7 @@ add_new_edge:
|
|
|
|
|
return trie_entry_set_result_added_new;
|
|
|
|
|
|
|
|
|
|
traverse_existing_edge:
|
|
|
|
|
printf( "traverse_existing_edge\n" );
|
|
|
|
|
//printf( "traverse_existing_edge\n" );
|
|
|
|
|
if( ed->count == 1 ) {
|
|
|
|
|
free(ed->value);
|
|
|
|
|
ed->value = strdup(value);
|
|
|
|
@ -246,18 +245,18 @@ traverse_existing_edge:
|
|
|
|
|
|
|
|
|
|
char filename[512];
|
|
|
|
|
snprintf( filename, sizeof(filename), "%s%s", e->filename, ed->label );
|
|
|
|
|
printf( "Traversing down %s (filename=%s) key=%s, remaining=%s\n", ed->label, filename, key, &key[prefix_len] );
|
|
|
|
|
//printf( "Traversing down %s (filename=%s) key=%s, remaining=%s\n", ed->label, filename, key, &key[prefix_len] );
|
|
|
|
|
|
|
|
|
|
struct trie_entry branch;
|
|
|
|
|
memset(&branch,0,sizeof(branch));
|
|
|
|
|
trie_entry_load_from_file( filename, &branch );
|
|
|
|
|
int result = trie_entry_set( &branch, &key[prefix_len], value );
|
|
|
|
|
trie_entry_free_composite( &branch );
|
|
|
|
|
printf( "result=%d\n", result );
|
|
|
|
|
//printf( "result=%d\n", result );
|
|
|
|
|
|
|
|
|
|
// update count
|
|
|
|
|
if( result == trie_entry_set_result_added_new ) {
|
|
|
|
|
printf( "Updated edge count" );
|
|
|
|
|
//printf( "Updated edge count" );
|
|
|
|
|
ed->count += 1;
|
|
|
|
|
trie_entry_save_to_file( e->filename, e );
|
|
|
|
|
return trie_entry_set_result_added_new;
|
|
|
|
@ -266,7 +265,7 @@ traverse_existing_edge:
|
|
|
|
|
return trie_entry_set_result_updated_existing;
|
|
|
|
|
|
|
|
|
|
split_existing_edge:
|
|
|
|
|
printf( "split_existing_edge\n" );
|
|
|
|
|
//printf( "split_existing_edge\n" );
|
|
|
|
|
{
|
|
|
|
|
char* new_prefix = strndup( key, prefix_len );
|
|
|
|
|
char* new_filename = malloc(strlen(e->filename)+prefix_len+1);
|
|
|
|
@ -365,7 +364,7 @@ static char* lookup_key( struct trie_entry* e, const char* key )
|
|
|
|
|
|
|
|
|
|
if( match ) {
|
|
|
|
|
const char* remaining = &key[prefix_len];
|
|
|
|
|
printf( "match=%s, remaining=%s\n", ed->label, remaining );
|
|
|
|
|
//printf( "match=%s, remaining=%s\n", ed->label, remaining );
|
|
|
|
|
|
|
|
|
|
if( ed->count > 1 ) {
|
|
|
|
|
char filename[512];
|
|
|
|
@ -380,7 +379,7 @@ static char* lookup_key( struct trie_entry* e, const char* key )
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
if( 0 == strcmp( ed->label, key ) ) {
|
|
|
|
|
printf( "ed->label=%s, result=%s\n", ed->label, ed->value );
|
|
|
|
|
//printf( "ed->label=%s, result=%s\n", ed->label, ed->value );
|
|
|
|
|
return strdup(ed->value);
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|