Lines Matching refs:lh
110 static void expand(_LHASH *lh);
111 static void contract(_LHASH *lh);
112 static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash);
157 void lh_free(_LHASH *lh) in lh_free() argument
162 if (lh == NULL) in lh_free()
165 for (i=0; i<lh->num_nodes; i++) in lh_free()
167 n=lh->b[i]; in lh_free()
175 OPENSSL_free(lh->b); in lh_free()
176 OPENSSL_free(lh); in lh_free()
179 void *lh_insert(_LHASH *lh, void *data) in lh_insert() argument
185 lh->error=0; in lh_insert()
186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) in lh_insert()
187 expand(lh); in lh_insert()
189 rn=getrn(lh,data,&hash); in lh_insert()
195 lh->error++; in lh_insert()
205 lh->num_insert++; in lh_insert()
206 lh->num_items++; in lh_insert()
212 lh->num_replace++; in lh_insert()
217 void *lh_delete(_LHASH *lh, const void *data) in lh_delete() argument
223 lh->error=0; in lh_delete()
224 rn=getrn(lh,data,&hash); in lh_delete()
228 lh->num_no_delete++; in lh_delete()
237 lh->num_delete++; in lh_delete()
240 lh->num_items--; in lh_delete()
241 if ((lh->num_nodes > MIN_NODES) && in lh_delete()
242 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) in lh_delete()
243 contract(lh); in lh_delete()
248 void *lh_retrieve(_LHASH *lh, const void *data) in lh_retrieve() argument
254 lh->error=0; in lh_retrieve()
255 rn=getrn(lh,data,&hash); in lh_retrieve()
259 lh->num_retrieve_miss++; in lh_retrieve()
265 lh->num_retrieve++; in lh_retrieve()
270 static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, in doall_util_fn() argument
276 if (lh == NULL) in doall_util_fn()
281 for (i=lh->num_nodes-1; i>=0; i--) in doall_util_fn()
283 a=lh->b[i]; in doall_util_fn()
300 void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func) in lh_doall() argument
302 doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL); in lh_doall()
305 void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg) in lh_doall_arg() argument
307 doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg); in lh_doall_arg()
310 static void expand(_LHASH *lh) in expand() argument
316 lh->num_nodes++; in expand()
317 lh->num_expands++; in expand()
318 p=(int)lh->p++; in expand()
319 n1= &(lh->b[p]); in expand()
320 n2= &(lh->b[p+(int)lh->pmax]); in expand()
322 nni=lh->num_alloc_nodes; in expand()
329 hash=lh->hash(np->data); in expand()
330 lh->num_hash_calls++; in expand()
343 if ((lh->p) >= lh->pmax) in expand()
345 j=(int)lh->num_alloc_nodes*2; in expand()
346 n=(LHASH_NODE **)OPENSSL_realloc(lh->b, in expand()
351 lh->error++; in expand()
352 lh->p=0; in expand()
356 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */ in expand()
358 lh->pmax=lh->num_alloc_nodes; in expand()
359 lh->num_alloc_nodes=j; in expand()
360 lh->num_expand_reallocs++; in expand()
361 lh->p=0; in expand()
362 lh->b=n; in expand()
366 static void contract(_LHASH *lh) in contract() argument
370 np=lh->b[lh->p+lh->pmax-1]; in contract()
371 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ in contract()
372 if (lh->p == 0) in contract()
374 n=(LHASH_NODE **)OPENSSL_realloc(lh->b, in contract()
375 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); in contract()
379 lh->error++; in contract()
382 lh->num_contract_reallocs++; in contract()
383 lh->num_alloc_nodes/=2; in contract()
384 lh->pmax/=2; in contract()
385 lh->p=lh->pmax-1; in contract()
386 lh->b=n; in contract()
389 lh->p--; in contract()
391 lh->num_nodes--; in contract()
392 lh->num_contracts++; in contract()
394 n1=lh->b[(int)lh->p]; in contract()
396 lh->b[(int)lh->p]=np; in contract()
405 static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash) in getrn() argument
411 hash=(*(lh->hash))(data); in getrn()
412 lh->num_hash_calls++; in getrn()
415 nn=hash%lh->pmax; in getrn()
416 if (nn < lh->p) in getrn()
417 nn=hash%lh->num_alloc_nodes; in getrn()
419 cf=lh->comp; in getrn()
420 ret= &(lh->b[(int)nn]); in getrn()
424 lh->num_hash_comps++; in getrn()
431 lh->num_comp_calls++; in getrn()
472 unsigned long lh_num_items(const _LHASH *lh) in lh_num_items() argument
474 return lh ? lh->num_items : 0; in lh_num_items()