glibc/db2/common/db_shash.c
Ulrich Drepper bf7997b65c Update.
1998-06-09  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/netinet/ip.h (struct ip_options): Define
	__data member only for gcc.  Reported by ak@muc.de.

	* misc/mntent.h: Undo last patch.
	* sysdeps/unix/sysv/linux/fstatvfs.c (fstatvfs): Undo last patch.
	* misc/tst/mntent.c: Adjust code for this change.

	* io/fts.c: Updated from a slightly more recent BSD version.
	* io/fts.h: Likewise.

	* libc.map: Add __libc_stack_end.

	* db2/Makefile (routines): Add lock_region.
	* db2/config.h: Update from db-2.4.14.
	* db2/db.h: Likewise.
	* db2/db_185.h: Likewise.
	* db2/db_int.h: Likewise.
	* db2/bt_close.c: Likewise.
	* db2/bt_compare.c: Likewise.
	* db2/bt_conv.c: Likewise.
	* db2/bt_cursor.c: Likewise.
	* db2/bt_delete.c: Likewise.
	* db2/bt_open.c: Likewise.
	* db2/bt_page.c: Likewise.
	* db2/bt_put.c: Likewise.
	* db2/bt_rec.c: Likewise.
	* db2/bt_recno.c: Likewise.
	* db2/bt_rsearch.c: Likewise.
	* db2/bt_search.c: Likewise.
	* db2/bt_split.c: Likewise.
	* db2/bt_stat.c: Likewise.
	* db2/btree.src: Likewise.
	* db2/btree_auto.c: Likewise.
	* db2/getlong.c: Likewise.
	* db2/db_appinit.c: Likewise.
	* db2/db_apprec.c: Likewise.
	* db2/db_byteorder.c: Likewise.
	* db2/db_err.c: Likewise.
	* db2/db_log2.c: Likewise.
	* db2/db_region.c: Likewise.
	* db2/db_salloc.c: Likewise.
	* db2/db_shash.c: Likewise.
	* db2/db.c: Likewise.
	* db2/db.src: Likewise.
	* db2/db_auto.c: Likewise.
	* db2/db_conv.c: Likewise.
	* db2/db_dispatch.c: Likewise.
	* db2/db_dup.c: Likewise.
	* db2/db_overflow.c: Likewise.
	* db2/db_pr.c: Likewise.
	* db2/db_rec.c: Likewise.
	* db2/db_ret.c: Likewise.
	* db2/db_thread.c: Likewise.
	* db2/db185.c: Likewise.
	* db2/db185_int.h: Likewise.
	* db2/dbm.c: Likewise.
	* db2/hash.c: Likewise.
	* db2/hash.src: Likewise.
	* db2/hash_auto.c: Likewise.
	* db2/hash_conv.c: Likewise.
	* db2/hash_debug.c: Likewise.
	* db2/hash_dup.c: Likewise.
	* db2/hash_func.c: Likewise.
	* db2/hash_page.c: Likewise.
	* db2/hash_rec.c: Likewise.
	* db2/hash_stat.c: Likewise.
	* db2/btree.h: Likewise.
	* db2/btree_ext.h: Likewise.
	* db2/clib_ext.h: Likewise.
	* db2/common_ext.h: Likewise.
	* db2/cxx_int.h: Likewise.
	* db2/db.h.src: Likewise.
	* db2/db_185.h.src: Likewise.
	* db2/db_am.h: Likewise.
	* db2/db_auto.h: Likewise.
	* db2/db_cxx.h: Likewise.
	* db2/db_dispatch.h: Likewise.
	* db2/db_ext.h: Likewise.
	* db2/db_int.h.src: Likewise.
	* db2/db_page.h: Likewise.
	* db2/db_shash.h: Likewise.
	* db2/db_swap.h: Likewise.
	* db2/hash.h: Likewise.
	* db2/hash_ext.h: Likewise.
	* db2/lock.h: Likewise.
	* db2/lock_ext.h: Likewise.
	* db2/log.h: Likewise.
	* db2/log_ext.h: Likewise.
	* db2/mp.h: Likewise.
	* db2/mp_ext.h: Likewise.
	* db2/mutex_ext.h: Likewise.
	* db2/os_ext.h: Likewise.
	* db2/os_func.h: Likewise.
	* db2/queue.h: Likewise.
	* db2/shqueue.h: Likewise.
	* db2/txn.h: Likewise.
	* db2/lock.c: Likewise.
	* db2/lock_conflict.c: Likewise.
	* db2/lock_deadlock.c: Likewise.
	* db2/lock_region.c: Likewise.
	* db2/lock_util.c: Likewise.
	* db2/log.c: Likewise.
	* db2/log.src: Likewise.
	* db2/log_archive.c: Likewise.
	* db2/log_auto.c: Likewise.
	* db2/log_compare.c: Likewise.
	* db2/log_findckp.c: Likewise.
	* db2/log_get.c: Likewise.
	* db2/log_put.c: Likewise.
	* db2/log_rec.c: Likewise.
	* db2/log_register.c: Likewise.
	* db2/mp_bh.c: Likewise.
	* db2/mp_fget.c: Likewise.
	* db2/mp_fopen.c: Likewise.
	* db2/mp_fput.c: Likewise.
	* db2/mp_fset.c: Likewise.
	* db2/mp_open.c: Likewise.
	* db2/mp_pr.c: Likewise.
	* db2/mp_region.c: Likewise.
	* db2/mp_sync.c: Likewise.
	* db2/68020.gcc: Likewise.
	* db2/mutex.c: Likewise.
	* db2/parisc.gcc: Likewise.
	* db2/parisc.hp: Likewise.
	* db2/sco.cc: Likewise.
	* db2/os_abs.c: Likewise.
	* db2/os_alloc.c: Likewise.
	* db2/os_config.c: Likewise.
	* db2/os_dir.c: Likewise.
	* db2/os_fid.c: Likewise.
	* db2/os_fsync.c: Likewise.
	* db2/os_map.c: Likewise.
	* db2/os_oflags.c: Likewise.
	* db2/os_open.c: Likewise.
	* db2/os_rpath.c: Likewise.
	* db2/os_rw.c: Likewise.
	* db2/os_seek.c: Likewise.
	* db2/os_sleep.c: Likewise.
	* db2/os_spin.c: Likewise.
	* db2/os_stat.c: Likewise.
	* db2/os_unlink.c: Likewise.
	* db2/db_archive.c: Likewise.
	* db2/db_checkpoint.c: Likewise.
	* db2/db_deadlock.c: Likewise.
	* db2/db_dump.c: Likewise.
	* db2/db_dump185.c: Likewise.
	* db2/db_load.c: Likewise.
	* db2/db_printlog.c: Likewise.
	* db2/db_recover.c: Likewise.
	* db2/db_stat.c: Likewise.
	* db2/txn.c: Likewise.
	* db2/txn.src: Likewise.
	* db2/txn_auto.c: Likewise.
	* db2/txn_rec.c: Likewise.

	* elf/rtld.c: Move definition of __libc_stack_end to ...
	* sysdeps/generic/dl-sysdep.h: ...here.

	* sysdeps/unix/sysv/linux/fstatvfs.c: Handle nodiratime option.
	* sysdeps/unix/sysv/linux/bits/statvfs.h: Define ST_NODIRATIME.
	* sysdeps/unix/sysv/linux/sys/mount.h: Define MS_NODIRATIME.

1998-06-08 21:44  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/fstatvfs.c: Handle constant option string
	from mntent correctly.

1998-06-06  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* sunrpc/Makefile (generated): Correct typo.

1998-06-04  Philip Blundell  <philb@gnu.org>

	* elf/elf.h (EM_ARM, et al.): New definitions.
	* sysdeps/arm/dl-machine.h: Update for new draft ARM ELF ABI.
1998-06-09 15:16:55 +00:00

127 lines
3.3 KiB
C

/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
static const char sccsid[] = "@(#)db_shash.c 10.9 (Sleepycat) 4/10/98";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
#include "db_int.h"
#include "shqueue.h"
#include "common_ext.h"
/*
* Table of good hash values. Up to ~250,000 buckets, we use powers of 2.
* After that, we slow the rate of increase by half. For each choice, we
* then use a nearby prime number as the hash value.
*
* If a terabyte is the maximum cache we'll see, and we assume there are
* 10 1K buckets on each hash chain, then 107374182 is the maximum number
* of buckets we'll ever need.
*/
static const struct {
u_int32_t power;
u_int32_t prime;
} list[] = {
{ 64, 67}, /* 2^6 */
{ 128, 131}, /* 2^7 */
{ 256, 257}, /* 2^8 */
{ 512, 521}, /* 2^9 */
{ 1024, 1031}, /* 2^10 */
{ 2048, 2053}, /* 2^11 */
{ 4096, 4099}, /* 2^12 */
{ 8192, 8191}, /* 2^13 */
{ 16384, 16381}, /* 2^14 */
{ 32768, 32771}, /* 2^15 */
{ 65536, 65537}, /* 2^16 */
{ 131072, 131071}, /* 2^17 */
{ 262144, 262147}, /* 2^18 */
{ 393216, 393209}, /* 2^18 + 2^18/2 */
{ 524288, 524287}, /* 2^19 */
{ 786432, 786431}, /* 2^19 + 2^19/2 */
{ 1048576, 1048573}, /* 2^20 */
{ 1572864, 1572869}, /* 2^20 + 2^20/2 */
{ 2097152, 2097169}, /* 2^21 */
{ 3145728, 3145721}, /* 2^21 + 2^21/2 */
{ 4194304, 4194301}, /* 2^22 */
{ 6291456, 6291449}, /* 2^22 + 2^22/2 */
{ 8388608, 8388617}, /* 2^23 */
{ 12582912, 12582917}, /* 2^23 + 2^23/2 */
{ 16777216, 16777213}, /* 2^24 */
{ 25165824, 25165813}, /* 2^24 + 2^24/2 */
{ 33554432, 33554393}, /* 2^25 */
{ 50331648, 50331653}, /* 2^25 + 2^25/2 */
{ 67108864, 67108859}, /* 2^26 */
{ 100663296, 100663291}, /* 2^26 + 2^26/2 */
{ 134217728, 134217757}, /* 2^27 */
{ 201326592, 201326611}, /* 2^27 + 2^27/2 */
{ 268435456, 268435459}, /* 2^28 */
{ 402653184, 402653189}, /* 2^28 + 2^28/2 */
{ 536870912, 536870909}, /* 2^29 */
{ 805306368, 805306357}, /* 2^29 + 2^29/2 */
{1073741824, 1073741827}, /* 2^30 */
{0, 0}
};
/*
* __db_tablesize --
* Choose a size for the hash table.
*
* PUBLIC: int __db_tablesize __P((u_int32_t));
*/
int
__db_tablesize(n_buckets)
u_int32_t n_buckets;
{
int i;
/*
* We try to be clever about how big we make the hash tables. Use a
* prime number close to the "suggested" number of elements that will
* be in the hash table. Use 64 as the minimum hash table size.
*
* Ref: Sedgewick, Algorithms in C, "Hash Functions"
*/
if (n_buckets < 64)
n_buckets = 64;
for (i = 0;; ++i) {
if (list[i].power == 0) {
--i;
break;
}
if (list[i].power >= n_buckets)
break;
}
return (list[i].prime);
}
/*
* __db_hashinit --
* Initialize a hash table that resides in shared memory.
*
* PUBLIC: void __db_hashinit __P((void *, u_int32_t));
*/
void
__db_hashinit(begin, nelements)
void *begin;
u_int32_t nelements;
{
u_int32_t i;
SH_TAILQ_HEAD(hash_head) *headp;
headp = (struct hash_head *)begin;
for (i = 0; i < nelements; i++, headp++)
SH_TAILQ_INIT(headp);
}