add a Makefile for gnu make
[hashtab.git] / hashtab.h
blob6397d7e50d08414df98002a27f34468d5038b937
1 /*
2 * Copyright (c) 2015 Mohamed Aslan <maslan@sce.carleton.ca>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef HASHTAB_H
18 #define HASHTAB_H
20 #include <stdint.h>
22 #define HTMIN 4
23 #define HTMAX 24
25 struct hashtab {
26 struct hashtab_kv *kv;
27 size_t size;
28 uint32_t (*hash) (void *, size_t);
31 struct hashtab_options;
33 int hashtab_init(struct hashtab *, uint8_t, struct hashtab_options *);
34 int hashtab_put(struct hashtab *, void *, size_t, void *, size_t);
35 int hashtab_get(struct hashtab *, void *, size_t, void **, size_t *);
36 int hashtab_del(struct hashtab *, void *, size_t);
37 int hashtab_first(struct hashtab *, size_t *);
38 int hashtab_next(struct hashtab *, size_t *);
39 int hashtab_at(struct hashtab *, size_t, void **, size_t *, void **, size_t *);
41 #define HASHTAB_FOREACH(ht, itr, key, ksize, val, vsize) \
42 for (hashtab_first(&(ht), &(itr)) ; \
43 hashtab_at(&(ht), (itr), (void *)&(key), &(ksize), \
44 (void *)&(val), &(vsize)) ; \
45 hashtab_next(&(ht), &(itr)) \
48 #endif