ucx/cx/hash_map.h

branch
dav-2
changeset 889
42cdbf9bbd49
parent 886
da79af4baec8
equal deleted inserted replaced
887:26541c37b619 889:42cdbf9bbd49
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 *
125 * @param map the map to rehash 121 * @param map the map to rehash
126 * @retval zero success 122 * @retval zero success
127 * @retval non-zero if a memory allocation error occurred 123 * @retval non-zero if a memory allocation error occurred
128 */ 124 */
129 cx_attr_nonnull 125 cx_attr_nonnull
130 cx_attr_export 126 CX_EXPORT int cxMapRehash(CxMap *map);
131 int cxMapRehash(CxMap *map);
132 127
133 128
134 #ifdef __cplusplus 129 #ifdef __cplusplus
135 } // extern "C" 130 } // extern "C"
136 #endif 131 #endif

mercurial