hash.h
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* hash.h --
*
* This file contains definitions used by the hash module,
* which maintains hash tables.
*
* Copyright 1986, 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*
* $Header: /root/leakn64/depot/rf/sw/bbplayer/simos/apps/unix/ethersim/sun/hash.h,v 1.1.1.1 2002/05/29 01:09:09 blythe Exp $ SPRITE (Berkeley)
*/
#ifndef _HASH
#define _HASH
#ifndef _LIST
#include <list.h>
#endif
#ifndef _SPRITE
#include <sprite.h>
#endif
/*
* The following defines one entry in the hash table.
*/
typedef struct Hash_Entry {
List_Links links; /* Used to link together all the
* entries associated with the same
* bucket. */
ClientData clientData; /* Arbitrary piece of data associated
* with key. */
union {
Address ptr; /* One-word key value to identify
* entry. */
int words[1]; /* N-word key value. Note: the actual
* size may be longer if necessary to
* hold the entire key. */
char name[4]; /* Text name of this entry. Note: the
* actual size may be longer if
* necessary to hold the whole string.
* This MUST be the last entry in the
* structure!!! */
} key;
} Hash_Entry;
/*
* A hash table consists of an array of pointers to hash
* lists. Tables can be organized in either of three ways, depending
* on the type of comparison keys:
*
* Strings: these are NULL-terminated; their address
* is passed to HashFind as a (char *).
* Single-word keys: these may be anything, but must be passed
* to Hash_Find as an Address.
* Multi-word keys: these may also be anything; their address
* is passed to HashFind as an Address.
*
* Single-word keys are fastest, but most restrictive.
*/
#define HASH_STRING_KEYS 0
#define HASH_ONE_WORD_KEYS 1
typedef struct Hash_Table {
List_Links *bucketPtr; /* Pointer to array of List_Links, one
* for each bucket in the table. */
int size; /* Actual size of array. */
int numEntries; /* Number of entries in the table. */
int downShift; /* Shift count, used in hashing function. */
int mask; /* Used to select bits for hashing. */
int keyType; /* Type of keys used in table:
* HASH_STRING_KEYS, HASH_ONE-WORD_KEYS,
* or >1 menas keyType gives number of words
* in keys.
*/
} Hash_Table;
/*
* The following structure is used by the searching routines
* to record where we are in the search.
*/
typedef struct Hash_Search {
Hash_Table *tablePtr; /* Table being searched. */
int nextIndex; /* Next bucket to check (after current). */
Hash_Entry *hashEntryPtr; /* Next entry to check in current bucket. */
List_Links *hashList; /* Hash chain currently being checked. */
} Hash_Search;
/*
* Macros.
*/
/*
* ClientData Hash_GetValue(h)
* Hash_Entry *h;
*/
#define Hash_GetValue(h) ((h)->clientData)
/*
* Hash_SetValue(h, val);
* HashEntry *h;
* char *val;
*/
#define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val))
/*
* Hash_Size(n) returns the number of words in an object of n bytes
*/
#define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int))
/*
* The following procedure declarations and macros
* are the only things that should be needed outside
* the implementation code.
*/
extern Hash_Entry * Hash_CreateEntry();
extern void Hash_DeleteTable();
extern void Hash_DeleteEntry();
extern void Hash_DeleteTable();
extern Hash_Entry * Hash_EnumFirst();
extern Hash_Entry * Hash_EnumNext();
extern Hash_Entry * Hash_FindEntry();
extern void Hash_InitTable();
extern void Hash_PrintStats();
#endif /* _HASH */