Fri, 09 Aug 2013 15:29:26 +0200
started documentation of map.h + renamed allocator version of ucx_map_new
ucx/map.c | file | annotate | diff | comparison | revisions | |
ucx/map.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/map.c Fri Aug 09 14:36:54 2013 +0200 1.2 +++ b/ucx/map.c Fri Aug 09 15:29:26 2013 +0200 1.3 @@ -32,10 +32,10 @@ 1.4 #include "map.h" 1.5 1.6 UcxMap *ucx_map_new(size_t size) { 1.7 - return ucx_map_new_allocator(size, NULL); 1.8 + return ucx_map_new_a(size, NULL); 1.9 } 1.10 1.11 -UcxMap *ucx_map_new_allocator(size_t size, UcxAllocator *allocator) { 1.12 +UcxMap *ucx_map_new_a(size_t size, UcxAllocator *allocator) { 1.13 if(size == 0) { 1.14 size = 16; 1.15 }
2.1 --- a/ucx/map.h Fri Aug 09 14:36:54 2013 +0200 2.2 +++ b/ucx/map.h Fri Aug 09 15:29:26 2013 +0200 2.3 @@ -26,6 +26,18 @@ 2.4 * POSSIBILITY OF SUCH DAMAGE. 2.5 */ 2.6 2.7 +/** 2.8 + * @file map.h 2.9 + * 2.10 + * Hash map implementation. 2.11 + * 2.12 + * This implementation uses murmur hash 2 and separate chaining with linked 2.13 + * lists. 2.14 + * 2.15 + * @author Mike Becker 2.16 + * @author Olaf Wintermann 2.17 + */ 2.18 + 2.19 #ifndef UCX_MAP_H 2.20 #define UCX_MAP_H 2.21 2.22 @@ -46,14 +58,6 @@ 2.23 typedef struct UcxMapElement UcxMapElement; 2.24 typedef struct UcxMapIterator UcxMapIterator; 2.25 2.26 -/* 2.27 - * param 1: element 2.28 - * param 2: additional data 2.29 - * param 3: size of encoded data will be stored here 2.30 - * returns encoded / decoded string or NULL on failure 2.31 - */ 2.32 -typedef void*(*ucx_map_coder)(void*,void*,size_t*); 2.33 - 2.34 struct UcxMap { 2.35 UcxAllocator *allocator; 2.36 UcxMapElement **map; 2.37 @@ -79,10 +83,31 @@ 2.38 size_t index; 2.39 }; 2.40 2.41 +/** 2.42 + * Creates a new hash map with the specified size. 2.43 + * @param size the size of the hash map 2.44 + * @return a pointer to the new hash map 2.45 + */ 2.46 +UcxMap *ucx_map_new(size_t size); 2.47 2.48 -UcxMap *ucx_map_new(size_t size); 2.49 -UcxMap *ucx_map_new_allocator(size_t size, UcxAllocator *allocator); 2.50 +/** 2.51 + * Creates a new hash map with the specified size using an UcxAllocator. 2.52 + * @param size the size of the hash map 2.53 + * @param allocator the allocator to use 2.54 + * @return a pointer to the new hash map 2.55 + */ 2.56 +UcxMap *ucx_map_new_a(size_t size, UcxAllocator *allocator); 2.57 + 2.58 +/** 2.59 + * Frees a hash map. 2.60 + * 2.61 + * <b>Note:</b> the contents are <b>not</b> freed, use an UcxMempool for that 2.62 + * purpose. 2.63 + * 2.64 + * @param map the map to be freed 2.65 + */ 2.66 void ucx_map_free(UcxMap *map); 2.67 + 2.68 /* you cannot clone maps with more than 390 mio entries */ 2.69 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, 2.70 copy_func fnc, void *data); 2.71 @@ -93,26 +118,81 @@ 2.72 void* ucx_map_get(UcxMap *map, UcxKey key); 2.73 void* ucx_map_remove(UcxMap *map, UcxKey key); 2.74 2.75 -#define ucx_map_sstr_put(m, s, d) \ 2.76 - ucx_map_put(m, ucx_key(s.ptr, s.length), (void*)d) 2.77 -#define ucx_map_cstr_put(m, s, d) \ 2.78 - ucx_map_put(m, ucx_key((void*)s, strlen(s)), (void*)d) 2.79 -#define ucx_map_int_put(m, i, d) \ 2.80 - ucx_map_put(m, ucx_key((void*)&i, sizeof(i)), (void*)d) 2.81 +/** 2.82 + * Shorthand for putting data with a sstr_t key into the map. 2.83 + * @param map the map 2.84 + * @param key the key 2.85 + * @param value the value 2.86 + * @see ucx_map_put() 2.87 + */ 2.88 +#define ucx_map_sstr_put(map, key, value) \ 2.89 + ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value) 2.90 +/** 2.91 + * Shorthand for putting data with a C string key into the map. 2.92 + * @param map the map 2.93 + * @param key the key 2.94 + * @param value the value 2.95 + * @see ucx_map_put() 2.96 + */ 2.97 +#define ucx_map_cstr_put(map, key, value) \ 2.98 + ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value) 2.99 +/** 2.100 + * Shorthand for putting data with an integer key into the map. 2.101 + * @param map the map 2.102 + * @param key the key 2.103 + * @param value the value 2.104 + * @see ucx_map_put() 2.105 + */ 2.106 +#define ucx_map_int_put(map, key, value) \ 2.107 + ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value) 2.108 2.109 -#define ucx_map_sstr_get(m, s) \ 2.110 - ucx_map_get(m, ucx_key(s.ptr, s.length)) 2.111 -#define ucx_map_cstr_get(m, s) \ 2.112 - ucx_map_get(m, ucx_key((void*)s, strlen(s))) 2.113 -#define ucx_map_int_get(m, i) \ 2.114 - ucx_map_get(m, ucx_key((void*)&i, sizeof(int))) 2.115 2.116 -#define ucx_map_sstr_remove(m, s) \ 2.117 - ucx_map_remove(m, ucx_key(s.ptr, s.length)) 2.118 -#define ucx_map_cstr_remove(m, s) \ 2.119 - ucx_map_remove(m, ucx_key((void*)s, strlen(s))) 2.120 -#define ucx_map_int_remove(m, i) \ 2.121 - ucx_map_remove(m, ucx_key((void*)&i, sizeof(i))) 2.122 +/** 2.123 + * Shorthand for getting data from the map with a sstr_t key. 2.124 + * @param map the map 2.125 + * @param key the key 2.126 + * @see ucx_map_get() 2.127 + */ 2.128 +#define ucx_map_sstr_get(map, key) \ 2.129 + ucx_map_get(map, ucx_key(key.ptr, key.length)) 2.130 +/** 2.131 + * Shorthand for getting data from the map with a C string key. 2.132 + * @see ucx_map_get() 2.133 + */ 2.134 +#define ucx_map_cstr_get(map, key) \ 2.135 + ucx_map_get(map, ucx_key((void*)key, strlen(key))) 2.136 +/** 2.137 + * Shorthand for getting data from the map with an integer key. 2.138 + * @param map the map 2.139 + * @param key the key 2.140 + * @see ucx_map_get() 2.141 + */ 2.142 +#define ucx_map_int_get(map, key) \ 2.143 + ucx_map_get(map, ucx_key((void*)&key, sizeof(int))) 2.144 +/** 2.145 + * Shorthand for removing data from the map with a sstr_t key. 2.146 + * @param map the map 2.147 + * @param key the key 2.148 + * @see ucx_map_remove() 2.149 + */ 2.150 +#define ucx_map_sstr_remove(map, key) \ 2.151 + ucx_map_remove(map, ucx_key(key.ptr, key.length)) 2.152 +/** 2.153 + * Shorthand for removing data from the map with a C string key. 2.154 + * @param map the map 2.155 + * @param key the key 2.156 + * @see ucx_map_remove() 2.157 + */ 2.158 +#define ucx_map_cstr_remove(map, key) \ 2.159 + ucx_map_remove(map, ucx_key((void*)key, strlen(key))) 2.160 +/** 2.161 + * Shorthand for removing data from the map with an integer key. 2.162 + * @param map the map 2.163 + * @param key the key 2.164 + * @see ucx_map_remove() 2.165 + */ 2.166 +#define ucx_map_int_remove(map, key) \ 2.167 + ucx_map_remove(map, ucx_key((void*)&key, sizeof(key))) 2.168 2.169 UcxKey ucx_key(void *data, size_t len); 2.170