7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.19 1999/02/22 06:16:47 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/hash/dynahash.c,v 1.20 1999/03/06 21:17:56 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -373,18 +373,23 @@ hash_estimate_size(long num_entries, long keysize, long datasize)
373
373
long size = 0 ;
374
374
long nBuckets ,
375
375
nSegments ,
376
+ nDirEntries ,
376
377
nRecordAllocs ,
377
378
recordSize ;
378
379
379
380
/* estimate number of buckets wanted */
380
381
nBuckets = 1L << my_log2 ((num_entries - 1 ) / DEF_FFACTOR + 1 );
381
382
/* # of segments needed for nBuckets */
382
- nSegments = (nBuckets - 1 ) / DEF_SEGSIZE + 1 ;
383
+ nSegments = 1L << my_log2 ((nBuckets - 1 ) / DEF_SEGSIZE + 1 );
384
+ /* directory entries */
385
+ nDirEntries = DEF_DIRSIZE ;
386
+ while (nDirEntries < nSegments )
387
+ nDirEntries <<= 1 ; /* dir_alloc doubles dsize at each call */
383
388
384
389
/* fixed control info */
385
390
size += MAXALIGN (sizeof (HHDR )); /* but not HTAB, per above */
386
- /* directory, assumed to be of size DEF_DIRSIZE */
387
- size += MAXALIGN (DEF_DIRSIZE * sizeof (SEG_OFFSET ));
391
+ /* directory */
392
+ size += MAXALIGN (nDirEntries * sizeof (SEG_OFFSET ));
388
393
/* segments */
389
394
size += nSegments * MAXALIGN (DEF_SEGSIZE * sizeof (BUCKET_INDEX ));
390
395
/* records --- allocated in groups of BUCKET_ALLOC_INCR */
@@ -408,9 +413,6 @@ hash_estimate_size(long num_entries, long keysize, long datasize)
408
413
void
409
414
hash_destroy (HTAB * hashp )
410
415
{
411
- /* cannot destroy a shared memory hash table */
412
- Assert (!hashp -> segbase );
413
-
414
416
if (hashp != NULL )
415
417
{
416
418
SEG_OFFSET segNum ;
@@ -422,6 +424,13 @@ hash_destroy(HTAB *hashp)
422
424
q ;
423
425
ELEMENT * curr ;
424
426
427
+ /* cannot destroy a shared memory hash table */
428
+ Assert (!hashp -> segbase );
429
+ /* allocation method must be one we know how to free, too */
430
+ Assert (hashp -> alloc == (dhalloc_ptr ) MEM_ALLOC );
431
+
432
+ hash_stats ("destroy" , hashp );
433
+
425
434
for (segNum = 0 ; nsegs > 0 ; nsegs -- , segNum ++ )
426
435
{
427
436
@@ -435,11 +444,10 @@ hash_destroy(HTAB *hashp)
435
444
MEM_FREE ((char * ) curr );
436
445
}
437
446
}
438
- free ((char * ) segp );
447
+ MEM_FREE ((char * ) segp );
439
448
}
440
449
MEM_FREE ((char * ) hashp -> dir );
441
450
MEM_FREE ((char * ) hashp -> hctl );
442
- hash_stats ("destroy" , hashp );
443
451
MEM_FREE ((char * ) hashp );
444
452
}
445
453
}
0 commit comments