2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)db_shash.c 10.3 (Sleepycat) 6/21/97";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
20 #include "common_ext.h"
22 /* Powers-of-2 and close-by prime number pairs. */
40 * Choose a size for the hash table.
42 * PUBLIC: int __db_tablesize __P((int));
45 __db_tablesize(n_buckets
)
51 * We try to be clever about how big we make the hash tables. Pick
52 * a prime number close to the "suggested" number of elements that
53 * will be in the hash table. We shoot for minimum collisions (i.e.
54 * one element in each bucket). We use 64 as the minimum table size.
56 * Ref: Sedgewick, Algorithms in C, "Hash Functions"
62 if (list
[i
].power
== 0) {
66 if (list
[i
].power
>= n_buckets
)
69 return (list
[i
].prime
);
74 * Initialize a hash table that resides in shared memory.
76 * PUBLIC: void __db_hashinit __P((void *, int));
79 __db_hashinit(begin
, nelements
)
84 SH_TAILQ_HEAD(hash_head
) *headp
;
86 headp
= (struct hash_head
*)begin
;
88 for (i
= 0; i
< nelements
; i
++, headp
++)