| 412 if (buckets == 0) { |
412 if (buckets == 0) { |
| 413 // implementation defined default |
413 // implementation defined default |
| 414 buckets = 16; |
414 buckets = 16; |
| 415 } |
415 } |
| 416 |
416 |
| 417 struct cx_hash_map_s *map = cxCalloc(allocator, 1, |
417 struct cx_hash_map_s *map = cxZalloc(allocator, sizeof(struct cx_hash_map_s)); |
| 418 sizeof(struct cx_hash_map_s)); |
|
| 419 if (map == NULL) return NULL; |
418 if (map == NULL) return NULL; |
| 420 |
419 |
| 421 // initialize hash map members |
420 // initialize hash map members |
| 422 map->bucket_count = buckets; |
421 map->bucket_count = buckets; |
| 423 map->buckets = cxCalloc(allocator, buckets, |
422 map->buckets = cxCalloc(allocator, buckets, |
| 431 map->base.cl = &cx_hash_map_class; |
430 map->base.cl = &cx_hash_map_class; |
| 432 map->base.collection.allocator = allocator; |
431 map->base.collection.allocator = allocator; |
| 433 |
432 |
| 434 if (itemsize > 0) { |
433 if (itemsize > 0) { |
| 435 map->base.collection.elem_size = itemsize; |
434 map->base.collection.elem_size = itemsize; |
| |
435 map->base.collection.advanced_cmp = cx_acmp_memcmp; |
| |
436 map->base.collection.cmp_data = &map->base.collection.elem_size; |
| 436 } else { |
437 } else { |
| 437 map->base.collection.elem_size = sizeof(void *); |
438 map->base.collection.elem_size = sizeof(void *); |
| 438 map->base.collection.store_pointer = true; |
439 map->base.collection.store_pointer = true; |
| |
440 map->base.collection.simple_cmp = cx_cmp_ptr; |
| 439 } |
441 } |
| 440 |
442 |
| 441 return (CxMap *) map; |
443 return (CxMap *) map; |
| 442 } |
444 } |
| 443 |
445 |