| 1 |
/* hash.h: declarations for a hash table. |
| 2 |
|
| 3 |
Copyright 1994, 1995, 2008, 2010-2012 Karl Berry. |
| 4 |
Copyright 1999, 2005 Olaf Weber. |
| 5 |
|
| 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. |
| 10 |
|
| 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. |
| 15 |
|
| 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/>. */ |
| 18 |
|
| 19 |
#ifndef HASH_H |
| 20 |
#define HASH_H |
| 21 |
|
| 22 |
#include <kpathsea/c-proto.h> |
| 23 |
#include <kpathsea/types.h> |
| 24 |
|
| 25 |
/* |
| 26 |
* The code freeing strings and hash tables is enabled/disabled |
| 27 |
* by KPATHSEA_CAN_FREE. |
| 28 |
*/ |
| 29 |
/* At the moment can not free */ |
| 30 |
#define KPATHSEA_CAN_FREE 0 |
| 31 |
|
| 32 |
#ifdef __cplusplus |
| 33 |
extern "C" { |
| 34 |
#endif |
| 35 |
|
| 36 |
/* A single (key,value) pair. */ |
| 37 |
typedef struct hash_element_struct |
| 38 |
{ |
| 39 |
const_string key; |
| 40 |
const_string value; |
| 41 |
struct hash_element_struct *next; |
| 42 |
} hash_element_type; |
| 43 |
|
| 44 |
/* The usual arrangement of buckets initialized to null. */ |
| 45 |
typedef struct |
| 46 |
{ |
| 47 |
hash_element_type **buckets; |
| 48 |
unsigned size; |
| 49 |
} hash_table_type; |
| 50 |
|
| 51 |
|
| 52 |
/* Create a hash table of size SIZE. */ |
| 53 |
extern KPSEDLL hash_table_type hash_create (unsigned size); |
| 54 |
|
| 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); |
| 60 |
|
| 61 |
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */ |
| 62 |
|
| 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); |
| 69 |
|
| 70 |
#endif /* MAKE_KPSE_DLL */ |
| 71 |
|
| 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); |
| 75 |
|
| 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); |
| 79 |
|
| 80 |
#ifdef MAKE_KPSE_DLL /* libkpathsea internal only */ |
| 81 |
|
| 82 |
/* Print TABLE to stderr. */ |
| 83 |
extern void hash_print (hash_table_type table, boolean summary_only); |
| 84 |
|
| 85 |
#if KPATHSEA_CAN_FREE |
| 86 |
/* Drop the TABLE */ |
| 87 |
extern void hash_free (hash_table_type table); |
| 88 |
#endif |
| 89 |
|
| 90 |
#endif /* MAKE_KPSE_DLL */ |
| 91 |
|
| 92 |
#ifdef __cplusplus |
| 93 |
} |
| 94 |
#endif |
| 95 |
|
| 96 |
#endif /* not HASH_H */ |