| 71 * |
71 * |
| 72 * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of |
72 * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of |
| 73 * copies of the added elements. |
73 * copies of the added elements. |
| 74 * |
74 * |
| 75 * @note Iterators provided by this hash map implementation provide the remove operation. |
75 * @note Iterators provided by this hash map implementation provide the remove operation. |
| 76 * The index value of an iterator is incremented when the iterator advanced without removal. |
76 * The index value of an iterator is incremented when the iterator advanced without |
| |
77 * removing an entry. |
| 77 * In other words, when the iterator is finished, @c index==size . |
78 * In other words, when the iterator is finished, @c index==size . |
| 78 * |
79 * |
| 79 * @param allocator the allocator to use |
80 * @param allocator the allocator to use |
| 80 * (if @c NULL, the cxDefaultAllocator will be used) |
81 * (if @c NULL, the cxDefaultAllocator will be used) |
| 81 * @param itemsize the size of one element |
82 * @param itemsize the size of one element |
| 82 * @param buckets the initial number of buckets in this hash map |
83 * @param buckets the initial number of buckets in this hash map |
| 83 * @return a pointer to the new hash map |
84 * @return a pointer to the new hash map |
| 84 */ |
85 */ |
| 85 cx_attr_nodiscard |
86 cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMapFree, 1) |
| 86 cx_attr_malloc |
87 CX_EXPORT CxMap *cxHashMapCreate(const CxAllocator *allocator, |
| 87 cx_attr_dealloc(cxMapFree, 1) |
88 size_t itemsize, size_t buckets); |
| 88 cx_attr_export |
|
| 89 CxMap *cxHashMapCreate( |
|
| 90 const CxAllocator *allocator, |
|
| 91 size_t itemsize, |
|
| 92 size_t buckets |
|
| 93 ); |
|
| 94 |
89 |
| 95 /** |
90 /** |
| 96 * Creates a new hash map with a default number of buckets. |
91 * Creates a new hash map with a default number of buckets. |
| 97 * |
92 * |
| 98 * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of |
93 * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of |
| 99 * copies of the added elements. |
94 * copies of the added elements. |
| 100 * |
95 * |
| 101 * @note Iterators provided by this hash map implementation provide the remove operation. |
96 * @note Iterators provided by this hash map implementation provide the remove operation. |
| 102 * The index value of an iterator is incremented when the iterator advanced without removal. |
97 * The index value of an iterator is incremented when the iterator advanced without |
| |
98 * removing an entry. |
| 103 * In other words, when the iterator is finished, @c index==size . |
99 * In other words, when the iterator is finished, @c index==size . |
| 104 * |
100 * |
| 105 * @param itemsize (@c size_t) the size of one element |
101 * @param itemsize (@c size_t) the size of one element |
| 106 * @return (@c CxMap*) a pointer to the new hash map |
102 * @return (@c CxMap*) a pointer to the new hash map |
| 107 */ |
103 */ |
| 109 |
105 |
| 110 /** |
106 /** |
| 111 * Increases the number of buckets, if necessary. |
107 * Increases the number of buckets, if necessary. |
| 112 * |
108 * |
| 113 * The load threshold is @c 0.75*buckets. If the element count exceeds the load |
109 * The load threshold is @c 0.75*buckets. If the element count exceeds the load |
| 114 * threshold, the map will be rehashed. Otherwise, no action is performed and |
110 * threshold, the map will be rehashed. Otherwise, no action is performed, and |
| 115 * this function simply returns 0. |
111 * this function simply returns 0. |
| 116 * |
112 * |
| 117 * The rehashing process ensures, that the number of buckets is at least |
113 * The rehashing process ensures that the number of buckets is at least |
| 118 * 2.5 times the element count. So there is enough room for additional |
114 * 2.5 times the element count. So there is enough room for additional |
| 119 * elements without the need of another soon rehashing. |
115 * elements without the need of another soon rehashing. |
| 120 * |
116 * |
| 121 * You can use this function after filling a map to increase access performance. |
117 * You can use this function after filling a map to increase access performance. |
| 122 * |
118 * |