fix segfault
[apps/madmutt.git] / hash.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 #ifndef _HASH_H
11 #define _HASH_H
12
13 struct hash_elem {
14     const char *key;
15     void *data;
16     struct hash_elem *next;
17 };
18
19 typedef struct {
20     int nelem, curnelem;
21     struct hash_elem **table;
22 } HASH;
23
24 #define hash_find(table, key) \
25     hash_find_hash(table, hash_string((unsigned char *)key, table->nelem), key)
26
27 #define hash_delete(table,key,data,destroy) \
28     hash_delete_hash(table, hash_string((unsigned char *)key, table->nelem), key, data, destroy)
29
30 HASH *hash_create(int nelem);
31 int hash_string(const unsigned char *s, int n);
32 int hash_insert(HASH * table, const char *key, void *data, int allow_dup);
33 HASH *hash_resize(HASH * table, int nelem);
34 void *hash_find_hash(const HASH *table, int hash, const char *key);
35 void hash_delete_hash(HASH * table, int hash, const char *key,
36                       const void *data, void (*destroy) (void *));
37 void hash_destroy(HASH ** hash, void (*destroy) (void *));
38
39 void hash_map(HASH* table,
40               void (*mapfunc) (const char* key, void* data, unsigned long more),
41               unsigned long more);
42
43 #endif