1 # Hash Map |
1 # Hash Map |
2 |
2 |
3 UCX provides a basic hash map implementation with a configurable amount of buckets. |
3 UCX provides a basic hash map implementation with a configurable number of buckets. |
4 If you do not specify the number of buckets, a default of 16 buckets will be used. |
4 If you do not specify the number of buckets, a default of 16 buckets will be used. |
5 |
5 |
6 You can always rehash the map with `cxMapRehash()` to change the number of buckets to something more efficient, |
6 You can always rehash the map with `cxMapRehash()` to change the number of buckets to something more efficient, |
7 but you need to be careful, because when you use this function you are effectively locking into using this |
7 but you need to be careful, because when you use this function you are effectively locking into using this |
8 specific hash map implementation, and you would need to remove all calls to this function when you want to |
8 specific hash map implementation, and you would need to remove all calls to this function when you want to |
26 The map will store items of size `itemsize`. |
26 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 |
27 You can use the `CX_STORE_POINTERS` macro for `itemsize` to indicate that the map shall store |
28 pointers instead of actual items. |
28 pointers instead of actual items. |
29 |
29 |
30 If you pass zero for the number of `buckets`, or use `cxHashMapSimple()`, |
30 If you pass zero for the number of `buckets`, or use `cxHashMapSimple()`, |
31 the map is initialized with a default of 16 buckets, otherwise the specified number of buckets is allocated. |
31 the map is initialized with a default of 16 buckets; otherwise the specified number of buckets is allocated. |
32 |
32 |
33 The function `cxMapRehash()` allocates a new array of buckets and re-distributes all elements, |
33 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. |
34 if the number of elements exceeds ¾ of the number of buckets. |
35 Otherwise, no action is performed and this function simply returns 0. |
35 Otherwise, no action is performed, and this function simply returns 0. |
36 After rehashing, the number of buckets is at least 2½ times the number of elements. |
36 After rehashing, the number of buckets is at least 2½ times the number of elements. |
37 |
37 |
38 > Advice if you want to create your own hash map structures: |
38 > Advice if you want to create your own hash map structures: |
39 > Calling `cxMapRehash()` on a map is only defined, when the map is based on the |
39 > Calling `cxMapRehash()` on a map is only defined, when the map is based on the |
40 > `struct cx_hash_map_s` structure. |
40 > `struct cx_hash_map_s` structure. |