beta-0.89.2
[luatex.git] / source / texk / kpathsea / hash.h
blobf54cd0fd64664ded2ed45764b40e856f97e2be72
1 /* hash.h: declarations for a hash table.
3 Copyright 1994, 1995, 2008, 2010-2012 Karl Berry.
4 Copyright 1999, 2005 Olaf Weber.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19 #ifndef HASH_H
20 #define HASH_H
22 #include <kpathsea/c-proto.h>
23 #include <kpathsea/types.h>
26 * The code freeing strings and hash tables is enabled/disabled
27 * by KPATHSEA_CAN_FREE.
29 /* At the moment can not free */
30 #define KPATHSEA_CAN_FREE 0
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 /* A single (key,value) pair. */
37 typedef struct hash_element_struct
39 const_string key;
40 const_string value;
41 struct hash_element_struct *next;
42 } hash_element_type;
44 /* The usual arrangement of buckets initialized to null. */
45 typedef struct
47 hash_element_type **buckets;
48 unsigned size;
49 } hash_table_type;
52 /* Create a hash table of size SIZE. */
53 extern KPSEDLL hash_table_type hash_create (unsigned size);
55 /* Insert the (KEY,VALUE) association into TABLE. KEY may have more
56 than one VALUE. Neither KEY nor VALUE is copied. */
57 extern KPSEDLL void hash_insert (hash_table_type *table,
58 const_string key,
59 const_string value);
61 #ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
63 /* Insert the (KEY, VALUE) association into TABLE. KEY may have more
64 than one VALUE. Neither KEY nor VALUE is copied. Assume that KEY
65 is already normalized (all lowercase) on platforms where this matters. */
66 extern void hash_insert_normalized (hash_table_type *table,
67 const_string key,
68 const_string value);
70 #endif /* MAKE_KPSE_DLL */
72 /* Remove the (KEY,VALUE) association from TABLE. */
73 extern KPSEDLL void hash_remove (hash_table_type *table, const_string key,
74 const_string value);
76 /* Look up KEY in TABLE, and return NULL-terminated list of all matching
77 values (not copies), in insertion order. If none, return NULL. */
78 extern KPSEDLL const_string *hash_lookup (hash_table_type table, const_string key);
80 #ifdef MAKE_KPSE_DLL /* libkpathsea internal only */
82 /* Print TABLE to stderr. */
83 extern void hash_print (hash_table_type table, boolean summary_only);
85 #if KPATHSEA_CAN_FREE
86 /* Drop the TABLE */
87 extern void hash_free (hash_table_type table);
88 #endif
90 #endif /* MAKE_KPSE_DLL */
92 #ifdef __cplusplus
94 #endif
96 #endif /* not HASH_H */