diff --git a/map/README.md b/map/README.md index 63a77ee..9019ed4 100644 --- a/map/README.md +++ b/map/README.md @@ -3,8 +3,8 @@ ### Overview - Open addressing hashmap with linear probing. -- Requires postfix naming, it's ugly but macros are necessary to avoid - copy/compare function pointers, memcpy calls etc.. +- Requires postfix naming, e.g sc_map_str, sc_map_int. It's ugly but necessary + for better performance. - Comes with predefined key value pairs : @@ -71,6 +71,11 @@ void example_int_to_str() sc_map_put_64s(&map, 200, "new york"); sc_map_put_64s(&map, 300, "atlanta"); + value = sc_map_get_64s(&map, 200); + if (sc_map_found(&map)) { + printf("Found Value:[%s] \n", value); + } + value = sc_map_del_64s(&map, 100); if (sc_map_found(&map)) { printf("Deleted : %s \n", value); diff --git a/map/map_example.c b/map/map_example.c index 362a955..36a22de 100644 --- a/map/map_example.c +++ b/map/map_example.c @@ -32,6 +32,11 @@ void example_int_to_str() sc_map_put_64s(&map, 200, "new york"); sc_map_put_64s(&map, 300, "atlanta"); + value = sc_map_get_64s(&map, 200); + if (sc_map_found(&map)) { + printf("Found Value:[%s] \n", value); + } + value = sc_map_del_64s(&map, 100); if (sc_map_found(&map)) { printf("Deleted : %s \n", value); diff --git a/map/map_test.c b/map/map_test.c index 54c44c4..5bc8b9b 100644 --- a/map/map_test.c +++ b/map/map_test.c @@ -36,6 +36,11 @@ void example_int_to_str() sc_map_put_64s(&map, 200, "new york"); sc_map_put_64s(&map, 300, "atlanta"); + value = sc_map_get_64s(&map, 200); + if (sc_map_found(&map)) { + printf("Found Value:[%s] \n", value); + } + value = sc_map_del_64s(&map, 100); if (sc_map_found(&map)) { printf("Deleted : %s \n", value); diff --git a/map/sc_map.h b/map/sc_map.h index 6daec15..4949347 100644 --- a/map/sc_map.h +++ b/map/sc_map.h @@ -84,7 +84,7 @@ * @param load_factor must be >25 and <95. Pass 0 for default value. \ * @return 'true' on success, \ * 'false' on out of memory or if 'load_factor' value is \ - * invalid. \ + * invalid. \ */ \ bool sc_map_init_##name(struct sc_map_##name *map, uint32_t cap, \ uint32_t load_factor); \ @@ -121,6 +121,7 @@ * @param K key \ * @param V value \ * @return previous value if exists \ + * call sc_map_found() to see if returned value if valid. \ */ \ V sc_map_put_##name(struct sc_map_##name *map, K key, V val); \ \ @@ -149,6 +150,7 @@ /** * @param map map * @return - if put operation overrides a value, returns true + * - if get operation finds the key, returns true * - if del operation deletes a key, returns true */ #define sc_map_found(map) ((map)->found)