1
1
/*-------------------------------------------------------------------------
2
2
*
3
3
* hsearch.h
4
- * for hashing in the new buffer manager
4
+ * for hash tables, particularly hash tables in shared memory
5
5
*
6
6
*
7
7
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $Id: hsearch.h,v 1.13 2000/01 /26 05:58:38 momjian Exp $
10
+ * $Id: hsearch.h,v 1.14 2000/02 /26 05:25:53 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
25
25
* whole lot of records per bucket or performance goes down.
26
26
*
27
27
* In a hash table allocated in shared memory, the directory cannot be
28
- * expanded because it must stay at a fixed address.
28
+ * expanded because it must stay at a fixed address. The directory size
29
+ * should be selected using hash_select_dirsize (and you'd better have
30
+ * a good idea of the maximum number of entries!). For non-shared hash
31
+ * tables, the initial directory size can be left at the default.
29
32
*/
30
33
#define DEF_SEGSIZE 256
31
- #define DEF_SEGSIZE_SHIFT 8/* log2(SEGSIZE) */
34
+ #define DEF_SEGSIZE_SHIFT 8 /* must be log2(DEF_SEGSIZE) */
32
35
#define DEF_DIRSIZE 256
33
- #define DEF_FFACTOR 1/* default fill factor */
36
+ #define DEF_FFACTOR 1 /* default fill factor */
34
37
35
38
#define PRIME1 37 /* for the hash function */
36
39
#define PRIME2 1048583
42
45
*/
43
46
typedef struct element
44
47
{
45
- unsigned long next ; /* secret from user */
48
+ unsigned long next ; /* secret from user */
46
49
long key ;
47
50
} ELEMENT ;
48
51
49
52
typedef unsigned long BUCKET_INDEX ;
50
53
51
- /* segment is an array of bucket pointers */
54
+ /* segment is an array of bucket pointers */
52
55
typedef BUCKET_INDEX * SEGMENT ;
53
56
typedef unsigned long SEG_OFFSET ;
54
57
@@ -65,10 +68,8 @@ typedef struct hashhdr
65
68
long nsegs ; /* Number of allocated segments */
66
69
long keysize ; /* hash key length in bytes */
67
70
long datasize ; /* elem data length in bytes */
68
- long max_dsize ; /* 'dsize' limit if directory is fixed
69
- * size */
70
- BUCKET_INDEX freeBucketIndex ;
71
- /* index of first free bucket */
71
+ long max_dsize ; /* 'dsize' limit if directory is fixed size */
72
+ BUCKET_INDEX freeBucketIndex ; /* index of first free bucket */
72
73
#ifdef HASH_STATISTICS
73
74
long accesses ;
74
75
long collisions ;
@@ -84,7 +85,6 @@ typedef struct htab
84
85
SEG_OFFSET * dir ; /* 'directory' of segm starts */
85
86
long * (* alloc ) (); /* memory allocator (long * for alignment
86
87
* reasons) */
87
-
88
88
} HTAB ;
89
89
90
90
typedef struct hashctl
@@ -115,7 +115,7 @@ typedef struct hashctl
115
115
#define HASH_ALLOC 0x100 /* Setting memory allocator */
116
116
117
117
118
- /* seg_alloc assumes that INVALID_INDEX is 0*/
118
+ /* seg_alloc assumes that INVALID_INDEX is 0 */
119
119
#define INVALID_INDEX (0)
120
120
#define NO_MAX_DSIZE (-1)
121
121
/* number of hash buckets allocated at once */
@@ -141,6 +141,7 @@ extern long *hash_search(HTAB *hashp, char *keyPtr, HASHACTION action,
141
141
bool * foundPtr );
142
142
extern long * hash_seq (HTAB * hashp );
143
143
extern long hash_estimate_size (long num_entries , long keysize , long datasize );
144
+ extern long hash_select_dirsize (long num_entries );
144
145
145
146
/*
146
147
* prototypes from functions in hashfn.c
0 commit comments