Lines Matching refs:lh
100 void lh_free(_LHASH *lh) {
104 if (lh == NULL) {
108 for (i = 0; i < lh->num_buckets; i++) {
109 for (n = lh->buckets[i]; n != NULL; n = next) {
115 OPENSSL_free(lh->buckets);
116 OPENSSL_free(lh);
119 size_t lh_num_items(const _LHASH *lh) { return lh->num_items; }
124 * element of |lh->buckets|, otherwise it returns a pointer to the |next|
128 static LHASH_ITEM **get_next_ptr_and_hash(const _LHASH *lh, uint32_t *out_hash,
130 const uint32_t hash = lh->hash(data);
137 ret = &lh->buckets[hash % lh->num_buckets];
139 if (lh->comp(cur->data, data) == 0) {
148 void *lh_retrieve(const _LHASH *lh, const void *data) {
151 next_ptr = get_next_ptr_and_hash(lh, NULL, data);
161 * redistributes the existing items into it before making it |lh->buckets| and
163 static void lh_rebucket(_LHASH *lh, const size_t new_num_buckets) {
178 for (i = 0; i < lh->num_buckets; i++) {
179 for (cur = lh->buckets[i]; cur != NULL; cur = next) {
187 OPENSSL_free(lh->buckets);
189 lh->num_buckets = new_num_buckets;
190 lh->buckets = new_buckets;
194 static void lh_maybe_resize(_LHASH *lh) {
197 if (lh->callback_depth > 0) {
202 assert(lh->num_buckets >= kMinNumBuckets);
203 avg_chain_length = lh->num_items / lh->num_buckets;
206 const size_t new_num_buckets = lh->num_buckets * 2;
208 if (new_num_buckets > lh->num_buckets) {
209 lh_rebucket(lh, new_num_buckets);
212 lh->num_buckets > kMinNumBuckets) {
213 size_t new_num_buckets = lh->num_buckets / 2;
219 lh_rebucket(lh, new_num_buckets);
223 int lh_insert(_LHASH *lh, void **old_data, void *data) {
228 next_ptr = get_next_ptr_and_hash(lh, &hash, data);
249 lh->num_items++;
250 lh_maybe_resize(lh);
255 void *lh_delete(_LHASH *lh, const void *data) {
258 next_ptr = get_next_ptr_and_hash(lh, NULL, data);
270 lh->num_items--;
271 lh_maybe_resize(lh);
276 static void lh_doall_internal(_LHASH *lh, void (*no_arg_func)(void *),
281 if (lh == NULL) {
285 if (lh->callback_depth < UINT_MAX) {
287 lh->callback_depth++;
290 for (i = 0; i < lh->num_buckets; i++) {
291 for (cur = lh->buckets[i]; cur != NULL; cur = next) {
301 if (lh->callback_depth < UINT_MAX) {
302 lh->callback_depth--;
308 lh_maybe_resize(lh);
311 void lh_doall(_LHASH *lh, void (*func)(void *)) {
312 lh_doall_internal(lh, func, NULL, NULL);
315 void lh_doall_arg(_LHASH *lh, void (*func)(void *, void *), void *arg) {
316 lh_doall_internal(lh, NULL, func, arg);