void TestHashmaplinked_IterateHandlesCollisions( CuTest * tc ) { hashmap_t *hm, *hm2; hashmap_iterator_t iter; void *key; hm = hashmap_new(__uint_hash, __uint_compare, 4); hm2 = hashmap_new(__uint_hash, __uint_compare, 4); hashmap_put(hm, (void *) 1, (void *) 92); hashmap_put(hm, (void *) 5, (void *) 91); hashmap_put(hm, (void *) 9, (void *) 90); hashmap_put(hm2, (void *) 1, (void *) 92); hashmap_put(hm2, (void *) 5, (void *) 91); hashmap_put(hm2, (void *) 9, (void *) 90); hashmap_iterator(hm, &iter); /* remove every key we iterate on */ while ((key = hashmap_iterator_next(hm, &iter))) { CuAssertTrue(tc, NULL != hashmap_remove(hm2, key)); } /* check if the hashmap is empty */ CuAssertTrue(tc, 0 == hashmap_count(hm2)); hashmap_freeall(hm); }
/* * ASSEMBLER_constructor * * Creates all symbol_table_map, operations_map and registers_map hashmaps used in * conversion of assembly into bitcode. * * params: none * * return: ASSEMBLER_STR_p pointer to object fields struct */ ASSEMBLER_STR_p ASSEMBLER_constructor() { ASSEMBLER_STR_p this = (ASSEMBLER_STR_p) malloc(sizeof(ASSEMBLER_STR_p)); //declare maps map_t sacrificial_bugged_map = hashmap_new(); map_t symbolTable = hashmap_new(); map_t operationsMap = hashmap_new(); map_t registersMap = hashmap_new(); /********** populate maps **********/ //note any_t is type void * //you must caste to specific type of pointer after retrieving value via hashmap_get //operations int i; int num_elements_in_operations_arr = sizeof(operations_arr) / (sizeof(char) * GLOBAL_OP_REG_STRING_SIZE); for (i = 0; i < num_elements_in_operations_arr; i++) { hashmap_put(operationsMap, operations_arr[i], index_to_int_ptr[i]); } //registers int num_elements_in_registers_arr = sizeof(registers_arr) / (sizeof(char *)); for (i = 0; i < num_elements_in_registers_arr; i++) { //printf("%s\n", registers_arr[i]); hashmap_put(registersMap, registers_arr[i], index_to_int_ptr[i]); } this->sacrificial_bugged_map = sacrificial_bugged_map; this->symbol_table_map = symbolTable; this->operations_map = operationsMap; this->registers_map = registersMap; return this; }
Manager *manager_new(void) { Manager *m; int r; m = new0(Manager, 1); if (!m) return NULL; m->machines = hashmap_new(&string_hash_ops); m->machine_units = hashmap_new(&string_hash_ops); m->machine_leaders = hashmap_new(NULL); if (!m->machines || !m->machine_units || !m->machine_leaders) { manager_free(m); return NULL; } r = sd_event_default(&m->event); if (r < 0) { manager_free(m); return NULL; } sd_event_set_watchdog(m->event, true); return m; }
static void test_hashmap_merge(void) { Hashmap *m; Hashmap *n; char *val1, *val2, *val3, *val4, *r; val1 = strdup("my val1"); assert_se(val1); val2 = strdup("my val2"); assert_se(val2); val3 = strdup("my val3"); assert_se(val3); val4 = strdup("my val4"); assert_se(val4); n = hashmap_new(&string_hash_ops); m = hashmap_new(&string_hash_ops); hashmap_put(m, "Key 1", val1); hashmap_put(m, "Key 2", val2); hashmap_put(n, "Key 3", val3); hashmap_put(n, "Key 4", val4); assert_se(hashmap_merge(m, n) == 0); r = hashmap_get(m, "Key 3"); assert_se(r && streq(r, "my val3")); r = hashmap_get(m, "Key 4"); assert_se(r && streq(r, "my val4")); assert_se(n); assert_se(m); hashmap_free(n); hashmap_free_free(m); }
int sysview_seat_new(sysview_seat **out, sysview_context *c, const char *name) { _cleanup_(sysview_seat_freep) sysview_seat *seat = NULL; int r; assert_return(c, -EINVAL); assert_return(name, -EINVAL); seat = new0(sysview_seat, 1); if (!seat) return -ENOMEM; seat->context = c; seat->name = strdup(name); if (!seat->name) return -ENOMEM; seat->session_map = hashmap_new(string_hash_func, string_compare_func); if (!seat->session_map) return -ENOMEM; seat->device_map = hashmap_new(string_hash_func, string_compare_func); if (!seat->device_map) return -ENOMEM; r = hashmap_put(c->seat_map, seat->name, seat); if (r < 0) return r; if (out) *out = seat; seat = NULL; return 0; }
Manager *manager_new(void) { Manager *m; int r; m = new0(Manager, 1); if (!m) return NULL; m->machines = hashmap_new(string_hash_func, string_compare_func); m->machine_units = hashmap_new(string_hash_func, string_compare_func); m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func); if (!m->machines || !m->machine_units || !m->machine_leaders) { manager_free(m); return NULL; } r = sd_event_default(&m->event); if (r < 0) { manager_free(m); return NULL; } return m; }
static int manager_new(Manager **ret) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; assert(ret); m = new0(Manager, 1); if (!m) return -ENOMEM; m->machines = hashmap_new(&string_hash_ops); m->machine_units = hashmap_new(&string_hash_ops); m->machine_leaders = hashmap_new(NULL); if (!m->machines || !m->machine_units || !m->machine_leaders) return -ENOMEM; r = sd_event_default(&m->event); if (r < 0) return r; r = sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); if (r < 0) return r; r = sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL); if (r < 0) return r; (void) sd_event_set_watchdog(m->event, true); *ret = TAKE_PTR(m); return 0; }
int manager_new(Manager **ret) { _cleanup_manager_free_ Manager *m = NULL; int r; m = new0(Manager, 1); if (!m) return -ENOMEM; r = sd_event_default(&m->event); if (r < 0) return r; sd_event_set_watchdog(m->event, true); r = sd_rtnl_open(&m->rtnl, RTMGRP_LINK | RTMGRP_IPV4_IFADDR); if (r < 0) return r; r = sd_bus_default_system(&m->bus); if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */ return r; r = setup_signals(m); if (r < 0) return r; m->udev = udev_new(); if (!m->udev) return -ENOMEM; /* udev does not initialize devices inside containers, * so we rely on them being already initialized before * entering the container */ if (detect_container(NULL) > 0) { m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "kernel"); if (!m->udev_monitor) return -ENOMEM; } else { m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); if (!m->udev_monitor) return -ENOMEM; } m->links = hashmap_new(uint64_hash_func, uint64_compare_func); if (!m->links) return -ENOMEM; m->netdevs = hashmap_new(string_hash_func, string_compare_func); if (!m->netdevs) return -ENOMEM; LIST_HEAD_INIT(m->networks); *ret = m; m = NULL; return 0; }
int manager_new(Manager **ret) { _cleanup_manager_free_ Manager *m = NULL; int r; m = new0(Manager, 1); if (!m) return -ENOMEM; r = sd_event_default(&m->event); if (r < 0) return r; sd_event_set_watchdog(m->event, true); r = sd_rtnl_open(RTMGRP_LINK | RTMGRP_IPV4_IFADDR, &m->rtnl); if (r < 0) return r; m->udev = udev_new(); if (!m->udev) return -ENOMEM; m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); if (!m->udev_monitor) return -ENOMEM; m->links = hashmap_new(uint64_hash_func, uint64_compare_func); if (!m->links) return -ENOMEM; m->bridges = hashmap_new(string_hash_func, string_compare_func); if (!m->bridges) return -ENOMEM; LIST_HEAD_INIT(m->networks); m->network_dirs = strv_new("/etc/systemd/network/", "/run/systemd/network/", "/usr/lib/systemd/network", #ifdef HAVE_SPLIT_USER "/lib/systemd/network", #endif NULL); if (!m->network_dirs) return -ENOMEM; if (!path_strv_canonicalize_uniq(m->network_dirs)) return -ENOMEM; *ret = m; m = NULL; return 0; }
void *bt_rarestfirst_selector_new( const int npieces ) { rarestfirst_t *rf; rf = calloc(1, sizeof(rarestfirst_t)); rf->npieces = npieces; rf->peers = hashmap_new(__peer_hash, __peer_compare, 11); rf->pieces = hashmap_new(__peer_hash, __peer_compare, 11); rf->pieces_polled = hashmap_new(__peer_hash, __peer_compare, 11); return rf; }
int8_t init_resource_manager(){ foreground_changed = 0; dev_null = device_open(&ret_dev_null_uid,AP7000_NULL_DEVICE,0); device_to_real_uid_map = hashmap_new(); virt_uid_to_virt_dev_map = hashmap_new(); pid_to_virt_dev_map = hashmap_new(); pid_to_gdi_uid = hashmap_new(); return 0; }
void TestHashmaplinked_IterateAndRemoveDoesntBreakIteration( CuTest * tc ) { hashmap_t *hm; hashmap_t *hm2; hashmap_iterator_t iter; void *key; hm = hashmap_new(__uint_hash, __uint_compare, 11); hm2 = hashmap_new(__uint_hash, __uint_compare, 11); hashmap_put(hm, (void *) 50, (void *) 92); hashmap_put(hm, (void *) 49, (void *) 91); hashmap_put(hm, (void *) 48, (void *) 90); hashmap_put(hm, (void *) 47, (void *) 89); hashmap_put(hm, (void *) 46, (void *) 88); hashmap_put(hm, (void *) 45, (void *) 87); /* the following 3 collide: */ hashmap_put(hm, (void *) 1, (void *) 92); hashmap_put(hm, (void *) 5, (void *) 91); hashmap_put(hm, (void *) 9, (void *) 90); hashmap_put(hm2, (void *) 50, (void *) 92); hashmap_put(hm2, (void *) 49, (void *) 91); hashmap_put(hm2, (void *) 48, (void *) 90); hashmap_put(hm2, (void *) 47, (void *) 89); hashmap_put(hm2, (void *) 46, (void *) 88); hashmap_put(hm2, (void *) 45, (void *) 87); /* the following 3 collide: */ hashmap_put(hm2, (void *) 1, (void *) 92); hashmap_put(hm2, (void *) 5, (void *) 91); hashmap_put(hm2, (void *) 9, (void *) 90); hashmap_iterator(hm, &iter); /* remove every key we iterate on */ while ((key = hashmap_iterator_next(hm, &iter))) { CuAssertTrue(tc, NULL != hashmap_remove(hm2, key)); hashmap_remove(hm,key); } /* check if the hashmap is empty */ CuAssertTrue(tc, 0 == hashmap_count(hm2)); hashmap_freeall(hm); hashmap_freeall(hm2); }
int dowse_start(logerr_t *a_logerr) { /* * The "start" function is called once, when the program * starts. It is used to initialize the plugin. If the * plugin wants to write debugging and or error messages, * it should save the a_logerr pointer passed from the * parent code. */ logerr = a_logerr; if (filepfx) { logerr("Logging to file: %s\n", filepfx); fileout = fopen(filepfx, "a"); if (0 == fileout) { logerr("%s: %s\n", filepfx, strerror(errno)); exit(1); } } // get own hostname gethostname(hostname,(size_t)MAX_DOMAIN); visited = hashmap_new(); // load the domain-list path if there if(listpath) load_domainlist(listpath); return 0; }
static void test_hashmap_copy(void) { Hashmap *m, *copy; char *val1, *val2, *val3, *val4, *r; val1 = strdup("val1"); assert_se(val1); val2 = strdup("val2"); assert_se(val2); val3 = strdup("val3"); assert_se(val3); val4 = strdup("val4"); assert_se(val4); m = hashmap_new(&string_hash_ops); hashmap_put(m, "key 1", val1); hashmap_put(m, "key 2", val2); hashmap_put(m, "key 3", val3); hashmap_put(m, "key 4", val4); copy = hashmap_copy(m); r = hashmap_get(copy, "key 1"); assert_se(streq(r, "val1")); r = hashmap_get(copy, "key 2"); assert_se(streq(r, "val2")); r = hashmap_get(copy, "key 3"); assert_se(streq(r, "val3")); r = hashmap_get(copy, "key 4"); assert_se(streq(r, "val4")); hashmap_free_free(copy); hashmap_free(m); }
void load_domainlist(const char *path) { char line[MAX_LINE]; char trimmed[MAX_LINE]; domainlist = hashmap_new(); // parse all files in directory logerr("Parsing domain-list: %s\n", path); listdir = opendir(path); if(!listdir) { perror(path); exit(1); } // read file by file while (dp = readdir (listdir)) { char fullpath[MAX_LINE]; snprintf(fullpath,MAX_LINE,"%s/%s",path,dp->d_name); // open and read line by line fp = fopen(fullpath,"r"); if(!fp) { perror(fullpath); continue; } while(fgets(line,MAX_LINE, fp)) { // save lines in hashmap with filename as value if(line[0]=='#') continue; // skip comments trim(trimmed, strlen(line), line); if(trimmed[0]=='\0') continue; // skip blank lines // logerr("(%u) %s\t%s", trimmed[0], trimmed, dp->d_name); hashmap_put(domainlist, strdup(trimmed), strdup(dp->d_name)); } fclose(fp); } closedir(listdir); }
int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { _cleanup_(image_hashmap_freep) Hashmap *images = NULL; _cleanup_strv_free_ char **l = NULL; Image *image; Iterator i; int r; assert(bus); assert(path); assert(nodes); images = hashmap_new(&string_hash_ops); if (!images) return -ENOMEM; r = image_discover(images); if (r < 0) return r; HASHMAP_FOREACH(image, images, i) { char *p; p = image_bus_path(image->name); if (!p) return -ENOMEM; r = strv_consume(&l, p); if (r < 0) return r; }
int main(int argc, char* argv[]) { Hashmap *h; UnitFileList *p; Iterator i; int r; const char *const files[] = { "avahi-daemon.service", NULL }; const char *const files2[] = { "/home/lennart/test.service", NULL }; UnitFileChange *changes = NULL; unsigned n_changes = 0; UnitFileState state = 0; h = hashmap_new(&string_hash_ops); r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h); assert_se(r == 0); HASHMAP_FOREACH(p, h, i) { UnitFileState s = _UNIT_FILE_STATE_INVALID; r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(p->path), &s); assert_se((r < 0 && p->state == UNIT_FILE_BAD) || (p->state == s)); fprintf(stderr, "%s (%s)\n", p->path, unit_file_state_to_string(p->state)); }
static void test_hashmap_update(void) { Hashmap *m; char *val1, *val2, *r; log_info("%s", __func__); m = hashmap_new(&string_hash_ops); val1 = strdup("old_value"); assert_se(val1); val2 = strdup("new_value"); assert_se(val2); hashmap_put(m, "key 1", val1); r = hashmap_get(m, "key 1"); assert_se(streq(r, "old_value")); assert_se(hashmap_update(m, "key 2", val2) == -ENOENT); r = hashmap_get(m, "key 1"); assert_se(streq(r, "old_value")); assert_se(hashmap_update(m, "key 1", val2) == 0); r = hashmap_get(m, "key 1"); assert_se(streq(r, "new_value")); free(val1); free(val2); hashmap_free(m); }
static int list_bus_names(sd_bus *bus, char **argv) { _cleanup_strv_free_ char **acquired = NULL, **activatable = NULL; _cleanup_free_ char **merged = NULL; _cleanup_hashmap_free_ Hashmap *names = NULL; char **i; int r; size_t max_i = 0; unsigned n = 0; void *v; char *k; Iterator iterator; assert(bus); r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL); if (r < 0) { log_error("Failed to list names: %s", strerror(-r)); return r; } pager_open_if_enabled(); names = hashmap_new(&string_hash_ops); if (!names) return log_oom(); STRV_FOREACH(i, acquired) { max_i = MAX(max_i, strlen(*i)); r = hashmap_put(names, *i, INT_TO_PTR(1)); if (r < 0) { log_error("Failed to add to hashmap: %s", strerror(-r)); return r; } }
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) { Hashmap *fh; char **files, **p; int r; assert(strv); assert(suffix); /* This alters the dirs string array */ if (!path_strv_canonicalize_absolute_uniq(dirs, root)) return -ENOMEM; fh = hashmap_new(string_hash_func, string_compare_func); if (!fh) return -ENOMEM; STRV_FOREACH(p, dirs) { r = files_add(fh, *p, suffix); if (r == -ENOMEM) { hashmap_free_free(fh); return r; } else if (r < 0) log_debug("Failed to search for files in %s: %s", *p, strerror(-r)); }
int main(int argc, char **argv) { int i, key, inmap, insert, data; void *datap; struct hashmap_t *map = hashmap_new(5); srandom(0); for (i=0; i<10000; i++) { key = rand()%DATASET_SIZE; insert = rand()%2; inmap = test_status[key]; data = test_data[key]; if (inmap && insert) { /* update */ data++; hashmap_upsert(map, &key, sizeof(int), INT2PTR(data), &datap); assert((intptr_t)datap == (intptr_t)test_data[key]); test_data[key] = data; } else if ( !inmap && insert) { /* insert */ hashmap_upsert(map, &key, sizeof(int), INT2PTR(data), &datap); assert( (intptr_t)datap == 0); test_status[key] = 1; } else if (inmap && !insert) { /* delete */ hashmap_delete(map, &key, sizeof(int), &datap); assert((intptr_t)datap == (intptr_t)test_data[key]); test_status[key] = 0; } else if (!inmap && !insert) { /* nothing to be deleted */ hashmap_delete(map, &key, sizeof(int), &datap); assert((intptr_t)datap == 0); } } return 0; }
static void test_hashmap_foreach_key(void) { Hashmap *m; Iterator i; bool key_found[] = { false, false, false, false }; const char *s; const char *key; static const char key_table[] = "key 1\0" "key 2\0" "key 3\0" "key 4\0"; log_info("%s", __func__); m = hashmap_new(&string_hash_ops); NULSTR_FOREACH(key, key_table) hashmap_put(m, key, (void*) (const char*) "my dummy val"); HASHMAP_FOREACH_KEY(s, key, m, i) { assert(s); if (!key_found[0] && streq(key, "key 1")) key_found[0] = true; else if (!key_found[1] && streq(key, "key 2")) key_found[1] = true; else if (!key_found[2] && streq(key, "key 3")) key_found[2] = true; else if (!key_found[3] && streq(key, "fail")) key_found[3] = true; }
int catalog_update(const char* database, const char* root, const char* const* dirs) { _cleanup_strv_free_ char **files = NULL; char **f; struct strbuf *sb = NULL; _cleanup_hashmap_free_free_ Hashmap *h = NULL; _cleanup_free_ CatalogItem *items = NULL; CatalogItem *i; Iterator j; unsigned n; long r; h = hashmap_new(catalog_hash_func, catalog_compare_func); sb = strbuf_new(); if (!h || !sb) { r = log_oom(); goto finish; } r = conf_files_list_strv(&files, ".catalog", root, dirs); if (r < 0) { log_error("Failed to get catalog files: %s", strerror(-r)); goto finish; } STRV_FOREACH(f, files) { log_debug("Reading file '%s'", *f); r = catalog_import_file(h, sb, *f); if (r < 0) { log_error("Failed to import file '%s': %s.", *f, strerror(-r)); goto finish; } }
static void test_hashmap_remove_and_put(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; int valid; char *r; log_info("%s", __func__); m = hashmap_new(&string_hash_ops); assert_se(m); valid = hashmap_remove_and_put(m, "invalid key", "new key", NULL); assert_se(valid == -ENOENT); valid = hashmap_put(m, "key 1", (void*) (const char *) "val 1"); assert_se(valid == 1); valid = hashmap_remove_and_put(NULL, "key 1", "key 2", (void*) (const char *) "val 2"); assert_se(valid == -ENOENT); valid = hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2"); assert_se(valid == 0); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3"); assert_se(valid == 1); valid = hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2"); assert_se(valid == -EEXIST); }
BuxtonBackend *backend_for_layer(BuxtonConfig *config, BuxtonLayer *layer) { BuxtonBackend *backend; int ret; assert(layer); if (!config->databases) { config->databases = hashmap_new(string_hash_func, string_compare_func); if (!config->databases) { abort(); } } if ((backend = (BuxtonBackend*)hashmap_get(config->databases, layer->name.value)) == NULL) { /* attempt load of backend */ init_backend(config, layer, &backend); ret = hashmap_put(config->databases, layer->name.value, backend); if (ret != 1) { abort(); } } return (BuxtonBackend*)hashmap_get(config->databases, layer->name.value); }
static void test_hashmap_remove2(void) { _cleanup_hashmap_free_free_free_ Hashmap *m = NULL; char key1[] = "key 1"; char key2[] = "key 2"; char val1[] = "val 1"; char val2[] = "val 2"; void *r, *r2; log_info("%s", __func__); r = hashmap_remove2(NULL, "key 1", &r2); assert_se(r == NULL); m = hashmap_new(&string_hash_ops); assert_se(m); r = hashmap_remove2(m, "no such key", &r2); assert_se(r == NULL); hashmap_put(m, strdup(key1), strdup(val1)); hashmap_put(m, strdup(key2), strdup(val2)); r = hashmap_remove2(m, key1, &r2); assert_se(streq(r, val1)); assert_se(streq(r2, key1)); free(r); free(r2); r = hashmap_get(m, key2); assert_se(streq(r, val2)); assert_se(!hashmap_get(m, key1)); }
static void test_hashmap_remove_value(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; char *r; r = hashmap_remove_value(NULL, "key 1", (void*) "val 1"); assert_se(r == NULL); m = hashmap_new(&string_hash_ops); assert_se(m); r = hashmap_remove_value(m, "key 1", (void*) "val 1"); assert_se(r == NULL); hashmap_put(m, "key 1", (void*) "val 1"); hashmap_put(m, "key 2", (void*) "val 2"); r = hashmap_remove_value(m, "key 1", (void*) "val 1"); assert_se(streq(r, "val 1")); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); r = hashmap_remove_value(m, "key 2", (void*) "val 1"); assert_se(r == NULL); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); }
static int test_unit_file_get_set(void) { int r; Hashmap *h; Iterator i; UnitFileList *p; h = hashmap_new(&string_hash_ops); assert_se(h); r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h, NULL, NULL); if (IN_SET(r, -EPERM, -EACCES)) { log_notice_errno(r, "Skipping test: unit_file_get_list: %m"); return EXIT_TEST_SKIP; } log_full_errno(r == 0 ? LOG_INFO : LOG_ERR, r, "unit_file_get_list: %m"); if (r < 0) return EXIT_FAILURE; HASHMAP_FOREACH(p, h, i) printf("%s = %s\n", p->path, unit_file_state_to_string(p->state)); unit_file_list_free(h); return 0; }
static void test_hashmap_remove_value(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; char *r; char val1[] = "val 1"; char val2[] = "val 2"; log_info("%s", __func__); r = hashmap_remove_value(NULL, "key 1", val1); assert_se(r == NULL); m = hashmap_new(&string_hash_ops); assert_se(m); r = hashmap_remove_value(m, "key 1", val1); assert_se(r == NULL); hashmap_put(m, "key 1", val1); hashmap_put(m, "key 2", val2); r = hashmap_remove_value(m, "key 1", val1); assert_se(streq(r, "val 1")); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); r = hashmap_remove_value(m, "key 2", val1); assert_se(r == NULL); r = hashmap_get(m, "key 2"); assert_se(streq(r, "val 2")); assert_se(!hashmap_get(m, "key 1")); }
/* Load layer configurations from disk */ void buxton_init_layers(BuxtonConfig *config) { Hashmap *layers = NULL; int nlayers = 0; ConfigLayer *config_layers = NULL; int r; nlayers = buxton_key_get_layers(&config_layers); layers = hashmap_new(string_hash_func, string_compare_func); if (!layers) { abort(); } for (int n = 0; n < nlayers; n++) { BuxtonLayer *layer; layer = buxton_layer_new(&(config_layers[n])); if (!layer) { abort(); } r = hashmap_put(layers, layer->name.value, layer); if (r != 1) { abort(); } } config->layers = layers; free(config_layers); }