2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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 #include "telescope.h"
21 static void *hash_alloc(size_t, void*);
22 static void *hash_calloc(size_t, size_t, void*);
23 static void hash_free(void*, void*);
26 hash_alloc(size_t len, void *d)
28 if ((d = malloc(len)) == NULL)
34 hash_calloc(size_t nmemb, size_t size, void *d)
36 if ((d = calloc(nmemb, size)) == NULL)
42 hash_free(void *ptr, void *d)
48 telescope_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
50 struct ohash_info info = {
52 .calloc = hash_calloc,
57 ohash_init(h, sz, &info);
61 telescope_lookup_tofu(struct ohash *h, const char *domain)
65 slot = ohash_qlookup(h, domain);
66 return ohash_find(h, slot);
70 telescope_ohash_insert(struct ohash *h, struct tofu_entry *e)
74 slot = ohash_qlookup(h, e->domain);
75 ohash_insert(h, slot, e);