Imported from ../bash-1.14.7.tar.gz.
[platform/upstream/bash.git] / hashlib.h
1 /* hashlib.h -- the data structures used in hashing in Bash. */
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
19    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #if !defined (_HASHLIB_H_)
22 #define _HASHLIB_H_
23
24 typedef struct bucket_contents {
25   struct bucket_contents *next; /* Link to next hashed key in this bucket. */
26   char *key;                    /* What we look up. */
27   char *data;                   /* What we really want. */
28   int times_found;              /* Number of times this item has been found. */
29 } BUCKET_CONTENTS;
30
31 typedef struct hash_table {
32   BUCKET_CONTENTS **bucket_array;       /* Where the data is kept. */
33   int nbuckets;                 /* How many buckets does this table have. */
34   int nentries;                 /* How many entries does this table have. */
35 } HASH_TABLE;
36
37 extern int hash_string ();
38 extern HASH_TABLE *make_hash_table ();
39 extern BUCKET_CONTENTS *find_hash_item ();
40 extern BUCKET_CONTENTS *remove_hash_item ();
41 extern BUCKET_CONTENTS *add_hash_item ();
42 extern BUCKET_CONTENTS *get_hash_bucket ();
43 extern void flush_hash_table ();
44
45 /* Redefine the function as a macro for speed. */
46 #define get_hash_bucket(bucket, table) \
47         ((table && (bucket < table->nbuckets)) ?  \
48                 table->bucket_array[bucket] : \
49                 (BUCKET_CONTENTS *)NULL)
50
51 /* Default number of buckets in the hash table. */
52 #define DEFAULT_HASH_BUCKETS 107
53
54 #if !defined (NULL)
55 #  if defined (__STDC__)
56 #    define NULL ((void *) 0)
57 #  else
58 #    define NULL 0x0
59 #  endif /* !__STDC__ */
60 #endif /* !NULL */
61
62 #endif /* _HASHLIB_H */