node *LVARfundef( node *arg_node, info *arg_info) { DBUG_ENTER("LVARfundef"); arg_info->nest_level++; FUNDEF_HEADER(arg_node) = TRAVopt( FUNDEF_HEADER( arg_node), arg_info); FUNDEF_BODY(arg_node) = TRAVopt( FUNDEF_BODY( arg_node), arg_info); /* empty hashmap of local variables */ hashmap_empty(arg_info->local); arg_info->nest_level--; DBUG_RETURN( arg_node); }
int main(void) { entry *en; char *key, *value; int res; hashmap *hm = hashmap_empty(20, string_hash_function, entry_free_func); if (hm == NULL) { return EXIT_FAILURE; } printf("Inserting test entries...\n"); en = create_entry("cat", "goes meow"); res = hashmap_put(en, hm); if (res) { fprintf(stderr, "FAIL: OOM (Insert1)\n"); return EXIT_FAILURE; } en = create_entry("dog", "goes woof"); res = hashmap_put(en, hm); if (res) { fprintf(stderr, "FAIL: OOM (Insert2)\n"); return EXIT_FAILURE; } en = create_entry("bird", "goes tweet"); res = hashmap_put(en, hm); if (res) { fprintf(stderr, "FAIL: OOM (Insert3)\n"); return EXIT_FAILURE; } en = create_entry("mouse", "goes sqeak"); res = hashmap_put(en, hm); if (res) { fprintf(stderr, "FAIL: OOM (Insert4)\n"); return EXIT_FAILURE; } if (hm->nr_entries == 4) { printf("Success: 4 test entries inserted\n"); } else { fprintf(stderr, "FAIL: Wrong number of entries! (insert5)\n"); return EXIT_FAILURE; } printf("\nTest Get...\n"); key = "dog"; value = (char *) hashmap_get(key, strlen(key) + 1, hm); if (value) { printf("Success: %s %s\n", key, value); } else { fprintf(stderr, "FAIL: No entry found! (Get1)\n"); return EXIT_FAILURE; } value = (char *) hashmap_get(key, strlen(key), hm); if (value) { fprintf(stderr, "FAIL: Entry found! (Get2)\n"); return EXIT_FAILURE; } else { printf("Success: No entry found for erroneous key length\n"); } printf("\nTest Remove...\n"); res = hashmap_remove(key, strlen(key) + 1, hm); if (res) { printf("Success: Entry removed\n"); } else { fprintf(stderr, "FAIL: Entry not removed! (Remove1)\n"); return EXIT_FAILURE; } value = (char *) hashmap_get(key, strlen(key), hm); if (value) { fprintf(stderr, "FAIL: Entry found! (Remove2)\n"); return EXIT_FAILURE; } else { printf("Success: No entry found after removal\n"); } hashmap_free(hm); return EXIT_SUCCESS; }
static void size_test( void ) { int res; hashmap_t hashmap; size_t size; unsigned int empty; res = hashmap_init( &hashmap ); assert( 0 == res ); /* Confirm initial size is 0. */ size = hashmap_size( &hashmap ); assert( 0 == size ); empty = hashmap_empty( &hashmap ); assert( 0 != empty ); /* Confirm insertion increases by 1. */ res = hashmap_insert( &hashmap, "test", 1 ); assert( 0 == res ); size = hashmap_size( &hashmap ); assert( 1 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm duplicate insert doesn't change size. */ res = hashmap_insert( &hashmap, "test", 100 ); assert( 0 == res ); size = hashmap_size( &hashmap ); assert( 1 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm insertion increases by 1. */ res = hashmap_insert( &hashmap, "test2", 4 ); assert( 0 == res ); size = hashmap_size( &hashmap ); assert( 2 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm removal decreases by 1. */ hashmap_erase( &hashmap, "test" ); size = hashmap_size( &hashmap ); assert( 1 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm removal of key that doesn't exist doesn't change the size. */ hashmap_erase( &hashmap, "doesn't exist" ); size = hashmap_size( &hashmap ); assert( 1 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm removal of key that once existed but doesn't now doesn't change the size. */ hashmap_erase( &hashmap, "test" ); size = hashmap_size( &hashmap ); assert( 1 == size ); empty = hashmap_empty( &hashmap ); assert( 0 == empty ); /* Confirm removal decreases by 1. */ hashmap_erase( &hashmap, "test2" ); size = hashmap_size( &hashmap ); assert( 0 == size ); empty = hashmap_empty( &hashmap ); assert( 0 != empty ); hashmap_term( &hashmap ); }