Thu, 30 Oct 2025 19:27:18 +0100
fix typo bug in cxListDifference() - resolves #745
| 1143 
0559812df10c
assign proper names to the documentation topics
 Mike Becker <universe@uap-core.de> parents: 
1142diff
changeset | 1 | # Hash Map | 
| 1141 | 2 | |
| 1424 
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 3 | UCX provides a basic hash map implementation with a configurable number of buckets. | 
| 1141 | 4 | If you do not specify the number of buckets, a default of 16 buckets will be used. | 
| 1243 
13e15cd529ae
structur for map.h documentation
 Mike Becker <universe@uap-core.de> parents: 
1228diff
changeset | 5 | |
| 1141 | 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 | |
| 8 | specific hash map implementation, and you would need to remove all calls to this function when you want to | |
| 9 | exchange the concrete map implementation with something different. | |
| 1142 
9437530176bc
add symbols that need documentation as TODOs
 Mike Becker <universe@uap-core.de> parents: 
1141diff
changeset | 10 | |
| 1228 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 11 | ```C | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 12 | #include <cx/hash_map.h> | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 13 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 14 | CxMap *cxHashMapCreate(const CxAllocator *allocator, | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 15 | size_t itemsize, size_t buckets); | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 16 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 17 | CxMap *cxHashMapCreateSimple(size_t itemsize); | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 18 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 19 | int cxMapRehash(CxMap *map); | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 20 | ``` | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 21 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 22 | The function `cxHashMapCreate()` creates a new [map](map.h.md) where both the map structure | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 23 | and the contained buckets are allocated by the specified `allocator`. | 
| 1318 
12fa1d37fe48
allow changing the cxDefaultAllocator - resolves #669
 Mike Becker <universe@uap-core.de> parents: 
1243diff
changeset | 24 | The [default allocator](allocator.h.md#default-allocator) is used in `cxHashMapCreateSimple()`. | 
| 1228 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 25 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 26 | The map will store items of size `itemsize`. | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 27 | You can use the `CX_STORE_POINTERS` macro for `itemsize` to indicate that the map shall store | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 28 | pointers instead of actual items. | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 29 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 30 | If you pass zero for the number of `buckets`, or use `cxHashMapSimple()`, | 
| 1424 
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 31 | the map is initialized with a default of 16 buckets; otherwise the specified number of buckets is allocated. | 
| 1228 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 32 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 33 | The function `cxMapRehash()` allocates a new array of buckets and re-distributes all elements, | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 34 | if the number of elements exceeds ¾ of the number of buckets. | 
| 1424 
563033aa998c
fixes tons of typos and grammar issues across the documentation - fixes #667
 Mike Becker <universe@uap-core.de> parents: 
1318diff
changeset | 35 | Otherwise, no action is performed, and this function simply returns 0. | 
| 1228 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 36 | After rehashing, the number of buckets is at least 2½ times the number of elements. | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 37 | |
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 38 | > Advice if you want to create your own hash map structures: | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 39 | > Calling `cxMapRehash()` on a map is only defined, when the map is based on the | 
| 
c231f6a259b5
add documentation for hash_map.h
 Mike Becker <universe@uap-core.de> parents: 
1190diff
changeset | 40 | > `struct cx_hash_map_s` structure. | 
| 1190 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 41 | |
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 42 | <seealso> | 
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 43 | <category ref="apidoc"> | 
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 44 | <a href="https://ucx.sourceforge.io/api/hash__map_8h.html">hash_map.h</a> | 
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 45 | </category> | 
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 46 | </seealso> | 
| 
a7b913d5d589
bring incomplete docs into a shape that can be released
 Mike Becker <universe@uap-core.de> parents: 
1146diff
changeset | 47 |