Deleted Added
full compact
lhash.c (167613) lhash.c (205128)
1/* crypto/lhash/lhash.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *

--- 291 unchanged lines hidden (view full) ---

300void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
301 {
302 doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
303 }
304
305static void expand(LHASH *lh)
306 {
307 LHASH_NODE **n,**n1,**n2,*np;
1/* crypto/lhash/lhash.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *

--- 291 unchanged lines hidden (view full) ---

300void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
301 {
302 doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);
303 }
304
305static void expand(LHASH *lh)
306 {
307 LHASH_NODE **n,**n1,**n2,*np;
308 unsigned int p,i,j;
308 unsigned int p,i,j,pmax;
309 unsigned long hash,nni;
310
309 unsigned long hash,nni;
310
311 p=(int)lh->p++;
312 nni=lh->num_alloc_nodes;
313 pmax=lh->pmax;
314
315 if ((lh->p) >= lh->pmax)
316 {
317 j=(int)lh->num_alloc_nodes*2;
318 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
319 (int)sizeof(LHASH_NODE *)*j);
320 if (n == NULL)
321 {
322/* fputs("realloc error in lhash",stderr); */
323 lh->error++;
324 lh->p=0;
325 return;
326 }
327 /* else */
328 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
329 n[i]=NULL; /* 02/03/92 eay */
330 lh->pmax=lh->num_alloc_nodes;
331 lh->num_alloc_nodes=j;
332 lh->num_expand_reallocs++;
333 lh->p=0;
334 lh->b=n;
335 }
336
311 lh->num_nodes++;
312 lh->num_expands++;
337 lh->num_nodes++;
338 lh->num_expands++;
313 p=(int)lh->p++;
314 n1= &(lh->b[p]);
339 n1= &(lh->b[p]);
315 n2= &(lh->b[p+(int)lh->pmax]);
340 n2= &(lh->b[p+pmax]);
316 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
341 *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
317 nni=lh->num_alloc_nodes;
318
319 for (np= *n1; np != NULL; )
320 {
321#ifndef OPENSSL_NO_HASH_COMP
322 hash=np->hash;
323#else
324 hash=lh->hash(np->data);
325 lh->num_hash_calls++;

--- 4 unchanged lines hidden (view full) ---

330 np->next= *n2;
331 *n2=np;
332 }
333 else
334 n1= &((*n1)->next);
335 np= *n1;
336 }
337
342
343 for (np= *n1; np != NULL; )
344 {
345#ifndef OPENSSL_NO_HASH_COMP
346 hash=np->hash;
347#else
348 hash=lh->hash(np->data);
349 lh->num_hash_calls++;

--- 4 unchanged lines hidden (view full) ---

354 np->next= *n2;
355 *n2=np;
356 }
357 else
358 n1= &((*n1)->next);
359 np= *n1;
360 }
361
338 if ((lh->p) >= lh->pmax)
339 {
340 j=(int)lh->num_alloc_nodes*2;
341 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
342 (int)(sizeof(LHASH_NODE *)*j));
343 if (n == NULL)
344 {
345/* fputs("realloc error in lhash",stderr); */
346 lh->error++;
347 lh->p=0;
348 return;
349 }
350 /* else */
351 for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
352 n[i]=NULL; /* 02/03/92 eay */
353 lh->pmax=lh->num_alloc_nodes;
354 lh->num_alloc_nodes=j;
355 lh->num_expand_reallocs++;
356 lh->p=0;
357 lh->b=n;
358 }
359 }
360
361static void contract(LHASH *lh)
362 {
363 LHASH_NODE **n,*n1,*np;
362 }
363
364static void contract(LHASH *lh)
365 {
366 LHASH_NODE **n,*n1,*np;
367 int idx = lh->p+lh->pmax-1;
364
368
365 np=lh->b[lh->p+lh->pmax-1];
366 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
369 np=lh->b[idx];
367 if (lh->p == 0)
368 {
369 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
370 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
371 if (n == NULL)
372 {
373/* fputs("realloc error in lhash",stderr); */
374 lh->error++;
375 return;
376 }
377 lh->num_contract_reallocs++;
378 lh->num_alloc_nodes/=2;
379 lh->pmax/=2;
380 lh->p=lh->pmax-1;
381 lh->b=n;
382 }
383 else
384 lh->p--;
385
370 if (lh->p == 0)
371 {
372 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
373 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
374 if (n == NULL)
375 {
376/* fputs("realloc error in lhash",stderr); */
377 lh->error++;
378 return;
379 }
380 lh->num_contract_reallocs++;
381 lh->num_alloc_nodes/=2;
382 lh->pmax/=2;
383 lh->p=lh->pmax-1;
384 lh->b=n;
385 }
386 else
387 lh->p--;
388
389 lh->b[idx] = NULL;
386 lh->num_nodes--;
387 lh->num_contracts++;
388
389 n1=lh->b[(int)lh->p];
390 if (n1 == NULL)
391 lh->b[(int)lh->p]=np;
392 else
393 {

--- 77 unchanged lines hidden ---
390 lh->num_nodes--;
391 lh->num_contracts++;
392
393 n1=lh->b[(int)lh->p];
394 if (n1 == NULL)
395 lh->b[(int)lh->p]=np;
396 else
397 {

--- 77 unchanged lines hidden ---