]> git.ipfire.org Git - thirdparty/bash.git/blame - hashlib.h
allow some job notifications while running $PROMPT_COMMAND; allow notifications while...
[thirdparty/bash.git] / hashlib.h
CommitLineData
ccc6cda3 1/* hashlib.h -- the data structures used in hashing in Bash. */
726f6388 2
81e3a4fb 3/* Copyright (C) 1993-2022 Free Software Foundation, Inc.
726f6388
JA
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
2e4498b3
CR
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
726f6388 11
2e4498b3
CR
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
726f6388 16
2e4498b3
CR
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
19*/
726f6388 20
ccc6cda3
JA
21#if !defined (_HASHLIB_H_)
22#define _HASHLIB_H_
726f6388 23
bb70624e
JA
24#include "stdc.h"
25
7117c2d2 26#ifndef PTR_T
727e92c8 27# define PTR_T void *
7117c2d2
JA
28#endif
29
726f6388
JA
30typedef struct bucket_contents {
31 struct bucket_contents *next; /* Link to next hashed key in this bucket. */
32 char *key; /* What we look up. */
7117c2d2
JA
33 PTR_T data; /* What we really want. */
34 unsigned int khash; /* What key hashes to */
726f6388
JA
35 int times_found; /* Number of times this item has been found. */
36} BUCKET_CONTENTS;
37
38typedef struct hash_table {
39 BUCKET_CONTENTS **bucket_array; /* Where the data is kept. */
40 int nbuckets; /* How many buckets does this table have. */
41 int nentries; /* How many entries does this table have. */
42} HASH_TABLE;
43
81e3a4fb 44typedef int hash_wfunc (BUCKET_CONTENTS *);
7117c2d2
JA
45
46/* Operations on tables as a whole */
81e3a4fb
CR
47extern HASH_TABLE *hash_create (int);
48extern HASH_TABLE *hash_copy (HASH_TABLE *, sh_string_func_t *);
49extern void hash_flush (HASH_TABLE *, sh_free_func_t *);
50extern void hash_dispose (HASH_TABLE *);
51extern void hash_walk (HASH_TABLE *, hash_wfunc *);
7117c2d2
JA
52
53/* Operations to extract information from or pieces of tables */
81e3a4fb
CR
54extern int hash_bucket (const char *, HASH_TABLE *);
55extern int hash_size (HASH_TABLE *);
7117c2d2
JA
56
57/* Operations on hash table entries */
81e3a4fb
CR
58extern BUCKET_CONTENTS *hash_search (const char *, HASH_TABLE *, int);
59extern BUCKET_CONTENTS *hash_insert (char *, HASH_TABLE *, int);
60extern BUCKET_CONTENTS *hash_remove (const char *, HASH_TABLE *, int);
7117c2d2
JA
61
62/* Miscellaneous */
81e3a4fb 63extern unsigned int hash_string (const char *);
726f6388
JA
64
65/* Redefine the function as a macro for speed. */
7117c2d2 66#define hash_items(bucket, table) \
726f6388
JA
67 ((table && (bucket < table->nbuckets)) ? \
68 table->bucket_array[bucket] : \
69 (BUCKET_CONTENTS *)NULL)
70
71/* Default number of buckets in the hash table. */
09f70f2f 72#define DEFAULT_HASH_BUCKETS 128 /* must be power of two */
726f6388 73
f73dda09 74#define HASH_ENTRIES(ht) ((ht) ? (ht)->nentries : 0)
bb70624e 75
7117c2d2
JA
76/* flags for hash_search and hash_insert */
77#define HASH_NOSRCH 0x01
78#define HASH_CREATE 0x02
79
ccc6cda3 80#endif /* _HASHLIB_H */