Wed, 31 Dec 2025 16:32:36 +0100
Added tag v4.0 for changeset 976e629ce990
|
1143
0559812df10c
assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents:
1142
diff
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:
1318
diff
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:
1228
diff
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:
1141
diff
changeset
|
10 | |
|
1228
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
11 | ```C |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
12 | #include <cx/hash_map.h> |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
13 | |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
14 | CxMap *cxHashMapCreate(const CxAllocator *allocator, |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
15 | size_t itemsize, size_t buckets); |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
16 | |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
17 | int cxMapRehash(CxMap *map); |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
18 | ``` |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
19 | |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
20 | 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:
1190
diff
changeset
|
21 | and the contained buckets are allocated by the specified `allocator`. |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
22 | |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
23 | The map will store items of size `itemsize`. |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
24 | 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:
1190
diff
changeset
|
25 | pointers instead of actual items. |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
26 | |
|
1605
55b13f583356
refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents:
1424
diff
changeset
|
27 | If you pass zero for 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:
1318
diff
changeset
|
28 | 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:
1190
diff
changeset
|
29 | |
|
1694
a2757c6427cc
proof-read documentation
Mike Becker <universe@uap-core.de>
parents:
1605
diff
changeset
|
30 | The `cxMapRehash()` function creates a new bucket array and reassigns all elements when the element count surpasses three-quarters of the bucket count. |
|
a2757c6427cc
proof-read documentation
Mike Becker <universe@uap-core.de>
parents:
1605
diff
changeset
|
31 | If this condition isn't met, the function returns 0 without making any changes. |
|
a2757c6427cc
proof-read documentation
Mike Becker <universe@uap-core.de>
parents:
1605
diff
changeset
|
32 | Post-rehashing, the bucket count will be at least two and a half times the element count. |
|
1228
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
33 | |
|
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
34 | > Advice if you want to create your own hash map structures: |
|
1694
a2757c6427cc
proof-read documentation
Mike Becker <universe@uap-core.de>
parents:
1605
diff
changeset
|
35 | > Calling `cxMapRehash()` on a map is only defined when the map is based on the |
|
1228
c231f6a259b5
add documentation for hash_map.h
Mike Becker <universe@uap-core.de>
parents:
1190
diff
changeset
|
36 | > `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:
1146
diff
changeset
|
37 | |
|
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
38 | <seealso> |
|
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
39 | <category ref="apidoc"> |
|
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
40 | <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:
1146
diff
changeset
|
41 | </category> |
|
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
42 | </seealso> |
|
a7b913d5d589
bring incomplete docs into a shape that can be released
Mike Becker <universe@uap-core.de>
parents:
1146
diff
changeset
|
43 |