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 unsigned int strdup_keys : 1; /* if set, the key->strkey is strdup'ed */
39 unsigned int allow_dups : 1; /* if set, duplicate keys are allowed */
40 struct hash_elem **table;
41 unsigned int (*gen_hash)(union hash_key, unsigned int);
42 int (*cmp_key)(union hash_key, union hash_key);
43}
44HASH;
45
46/* flags for hash_create() */
47#define MUTT_HASH_STRCASECMP (1<<0) /* use strcasecmp() to compare keys */
48#define MUTT_HASH_STRDUP_KEYS (1<<1) /* make a copy of the keys */
49#define MUTT_HASH_ALLOW_DUPS (1<<2) /* allow duplicate keys to be inserted */
50
51HASH *hash_create (int nelem, int flags);
52HASH *int_hash_create (int nelem, int flags);
53
54int hash_insert (HASH * table, const char *key, void *data);
55int int_hash_insert (HASH *table, unsigned int key, void *data);
56
57void *hash_find (const HASH *table, const char *key);
58struct hash_elem *hash_find_elem (const HASH *table, const char *strkey);
59void *int_hash_find (const HASH *table, unsigned int key);
60
61struct hash_elem *hash_find_bucket (const HASH *table, const char *key);
62
63void hash_delete (HASH * table, const char *key, const void *data,
64 void (*destroy) (void *));
65void int_hash_delete (HASH * table, unsigned int key, const void *data,
66 void (*destroy) (void *));
67
68void hash_destroy (HASH ** hash, void (*destroy) (void *));
69
70struct hash_walk_state {
71 int index;
72 struct hash_elem *last;
73};
74
75struct hash_elem *hash_walk(const HASH *table, struct hash_walk_state *state);
76
77#endif