1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* hsearch.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* for hashing in the new buffer manager
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* $Id: hsearch.h,v 1.13 2000/01/26 05:58:38 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef HSEARCH_H
|
|
|
|
#define HSEARCH_H
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants
|
1999-02-22 07:16:57 +01:00
|
|
|
*
|
|
|
|
* A hash table has a top-level "directory", each of whose entries points
|
1999-05-25 18:15:34 +02:00
|
|
|
* to a "segment" of ssize bucket headers. The maximum number of hash
|
1999-02-22 07:16:57 +01:00
|
|
|
* buckets is thus dsize * ssize (but dsize may be expansible). Of course,
|
|
|
|
* the number of records in the table can be larger, but we don't want a
|
|
|
|
* whole lot of records per bucket or performance goes down.
|
|
|
|
*
|
|
|
|
* In a hash table allocated in shared memory, the directory cannot be
|
|
|
|
* expanded because it must stay at a fixed address.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define DEF_SEGSIZE 256
|
1999-05-25 18:15:34 +02:00
|
|
|
#define DEF_SEGSIZE_SHIFT 8/* log2(SEGSIZE) */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define DEF_DIRSIZE 256
|
1999-05-25 18:15:34 +02:00
|
|
|
#define DEF_FFACTOR 1/* default fill factor */
|
1999-02-22 07:16:57 +01:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
#define PRIME1 37 /* for the hash function */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PRIME2 1048583
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hash bucket is actually bigger than this. Key field can have
|
|
|
|
* variable length and a variable length data field follows it.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct element
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
unsigned long next; /* secret from user */
|
|
|
|
long key;
|
1997-09-08 23:56:23 +02:00
|
|
|
} ELEMENT;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
typedef unsigned long BUCKET_INDEX;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* segment is an array of bucket pointers */
|
|
|
|
typedef BUCKET_INDEX *SEGMENT;
|
|
|
|
typedef unsigned long SEG_OFFSET;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct hashhdr
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
long dsize; /* Directory Size */
|
1999-02-22 07:16:57 +01:00
|
|
|
long ssize; /* Segment Size --- must be power of 2 */
|
1997-09-08 04:41:22 +02:00
|
|
|
long sshift; /* Segment shift */
|
|
|
|
long max_bucket; /* ID of Maximum bucket in use */
|
|
|
|
long high_mask; /* Mask to modulo into entire table */
|
|
|
|
long low_mask; /* Mask to modulo into lower half of table */
|
|
|
|
long ffactor; /* Fill factor */
|
|
|
|
long nkeys; /* Number of keys in hash table */
|
|
|
|
long nsegs; /* Number of allocated segments */
|
|
|
|
long keysize; /* hash key length in bytes */
|
|
|
|
long datasize; /* elem data length in bytes */
|
1999-05-25 18:15:34 +02:00
|
|
|
long max_dsize; /* 'dsize' limit if directory is fixed
|
|
|
|
* size */
|
1997-09-08 04:41:22 +02:00
|
|
|
BUCKET_INDEX freeBucketIndex;
|
1997-09-07 07:04:48 +02:00
|
|
|
/* index of first free bucket */
|
1996-08-28 03:59:28 +02:00
|
|
|
#ifdef HASH_STATISTICS
|
1997-09-08 04:41:22 +02:00
|
|
|
long accesses;
|
|
|
|
long collisions;
|
1996-08-28 03:59:28 +02:00
|
|
|
#endif
|
1997-09-08 23:56:23 +02:00
|
|
|
} HHDR;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct htab
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HHDR *hctl; /* shared control information */
|
|
|
|
long (*hash) (); /* Hash Function */
|
|
|
|
char *segbase; /* segment base address for calculating
|
1997-09-07 07:04:48 +02:00
|
|
|
* pointer values */
|
1997-09-08 04:41:22 +02:00
|
|
|
SEG_OFFSET *dir; /* 'directory' of segm starts */
|
|
|
|
long *(*alloc) (); /* memory allocator (long * for alignment
|
1997-09-07 07:04:48 +02:00
|
|
|
* reasons) */
|
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
} HTAB;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct hashctl
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
long ssize; /* Segment Size */
|
|
|
|
long dsize; /* Dirsize Size */
|
|
|
|
long ffactor; /* Fill factor */
|
|
|
|
long (*hash) (); /* Hash Function */
|
|
|
|
long keysize; /* hash key length in bytes */
|
|
|
|
long datasize; /* elem data length in bytes */
|
1999-02-22 07:16:57 +01:00
|
|
|
long max_dsize; /* limit to dsize if directory size is
|
1997-09-07 07:04:48 +02:00
|
|
|
* limited */
|
1997-09-08 04:41:22 +02:00
|
|
|
long *segbase; /* base for calculating bucket + seg ptrs */
|
|
|
|
long *(*alloc) (); /* memory allocation function */
|
|
|
|
long *dir; /* directory if allocated already */
|
|
|
|
long *hctl; /* location of header information in shd
|
1997-09-07 07:04:48 +02:00
|
|
|
* mem */
|
1997-09-08 23:56:23 +02:00
|
|
|
} HASHCTL;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* Flags to indicate action for hctl */
|
|
|
|
#define HASH_SEGMENT 0x002 /* Setting segment size */
|
|
|
|
#define HASH_DIRSIZE 0x004 /* Setting directory size */
|
|
|
|
#define HASH_FFACTOR 0x008 /* Setting fill factor */
|
|
|
|
#define HASH_FUNCTION 0x010 /* Set user defined hash function */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define HASH_ELEM 0x020 /* Setting key/data size */
|
|
|
|
#define HASH_SHARED_MEM 0x040 /* Setting shared mem const */
|
|
|
|
#define HASH_ATTACH 0x080 /* Do not initialize hctl */
|
|
|
|
#define HASH_ALLOC 0x100 /* Setting memory allocator */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* seg_alloc assumes that INVALID_INDEX is 0*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define INVALID_INDEX (0)
|
|
|
|
#define NO_MAX_DSIZE (-1)
|
1996-08-28 03:59:28 +02:00
|
|
|
/* number of hash buckets allocated at once */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define BUCKET_ALLOC_INCR (30)
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* hash_search operations */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
HASH_FIND,
|
|
|
|
HASH_ENTER,
|
|
|
|
HASH_REMOVE,
|
|
|
|
HASH_FIND_SAVE,
|
|
|
|
HASH_REMOVE_SAVED
|
1997-09-08 23:56:23 +02:00
|
|
|
} HASHACTION;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* prototypes from functions in dynahash.c
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern HTAB *hash_create(int nelem, HASHCTL *info, int flags);
|
|
|
|
extern void hash_destroy(HTAB *hashp);
|
|
|
|
extern void hash_stats(char *where, HTAB *hashp);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern long *hash_search(HTAB *hashp, char *keyPtr, HASHACTION action,
|
1997-09-08 23:56:23 +02:00
|
|
|
bool *foundPtr);
|
|
|
|
extern long *hash_seq(HTAB *hashp);
|
1999-02-22 07:16:57 +01:00
|
|
|
extern long hash_estimate_size(long num_entries, long keysize, long datasize);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
1996-08-28 03:59:28 +02:00
|
|
|
* prototypes from functions in hashfn.c
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
extern long string_hash(char *key, int keysize);
|
|
|
|
extern long tag_hash(int *key, int keysize);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* HSEARCH_H */
|