1 /* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)hash.h 8.2 (Berkeley) 04/28/95 13 */ 14 15 /* hash.h -- 16 * 17 * This file contains definitions used by the hash module, 18 * which maintains hash tables. 19 */ 20 21 #ifndef _HASH 22 #define _HASH 23 24 /* 25 * The following defines one entry in the hash table. 26 */ 27 28 typedef struct Hash_Entry { 29 struct Hash_Entry *next; /* Used to link together all the 30 * entries associated with the same 31 * bucket. */ 32 ClientData clientData; /* Arbitrary piece of data associated 33 * with key. */ 34 unsigned namehash; /* hash value of key */ 35 char name[1]; /* key string */ 36 } Hash_Entry; 37 38 typedef struct Hash_Table { 39 struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one 40 * for each bucket in the table. */ 41 int size; /* Actual size of array. */ 42 int numEntries; /* Number of entries in the table. */ 43 int mask; /* Used to select bits for hashing. */ 44 } Hash_Table; 45 46 /* 47 * The following structure is used by the searching routines 48 * to record where we are in the search. 49 */ 50 51 typedef struct Hash_Search { 52 Hash_Table *tablePtr; /* Table being searched. */ 53 int nextIndex; /* Next bucket to check (after current). */ 54 Hash_Entry *hashEntryPtr; /* Next entry to check in current bucket. */ 55 } Hash_Search; 56 57 /* 58 * Macros. 59 */ 60 61 /* 62 * ClientData Hash_GetValue(h) 63 * Hash_Entry *h; 64 */ 65 66 #define Hash_GetValue(h) ((h)->clientData) 67 68 /* 69 * Hash_SetValue(h, val); 70 * Hash_Entry *h; 71 * char *val; 72 */ 73 74 #define Hash_SetValue(h, val) ((h)->clientData = (ClientData) (val)) 75 76 /* 77 * Hash_Size(n) returns the number of words in an object of n bytes 78 */ 79 80 #define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int)) 81 82 void Hash_InitTable __P((Hash_Table *, int)); 83 void Hash_DeleteTable __P((Hash_Table *)); 84 Hash_Entry *Hash_FindEntry __P((Hash_Table *, char *)); 85 Hash_Entry *Hash_CreateEntry __P((Hash_Table *, char *, Boolean *)); 86 void Hash_DeleteEntry __P((Hash_Table *, Hash_Entry *)); 87 Hash_Entry *Hash_EnumFirst __P((Hash_Table *, Hash_Search *)); 88 Hash_Entry *Hash_EnumNext __P((Hash_Search *)); 89 90 #endif /* _HASH */ 91