mirror of
https://github.com/tezc/sc.git
synced 2025-01-14 06:43:04 +08:00
map doc
This commit is contained in:
parent
145f8fbfc0
commit
9c9ab9d9c9
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user