chiark / gitweb /
Move ENDIAN_ constants to new byte-order.h.
[disorder] / lib / hash.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder
5aff007d 3 * Copyright (C) 2005-2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
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 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
132a5a4a
RK
18/** @file lib/hash.h
19 * @brief A simple hash table
20 */
460b9539 21
22#ifndef HASH_H
23#define HASH_H
24
00682707
RK
25/** @brief Hash structure
26 *
27 * A hash table has string keys and byte blocks of fixed size as values.
28 */
460b9539 29typedef struct hash hash;
9faa7a88 30struct kvp;
460b9539 31
32hash *hash_new(size_t valuesize);
33/* Create a new hash */
34
35int hash_add(hash *h, const char *key, const void *value, int mode);
36#define HASH_INSERT 0
37#define HASH_REPLACE 1
38#define HASH_INSERT_OR_REPLACE 2
39/* Insert/replace a value in the hash. Returns 0 on success, -1 on
40 * error. */
41
42int hash_remove(hash *h, const char *key);
43/* Remove a value in the hash. Returns 0 on success, -1 on error. */
44
45void *hash_find(hash *h, const char *key);
46/* Find a value in the hash. Returns a null pointer if not found. */
47
48int hash_foreach(hash *h,
49 int (*callback)(const char *key, void *value, void *u),
50 void *u);
51/* Visit all the elements in a hash in any old order. It's safe to remove
52 * items from inside the callback including the visited one. It is not safe to
53 * add items from inside the callback however.
54 *
55 * If the callback ever returns non-0 then that value is immediately returned.
56 * Otherwise the return value is 0.
57 */
58
59size_t hash_count(hash *h);
60/* Return the number of items in the hash */
61
62char **hash_keys(hash *h);
63/* Return all the keys of H */
64
65#endif /* HASH_H */
66
67/*
68Local Variables:
69c-basic-offset:2
70comment-column:40
71fill-column:79
72indent-tabs-mode:nil
73End:
74*/