chiark / gitweb /
Doxygen-clean
[disorder] / lib / hash.h
... / ...
CommitLineData
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2005-2008 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 3 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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU 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, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef HASH_H
20#define HASH_H
21
22typedef struct hash hash;
23struct kvp;
24
25hash *hash_new(size_t valuesize);
26/* Create a new hash */
27
28int hash_add(hash *h, const char *key, const void *value, int mode);
29#define HASH_INSERT 0
30#define HASH_REPLACE 1
31#define HASH_INSERT_OR_REPLACE 2
32/* Insert/replace a value in the hash. Returns 0 on success, -1 on
33 * error. */
34
35int hash_remove(hash *h, const char *key);
36/* Remove a value in the hash. Returns 0 on success, -1 on error. */
37
38void *hash_find(hash *h, const char *key);
39/* Find a value in the hash. Returns a null pointer if not found. */
40
41int hash_foreach(hash *h,
42 int (*callback)(const char *key, void *value, void *u),
43 void *u);
44/* Visit all the elements in a hash in any old order. It's safe to remove
45 * items from inside the callback including the visited one. It is not safe to
46 * add items from inside the callback however.
47 *
48 * If the callback ever returns non-0 then that value is immediately returned.
49 * Otherwise the return value is 0.
50 */
51
52size_t hash_count(hash *h);
53/* Return the number of items in the hash */
54
55char **hash_keys(hash *h);
56/* Return all the keys of H */
57
58#endif /* HASH_H */
59
60/*
61Local Variables:
62c-basic-offset:2
63comment-column:40
64fill-column:79
65indent-tabs-mode:nil
66End:
67*/