src/cx/hash_map.h

changeset 562
fd3368c20413
parent 559
8603709932b9
child 563
69a83fad8a35
equal deleted inserted replaced
561:bb17790af41e 562:fd3368c20413
106 ); 106 );
107 107
108 /** 108 /**
109 * Increases the number of buckets, if necessary. 109 * Increases the number of buckets, if necessary.
110 * 110 *
111 * The load value is \c loadFactor*buckets. If the element count exceeds the load 111 * The load threshold is \c 0.75*buckets. If the element count exceeds the load
112 * value, the map needs to be rehashed. Otherwise, no action is performed and 112 * threshold, the map will be rehashed. Otherwise, no action is performed and
113 * this function simply returns 0. 113 * this function simply returns 0.
114 * 114 *
115 * The rehashing process ensures, that the number of buckets is at least 115 * The rehashing process ensures, that the number of buckets is at least
116 * \p bucketFactor times the number of stored items. So there is enough room for additional 116 * 2.5 times the element count. So there is enough room for additional
117 * elements without the need of another soon rehashing. 117 * elements without the need of another soon rehashing.
118 * 118 *
119 * You can use this function after filling a map to dramatically increase access performance. 119 * You can use this function after filling a map to increase access performance.
120 * 120 *
121 * @note If the specified map is not a hash map, the behavior is undefined. 121 * @note If the specified map is not a hash map, the behavior is undefined.
122 * 122 *
123 * @param map the map to rehash 123 * @param map the map to rehash
124 * @param loadFactor a percentage threshold for the load of the map
125 * @param bucketFactor a factor for the number of buckets that shall be available after rehashing
126 * @return zero on success, non-zero if a memory allocation error occurred 124 * @return zero on success, non-zero if a memory allocation error occurred
127 */ 125 */
128 __attribute__((__nonnull__)) 126 __attribute__((__nonnull__))
129 int cxMapRehash2( 127 int cxMapRehash(CxMap *map);
130 CxMap *map,
131 float loadFactor,
132 float bucketFactor
133 );
134
135 /**
136 * Rehashes the map with load factor 0.75 and bucket factor 2.5.
137 *
138 * @param map the map to rehash
139 * @return zero on success, non-zero if a memory allocation error occurred
140 * @see cxMapRehash2()
141 */
142 __attribute__((__nonnull__))
143 static inline int cxMapRehash(CxMap *map) {
144 return cxMapRehash2(map, 0.75f, 2.5f);
145 }
146 128
147 129
148 #ifdef __cplusplus 130 #ifdef __cplusplus
149 } // extern "C" 131 } // extern "C"
150 #endif 132 #endif

mercurial