| 12 #include <cx/hash_map.h> |
12 #include <cx/hash_map.h> |
| 13 |
13 |
| 14 CxMap *cxHashMapCreate(const CxAllocator *allocator, |
14 CxMap *cxHashMapCreate(const CxAllocator *allocator, |
| 15 size_t itemsize, size_t buckets); |
15 size_t itemsize, size_t buckets); |
| 16 |
16 |
| 17 CxMap *cxHashMapCreateSimple(size_t itemsize); |
|
| 18 |
|
| 19 int cxMapRehash(CxMap *map); |
17 int cxMapRehash(CxMap *map); |
| 20 ``` |
18 ``` |
| 21 |
19 |
| 22 The function `cxHashMapCreate()` creates a new [map](map.h.md) where both the map structure |
20 The function `cxHashMapCreate()` creates a new [map](map.h.md) where both the map structure |
| 23 and the contained buckets are allocated by the specified `allocator`. |
21 and the contained buckets are allocated by the specified `allocator`. |
| 24 The [default allocator](allocator.h.md#default-allocator) is used in `cxHashMapCreateSimple()`. |
|
| 25 |
22 |
| 26 The map will store items of size `itemsize`. |
23 The map will store items of size `itemsize`. |
| 27 You can use the `CX_STORE_POINTERS` macro for `itemsize` to indicate that the map shall store |
24 You can use the `CX_STORE_POINTERS` macro for `itemsize` to indicate that the map shall store |
| 28 pointers instead of actual items. |
25 pointers instead of actual items. |
| 29 |
26 |
| 30 If you pass zero for the number of `buckets`, or use `cxHashMapSimple()`, |
27 If you pass zero for the number of `buckets`, |
| 31 the map is initialized with a default of 16 buckets; otherwise the specified number of buckets is allocated. |
28 the map is initialized with a default of 16 buckets; otherwise the specified number of buckets is allocated. |
| 32 |
29 |
| 33 The function `cxMapRehash()` allocates a new array of buckets and re-distributes all elements, |
30 The function `cxMapRehash()` allocates a new array of buckets and re-distributes all elements, |
| 34 if the number of elements exceeds ¾ of the number of buckets. |
31 if the number of elements exceeds ¾ of the number of buckets. |
| 35 Otherwise, no action is performed, and this function simply returns 0. |
32 Otherwise, no action is performed, and this function simply returns 0. |