1 /* hashlib.h -- the data structures used in hashing in Bash. */
3 /* Copyright (C) 1993 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21 #if !defined (_HASHLIB_H_)
26 typedef struct bucket_contents {
27 struct bucket_contents *next; /* Link to next hashed key in this bucket. */
28 char *key; /* What we look up. */
29 char *data; /* What we really want. */
30 int times_found; /* Number of times this item has been found. */
33 typedef struct hash_table {
34 BUCKET_CONTENTS **bucket_array; /* Where the data is kept. */
35 int nbuckets; /* How many buckets does this table have. */
36 int nentries; /* How many entries does this table have. */
39 extern int hash_string __P((char *, HASH_TABLE *));
40 extern HASH_TABLE *make_hash_table __P((int));
41 extern BUCKET_CONTENTS *find_hash_item __P((char *, HASH_TABLE *));
42 extern BUCKET_CONTENTS *remove_hash_item __P((char *, HASH_TABLE *));
43 extern BUCKET_CONTENTS *add_hash_item __P((char *, HASH_TABLE *));
44 extern void flush_hash_table __P((HASH_TABLE *, VFunction *));
45 extern void dispose_hash_table __P((HASH_TABLE *));
47 /* Redefine the function as a macro for speed. */
48 #define get_hash_bucket(bucket, table) \
49 ((table && (bucket < table->nbuckets)) ? \
50 table->bucket_array[bucket] : \
51 (BUCKET_CONTENTS *)NULL)
53 /* Default number of buckets in the hash table. */
54 #define DEFAULT_HASH_BUCKETS 53 /* was 107 */
56 #define HASH_ENTRIES(ht) (ht)->nentries
59 # if defined (__STDC__)
60 # define NULL ((void *) 0)
63 # endif /* !__STDC__ */
66 #endif /* _HASHLIB_H */