replace hash.c; speedup/cleanup from Chris Torek
[unix-history] / usr / src / usr.bin / make / hash.h
CommitLineData
b0ff1758
KB
1/*
2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3 * Copyright (c) 1988, 1989 by Adam de Boor
4 * Copyright (c) 1989 by Berkeley Softworks
5 * All rights reserved.
fe902645 6 *
b0ff1758
KB
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
fe902645 9 *
87198c0c 10 * %sccs.include.redist.c%
fe902645 11 *
fc46faab 12 * @(#)hash.h 5.4 (Berkeley) %G%
fe902645
KB
13 */
14
b0ff1758
KB
15/* hash.h --
16 *
17 * This file contains definitions used by the hash module,
18 * which maintains hash tables.
19 */
fe902645
KB
20
21#ifndef _HASH
22#define _HASH
23
fe902645
KB
24/*
25 * The following defines one entry in the hash table.
26 */
27
28typedef struct Hash_Entry {
fc46faab 29 struct Hash_Entry *next; /* Used to link together all the
fe902645
KB
30 * entries associated with the same
31 * bucket. */
32 ClientData clientData; /* Arbitrary piece of data associated
33 * with key. */
fc46faab
KB
34 unsigned namehash; /* hash value of key */
35 char name[1]; /* key string */
fe902645
KB
36} Hash_Entry;
37
fe902645 38typedef struct Hash_Table {
fc46faab 39 struct Hash_Entry **bucketPtr;/* Pointers to Hash_Entry, one
fe902645
KB
40 * for each bucket in the table. */
41 int size; /* Actual size of array. */
42 int numEntries; /* Number of entries in the table. */
fe902645 43 int mask; /* Used to select bits for hashing. */
fe902645
KB
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
51typedef 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. */
fe902645
KB
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);
fc46faab 70 * Hash_Entry *h;
fe902645
KB
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/*
83 * The following procedure declarations and macros
84 * are the only things that should be needed outside
85 * the implementation code.
86 */
87
88extern Hash_Entry * Hash_CreateEntry();
89extern void Hash_DeleteTable();
90extern void Hash_DeleteEntry();
91extern void Hash_DeleteTable();
92extern Hash_Entry * Hash_EnumFirst();
93extern Hash_Entry * Hash_EnumNext();
94extern Hash_Entry * Hash_FindEntry();
95extern void Hash_InitTable();
96extern void Hash_PrintStats();
97
98#endif _HASH