460b9539 |
1 | /* |
2 | * This file is part of DisOrder |
3 | * Copyright (C) 2005, 2006 Richard Kettlewell |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 | * USA |
19 | */ |
20 | |
21 | #ifndef HASH_H |
22 | #define HASH_H |
23 | |
24 | typedef struct hash hash; |
25 | |
26 | hash *hash_new(size_t valuesize); |
27 | /* Create a new hash */ |
28 | |
29 | int hash_add(hash *h, const char *key, const void *value, int mode); |
30 | #define HASH_INSERT 0 |
31 | #define HASH_REPLACE 1 |
32 | #define HASH_INSERT_OR_REPLACE 2 |
33 | /* Insert/replace a value in the hash. Returns 0 on success, -1 on |
34 | * error. */ |
35 | |
36 | int hash_remove(hash *h, const char *key); |
37 | /* Remove a value in the hash. Returns 0 on success, -1 on error. */ |
38 | |
39 | void *hash_find(hash *h, const char *key); |
40 | /* Find a value in the hash. Returns a null pointer if not found. */ |
41 | |
42 | int hash_foreach(hash *h, |
43 | int (*callback)(const char *key, void *value, void *u), |
44 | void *u); |
45 | /* Visit all the elements in a hash in any old order. It's safe to remove |
46 | * items from inside the callback including the visited one. It is not safe to |
47 | * add items from inside the callback however. |
48 | * |
49 | * If the callback ever returns non-0 then that value is immediately returned. |
50 | * Otherwise the return value is 0. |
51 | */ |
52 | |
53 | size_t hash_count(hash *h); |
54 | /* Return the number of items in the hash */ |
55 | |
56 | char **hash_keys(hash *h); |
57 | /* Return all the keys of H */ |
58 | |
59 | #endif /* HASH_H */ |
60 | |
61 | /* |
62 | Local Variables: |
63 | c-basic-offset:2 |
64 | comment-column:40 |
65 | fill-column:79 |
66 | indent-tabs-mode:nil |
67 | End: |
68 | */ |