1294109Sbapt/*	$Id: mandoc_ohash.c,v 1.2 2015/10/19 18:58:47 schwarze Exp $	*/
2294109Sbapt/*
3294109Sbapt * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
4294109Sbapt *
5294109Sbapt * Permission to use, copy, modify, and distribute this software for any
6294109Sbapt * purpose with or without fee is hereby granted, provided that the above
7294109Sbapt * copyright notice and this permission notice appear in all copies.
8294109Sbapt *
9294109Sbapt * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
10294109Sbapt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11294109Sbapt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
12294109Sbapt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13294109Sbapt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14294109Sbapt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15294109Sbapt * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16294109Sbapt */
17294109Sbapt#include <sys/types.h>
18294109Sbapt#include <stddef.h>
19294109Sbapt#include <stdint.h>
20294109Sbapt#include <stdlib.h>
21294109Sbapt
22294109Sbapt#include "mandoc_aux.h"
23294109Sbapt#include "mandoc_ohash.h"
24294109Sbapt
25294109Sbaptstatic	void	 *hash_alloc(size_t, void *);
26294109Sbaptstatic	void	 *hash_calloc(size_t, size_t, void *);
27294109Sbaptstatic	void	  hash_free(void *, void *);
28294109Sbapt
29294109Sbapt
30294109Sbaptvoid
31294109Sbaptmandoc_ohash_init(struct ohash *h, unsigned int sz, ptrdiff_t ko)
32294109Sbapt{
33294109Sbapt	struct ohash_info info;
34294109Sbapt
35294109Sbapt	info.alloc = hash_alloc;
36294109Sbapt	info.calloc = hash_calloc;
37294109Sbapt	info.free = hash_free;
38294109Sbapt	info.data = NULL;
39294109Sbapt	info.key_offset = ko;
40294109Sbapt
41294109Sbapt	ohash_init(h, sz, &info);
42294109Sbapt}
43294109Sbapt
44294109Sbaptstatic void *
45294109Sbapthash_alloc(size_t sz, void *arg)
46294109Sbapt{
47294109Sbapt
48294109Sbapt	return mandoc_malloc(sz);
49294109Sbapt}
50294109Sbapt
51294109Sbaptstatic void *
52294109Sbapthash_calloc(size_t n, size_t sz, void *arg)
53294109Sbapt{
54294109Sbapt
55294109Sbapt	return mandoc_calloc(n, sz);
56294109Sbapt}
57294109Sbapt
58294109Sbaptstatic void
59294109Sbapthash_free(void *p, void *arg)
60294109Sbapt{
61294109Sbapt
62294109Sbapt	free(p);
63294109Sbapt}
64