2 * Copyright (C) 1996-2009 Michael R. Elkins <me@mutt.org>
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.
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.
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.
32 struct hash_elem *next;
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);
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 */
51 HASH *hash_create (int nelem, int flags);
52 HASH *int_hash_create (int nelem, int flags);
54 int hash_insert (HASH * table, const char *key, void *data);
55 int int_hash_insert (HASH *table, unsigned int key, void *data);
57 void *hash_find (const HASH *table, const char *key);
58 struct hash_elem *hash_find_elem (const HASH *table, const char *strkey);
59 void *int_hash_find (const HASH *table, unsigned int key);
61 struct hash_elem *hash_find_bucket (const HASH *table, const char *key);
63 void hash_delete (HASH * table, const char *key, const void *data,
64 void (*destroy) (void *));
65 void int_hash_delete (HASH * table, unsigned int key, const void *data,
66 void (*destroy) (void *));
68 void hash_destroy (HASH ** hash, void (*destroy) (void *));
70 struct hash_walk_state {
72 struct hash_elem *last;
75 struct hash_elem *hash_walk(const HASH *table, struct hash_walk_state *state);