int hi_get_int16_t(hi_handle_t *hi_hndl, const int16_t key, void **data) { return hi_get(hi_hndl, (void *)&key, sizeof(int16_t), data); }
static void check_get_remove(enum coll_eng engine, enum hash_alg hash_alg) { int ret; hi_handle_t *hi_hndl; struct hi_init_set hi_set; void *data_ret; hi_set_zero(&hi_set); ret = hi_set_bucket_size(&hi_set, 100); assert(ret == 0); ret = hi_set_hash_alg(&hi_set, hash_alg); assert(ret == 0); ret = hi_set_coll_eng(&hi_set, engine); assert(ret == 0); ret = hi_set_key_cmp_func(&hi_set, hi_cmp_str); assert(ret == 0); /* we need aditional arguments for ARRAY based engines */ switch (engine) { case COLL_ENG_ARRAY: case COLL_ENG_ARRAY_HASH: case COLL_ENG_ARRAY_DYN: case COLL_ENG_ARRAY_DYN_HASH: ret = hi_set_coll_eng_array_size(&hi_set, 20); assert(ret == 0); break; default: break; }; ret = hi_create(&hi_hndl, &hi_set); if (ret != 0) print_error(ret); assert(ret == 0); assert(hi_hndl->no_objects == 0); ret = hi_insert(hi_hndl, (void *) "key", sizeof("key"), "DATA"); assert(ret == 0); assert(hi_hndl->no_objects == 1); ret = hi_insert(hi_hndl, (void *) "key2", sizeof("key2"), "DATAX"); assert(ret == 0); assert(hi_hndl->no_objects == 2); ret = hi_insert(hi_hndl, (void *) "key3", sizeof("key3"), "DATAX"); assert(ret == 0); assert(hi_hndl->no_objects == 3); /* key already in data structure -> must return 0 (SUCCESS) */ ret = hi_get(hi_hndl, (void *) "key", sizeof("key"), &data_ret); if (ret != 0) print_error(ret); check_data(data_ret, "DATA"); assert(hi_hndl->no_objects == 3); ret = hi_get(hi_hndl, (void *) "key3", sizeof("key3"), &data_ret); if (ret != 0) print_error(ret); check_data(data_ret, "DATAX"); assert(hi_hndl->no_objects == 3); data_ret = NULL; ret = hi_remove(hi_hndl, (void *) "key", sizeof("key"), &data_ret); assert(ret == 0); assert(hi_hndl->no_objects == 2); check_data(data_ret, "DATA"); data_ret = NULL; ret = hi_remove(hi_hndl, (void *) "key2", sizeof("key2"), &data_ret); assert(ret == 0); assert(hi_hndl->no_objects == 1); ret = hi_remove(hi_hndl, (void *) "key3", sizeof("key3"), &data_ret); assert(ret == 0); assert(hi_hndl->no_objects == 0); check_data(data_ret, "DATAX"); ret = hi_fini(hi_hndl); assert(ret == 0); fputs("passed\n", stdout); }
static void check_insert(enum coll_eng engine, enum hash_alg hash_alg) { int ret; hi_handle_t *hi_hndl; struct hi_init_set hi_set; void *data_ptr = (void *) 0xdeadbeef; hi_set_zero(&hi_set); ret = hi_set_bucket_size(&hi_set, 100); assert(ret == 0); ret = hi_set_hash_alg(&hi_set, hash_alg); assert(ret == 0); ret = hi_set_coll_eng(&hi_set, engine); assert(ret == 0); ret = hi_set_key_cmp_func(&hi_set, hi_cmp_str); assert(ret == 0); /* we need aditional arguments for ARRAY based engines */ switch (engine) { case COLL_ENG_ARRAY: case COLL_ENG_ARRAY_HASH: case COLL_ENG_ARRAY_DYN: case COLL_ENG_ARRAY_DYN_HASH: ret = hi_set_coll_eng_array_size(&hi_set, 20); assert(ret == 0); break; default: break; }; ret = hi_create(&hi_hndl, &hi_set); if (ret != 0) print_error(ret); assert(ret == 0); ret = hi_insert(hi_hndl, (void *) "key", sizeof("key"), "XX"); assert(ret == 0); /* same key -> must fail */ ret = hi_insert(hi_hndl, (void *) "key", sizeof("key"), "XX"); assert(ret == HI_ERR_DUPKEY); /* key already in data structure -> must return 0 (SUCCESS) */ ret = hi_get(hi_hndl, (void *) "key", sizeof("key"), &data_ptr); assert(ret == 0); //assert(data_ptr == NULL); ret = hi_remove(hi_hndl, (void *) "key", sizeof("key"), &data_ptr); assert(ret == 0); ret = hi_get(hi_hndl, (void *) "key", sizeof("key"), &data_ptr); assert(ret == HI_ERR_NOKEY); ret = hi_fini(hi_hndl); assert(ret == 0); fputs("passed\n", stdout); }
int hi_get_str(hi_handle_t *hi_hndl, const char *key, void **data) { return hi_get(hi_hndl, (void *)key, strlen(key) + 1, data); }