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