2 cbcc75fb 2021-03-17 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 cbcc75fb 2021-03-17 op * Permission to use, copy, modify, and distribute this software for any
5 cbcc75fb 2021-03-17 op * purpose with or without fee is hereby granted, provided that the above
6 cbcc75fb 2021-03-17 op * copyright notice and this permission notice appear in all copies.
8 cbcc75fb 2021-03-17 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 cbcc75fb 2021-03-17 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 cbcc75fb 2021-03-17 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 cbcc75fb 2021-03-17 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 cbcc75fb 2021-03-17 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 cbcc75fb 2021-03-17 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 cbcc75fb 2021-03-17 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 cbcc75fb 2021-03-17 op #include "telescope.h"
19 cbcc75fb 2021-03-17 op #include <stdlib.h>
21 cbcc75fb 2021-03-17 op static void *hash_alloc(size_t, void*);
22 cbcc75fb 2021-03-17 op static void *hash_calloc(size_t, size_t, void*);
23 cbcc75fb 2021-03-17 op static void hash_free(void*, void*);
26 cbcc75fb 2021-03-17 op hash_alloc(size_t len, void *d)
28 cbcc75fb 2021-03-17 op if ((d = malloc(len)) == NULL)
34 cbcc75fb 2021-03-17 op hash_calloc(size_t nmemb, size_t size, void *d)
36 cbcc75fb 2021-03-17 op if ((d = calloc(nmemb, size)) == NULL)
42 cbcc75fb 2021-03-17 op hash_free(void *ptr, void *d)
48 cbcc75fb 2021-03-17 op telescope_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
50 cbcc75fb 2021-03-17 op struct ohash_info info = {
51 cbcc75fb 2021-03-17 op .key_offset = ko,
52 cbcc75fb 2021-03-17 op .calloc = hash_calloc,
53 cbcc75fb 2021-03-17 op .free = hash_free,
54 cbcc75fb 2021-03-17 op .alloc = hash_alloc,
57 cbcc75fb 2021-03-17 op ohash_init(h, sz, &info);
60 cbcc75fb 2021-03-17 op struct tofu_entry *
61 cbcc75fb 2021-03-17 op telescope_lookup_tofu(struct ohash *h, const char *domain)
63 cbcc75fb 2021-03-17 op unsigned int slot;
65 cbcc75fb 2021-03-17 op slot = ohash_qlookup(h, domain);
66 cbcc75fb 2021-03-17 op return ohash_find(h, slot);
70 cbcc75fb 2021-03-17 op telescope_ohash_insert(struct ohash *h, struct tofu_entry *e)
72 cbcc75fb 2021-03-17 op unsigned int slot;
74 cbcc75fb 2021-03-17 op slot = ohash_qlookup(h, e->domain);
75 cbcc75fb 2021-03-17 op ohash_insert(h, slot, e);