src/hash_map.c

changeset 890
54565fd74e74
parent 856
6bbbf219251d
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
82 CxMap *map, 82 CxMap *map,
83 CxHashKey key, 83 CxHashKey key,
84 void *value 84 void *value
85 ) { 85 ) {
86 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; 86 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map;
87 CxAllocator const *allocator = map->collection.allocator; 87 const CxAllocator *allocator = map->collection.allocator;
88 88
89 unsigned hash = key.hash; 89 unsigned hash = key.hash;
90 if (hash == 0) { 90 if (hash == 0) {
91 cx_hash_murmur(&key); 91 cx_hash_murmur(&key);
92 hash = key.hash; 92 hash = key.hash;
221 221
222 return NULL; 222 return NULL;
223 } 223 }
224 224
225 static void *cx_hash_map_get( 225 static void *cx_hash_map_get(
226 CxMap const *map, 226 const CxMap *map,
227 CxHashKey key 227 CxHashKey key
228 ) { 228 ) {
229 // we can safely cast, because we know the map stays untouched 229 // we can safely cast, because we know the map stays untouched
230 return cx_hash_map_get_remove((CxMap *) map, key, false, false); 230 return cx_hash_map_get_remove((CxMap *) map, key, false, false);
231 } 231 }
236 bool destroy 236 bool destroy
237 ) { 237 ) {
238 return cx_hash_map_get_remove(map, key, true, destroy); 238 return cx_hash_map_get_remove(map, key, true, destroy);
239 } 239 }
240 240
241 static void *cx_hash_map_iter_current_entry(void const *it) { 241 static void *cx_hash_map_iter_current_entry(const void *it) {
242 struct cx_iterator_s const *iter = it; 242 const struct cx_iterator_s *iter = it;
243 // struct has to have a compatible signature 243 // struct has to have a compatible signature
244 return (struct cx_map_entry_s *) &(iter->kv_data); 244 return (struct cx_map_entry_s *) &(iter->kv_data);
245 } 245 }
246 246
247 static void *cx_hash_map_iter_current_key(void const *it) { 247 static void *cx_hash_map_iter_current_key(const void *it) {
248 struct cx_iterator_s const *iter = it; 248 const struct cx_iterator_s *iter = it;
249 struct cx_hash_map_element_s *elm = iter->elem_handle; 249 struct cx_hash_map_element_s *elm = iter->elem_handle;
250 return &elm->key; 250 return &elm->key;
251 } 251 }
252 252
253 static void *cx_hash_map_iter_current_value(void const *it) { 253 static void *cx_hash_map_iter_current_value(const void *it) {
254 struct cx_iterator_s const *iter = it; 254 const struct cx_iterator_s *iter = it;
255 struct cx_hash_map_s const *map = iter->src_handle.c; 255 const struct cx_hash_map_s *map = iter->src_handle.c;
256 struct cx_hash_map_element_s *elm = iter->elem_handle; 256 struct cx_hash_map_element_s *elm = iter->elem_handle;
257 if (map->base.collection.store_pointer) { 257 if (map->base.collection.store_pointer) {
258 return *(void **) elm->data; 258 return *(void **) elm->data;
259 } else { 259 } else {
260 return elm->data; 260 return elm->data;
261 } 261 }
262 } 262 }
263 263
264 static bool cx_hash_map_iter_valid(void const *it) { 264 static bool cx_hash_map_iter_valid(const void *it) {
265 struct cx_iterator_s const *iter = it; 265 const struct cx_iterator_s *iter = it;
266 return iter->elem_handle != NULL; 266 return iter->elem_handle != NULL;
267 } 267 }
268 268
269 static void cx_hash_map_iter_next(void *it) { 269 static void cx_hash_map_iter_next(void *it) {
270 struct cx_iterator_s *iter = it; 270 struct cx_iterator_s *iter = it;
322 } 322 }
323 } 323 }
324 } 324 }
325 325
326 static CxIterator cx_hash_map_iterator( 326 static CxIterator cx_hash_map_iterator(
327 CxMap const *map, 327 const CxMap *map,
328 enum cx_map_iterator_type type 328 enum cx_map_iterator_type type
329 ) { 329 ) {
330 CxIterator iter; 330 CxIterator iter;
331 331
332 iter.src_handle.c = map; 332 iter.src_handle.c = map;
387 cx_hash_map_remove, 387 cx_hash_map_remove,
388 cx_hash_map_iterator, 388 cx_hash_map_iterator,
389 }; 389 };
390 390
391 CxMap *cxHashMapCreate( 391 CxMap *cxHashMapCreate(
392 CxAllocator const *allocator, 392 const CxAllocator *allocator,
393 size_t itemsize, 393 size_t itemsize,
394 size_t buckets 394 size_t buckets
395 ) { 395 ) {
396 if (buckets == 0) { 396 if (buckets == 0) {
397 // implementation defined default 397 // implementation defined default

mercurial