static map_node_t *map_newnode(const char *key, void *value, int vsize) { map_node_t *node; int ksize = strlen(key) + 1; int voffset = ksize + ((sizeof(void*) - ksize) % sizeof(void*)); node = malloc(sizeof(*node) + voffset + vsize); if (!node) return NULL; memcpy(node + 1, key, ksize); node->hash = map_hash(key); node->value = ((char*) (node + 1)) + voffset; memcpy(node->value, value, vsize); return node; }
static void test_map() { table = create_hash( compare_string, hash_string ); char key[] = "key"; insert_hash_entry( table, key, alpha ); insert_hash_entry( table, key, bravo ); insert_hash_entry( table, key, charlie ); map_hash( table, key, append_back, NULL ); assert_string_equal( abc0[ 0 ], "charlie" ); assert_string_equal( abc0[ 1 ], "bravo" ); assert_string_equal( abc0[ 2 ], "alpha" ); delete_hash( table ); }