mutt stable branch with some hacks
1/*
2 * Copyright (C) 1996-2009 Michael R. Elkins <me@mutt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef _HASH_H
20#define _HASH_H
21
22union hash_key
23{
24 const char *strkey;
25 unsigned int intkey;
26};
27
28struct hash_elem
29{
30 union hash_key key;
31 void *data;
32 struct hash_elem *next;
33};
34
35typedef struct
36{
37 int nelem;
38 struct hash_elem **table;
39 unsigned int (*gen_hash)(union hash_key, unsigned int);
40 int (*cmp_key)(union hash_key, union hash_key);
41}
42HASH;
43
44HASH *hash_create (int nelem, int lower);
45HASH *int_hash_create (int nelem);
46
47int hash_insert (HASH * table, const char *key, void *data, int allow_dup);
48int int_hash_insert (HASH *table, unsigned int key, void *data, int allow_dup);
49
50void *hash_find (const HASH *table, const char *key);
51void *int_hash_find (const HASH *table, unsigned int key);
52
53struct hash_elem *hash_find_bucket (const HASH *table, const char *key);
54
55void hash_delete (HASH * table, const char *key, const void *data,
56 void (*destroy) (void *));
57void int_hash_delete (HASH * table, unsigned int key, const void *data,
58 void (*destroy) (void *));
59
60void hash_destroy (HASH ** hash, void (*destroy) (void *));
61
62#endif