1.1 --- a/src/ucx/map.h Wed May 30 11:13:52 2018 +0200 1.2 +++ b/src/ucx/map.h Thu Jun 21 16:00:37 2018 +0200 1.3 @@ -89,26 +89,36 @@ 1.4 size_t count; 1.5 }; 1.6 1.7 -/** Structure for a key of a UcxMap. */ 1.8 +/** Structure to publicly denote a key of a UcxMap. */ 1.9 struct UcxKey { 1.10 /** The key data. */ 1.11 - void *data; 1.12 + const void *data; 1.13 /** The length of the key data. */ 1.14 - size_t len; 1.15 + size_t len; 1.16 + /** A cache for the hash value of the key data. */ 1.17 + int hash; 1.18 +}; 1.19 + 1.20 +/** Internal structure for a key of a UcxMap. */ 1.21 +struct UcxMapKey { 1.22 + /** The key data. */ 1.23 + void *data; 1.24 + /** The length of the key data. */ 1.25 + size_t len; 1.26 /** The hash value of the key data. */ 1.27 - int hash; 1.28 + int hash; 1.29 }; 1.30 1.31 /** Structure for an element of a UcxMap. */ 1.32 struct UcxMapElement { 1.33 /** The value data. */ 1.34 - void *data; 1.35 + void *data; 1.36 1.37 /** A pointer to the next element in the current list. */ 1.38 - UcxMapElement *next; 1.39 + UcxMapElement *next; 1.40 1.41 /** The corresponding key. */ 1.42 - UcxKey key; 1.43 + struct UcxMapKey key; 1.44 }; 1.45 1.46 /** Structure for an iterator over a UcxMap. */ 1.47 @@ -285,7 +295,7 @@ 1.48 * @see ucx_map_put() 1.49 */ 1.50 #define ucx_map_cstr_put(map, key, value) \ 1.51 - ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value) 1.52 + ucx_map_put(map, ucx_key(key, strlen(key)), (void*)value) 1.53 1.54 /** 1.55 * Shorthand for putting data with an integer key into the map. 1.56 @@ -296,7 +306,7 @@ 1.57 * @see ucx_map_put() 1.58 */ 1.59 #define ucx_map_int_put(map, key, value) \ 1.60 - ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value) 1.61 + ucx_map_put(map, ucx_key(&key, sizeof(key)), (void*)value) 1.62 1.63 /** 1.64 * Shorthand for getting data from the map with a sstr_t key. 1.65 @@ -316,7 +326,7 @@ 1.66 * @see ucx_map_get() 1.67 */ 1.68 #define ucx_map_cstr_get(map, key) \ 1.69 - ucx_map_get(map, ucx_key((void*)key, strlen(key))) 1.70 + ucx_map_get(map, ucx_key(key, strlen(key))) 1.71 1.72 /** 1.73 * Shorthand for getting data from the map with an integer key. 1.74 @@ -326,7 +336,7 @@ 1.75 * @see ucx_map_get() 1.76 */ 1.77 #define ucx_map_int_get(map, key) \ 1.78 - ucx_map_get(map, ucx_key((void*)&key, sizeof(int))) 1.79 + ucx_map_get(map, ucx_key(&key, sizeof(int))) 1.80 1.81 /** 1.82 * Shorthand for removing data from the map with a sstr_t key. 1.83 @@ -346,7 +356,7 @@ 1.84 * @see ucx_map_remove() 1.85 */ 1.86 #define ucx_map_cstr_remove(map, key) \ 1.87 - ucx_map_remove(map, ucx_key((void*)key, strlen(key))) 1.88 + ucx_map_remove(map, ucx_key(key, strlen(key))) 1.89 1.90 /** 1.91 * Shorthand for removing data from the map with an integer key. 1.92 @@ -356,7 +366,7 @@ 1.93 * @see ucx_map_remove() 1.94 */ 1.95 #define ucx_map_int_remove(map, key) \ 1.96 - ucx_map_remove(map, ucx_key((void*)&key, sizeof(key))) 1.97 + ucx_map_remove(map, ucx_key(&key, sizeof(key))) 1.98 1.99 /** 1.100 * Creates a UcxKey based on the given data. 1.101 @@ -368,7 +378,7 @@ 1.102 * @return a UcxKey with implicitly computed hash 1.103 * @see ucx_hash() 1.104 */ 1.105 -UcxKey ucx_key(void *data, size_t len); 1.106 +UcxKey ucx_key(const void *data, size_t len); 1.107 1.108 /** 1.109 * Computes a murmur hash-2.