]>
Commit | Line | Data |
---|---|---|
ccc6cda3 | 1 | /* hashlib.h -- the data structures used in hashing in Bash. */ |
726f6388 JA |
2 | |
3 | /* Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GNU Bash, the Bourne Again SHell. | |
6 | ||
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 | |
10 | version. | |
11 | ||
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 | |
15 | for more details. | |
16 | ||
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 | |
bb70624e | 19 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ |
726f6388 | 20 | |
ccc6cda3 JA |
21 | #if !defined (_HASHLIB_H_) |
22 | #define _HASHLIB_H_ | |
726f6388 | 23 | |
bb70624e JA |
24 | #include "stdc.h" |
25 | ||
726f6388 JA |
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. */ | |
31 | } BUCKET_CONTENTS; | |
32 | ||
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. */ | |
37 | } HASH_TABLE; | |
38 | ||
f73dda09 JA |
39 | extern int hash_string __P((const char *, HASH_TABLE *)); |
40 | extern int hash_table_nentries __P((HASH_TABLE *)); | |
bb70624e | 41 | extern HASH_TABLE *make_hash_table __P((int)); |
f73dda09 JA |
42 | extern HASH_TABLE *copy_hash_table __P((HASH_TABLE *, sh_string_func_t *)); |
43 | extern BUCKET_CONTENTS *find_hash_item __P((const char *, HASH_TABLE *)); | |
44 | extern BUCKET_CONTENTS *remove_hash_item __P((const char *, HASH_TABLE *)); | |
bb70624e | 45 | extern BUCKET_CONTENTS *add_hash_item __P((char *, HASH_TABLE *)); |
f73dda09 | 46 | extern void flush_hash_table __P((HASH_TABLE *, sh_free_func_t *)); |
bb70624e | 47 | extern void dispose_hash_table __P((HASH_TABLE *)); |
726f6388 JA |
48 | |
49 | /* Redefine the function as a macro for speed. */ | |
50 | #define get_hash_bucket(bucket, table) \ | |
51 | ((table && (bucket < table->nbuckets)) ? \ | |
52 | table->bucket_array[bucket] : \ | |
53 | (BUCKET_CONTENTS *)NULL) | |
54 | ||
55 | /* Default number of buckets in the hash table. */ | |
d166f048 | 56 | #define DEFAULT_HASH_BUCKETS 53 /* was 107 */ |
726f6388 | 57 | |
f73dda09 | 58 | #define HASH_ENTRIES(ht) ((ht) ? (ht)->nentries : 0) |
bb70624e | 59 | |
726f6388 JA |
60 | #if !defined (NULL) |
61 | # if defined (__STDC__) | |
62 | # define NULL ((void *) 0) | |
63 | # else | |
64 | # define NULL 0x0 | |
65 | # endif /* !__STDC__ */ | |
66 | #endif /* !NULL */ | |
67 | ||
ccc6cda3 | 68 | #endif /* _HASHLIB_H */ |