xref: /minix3/usr.bin/m4/lib/ohash_init.c (revision 2e8d1eda1b10b1eefcc41d19325e6baa0615ae5c)
1*2e8d1edaSArun Thomas /* $OpenBSD: ohash_init.c,v 1.2 2004/06/22 20:00:16 espie Exp $ */
2*2e8d1edaSArun Thomas /* ex:ts=8 sw=4:
3*2e8d1edaSArun Thomas  */
4*2e8d1edaSArun Thomas 
5*2e8d1edaSArun Thomas /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
6*2e8d1edaSArun Thomas  *
7*2e8d1edaSArun Thomas  * Permission to use, copy, modify, and distribute this software for any
8*2e8d1edaSArun Thomas  * purpose with or without fee is hereby granted, provided that the above
9*2e8d1edaSArun Thomas  * copyright notice and this permission notice appear in all copies.
10*2e8d1edaSArun Thomas  *
11*2e8d1edaSArun Thomas  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12*2e8d1edaSArun Thomas  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13*2e8d1edaSArun Thomas  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14*2e8d1edaSArun Thomas  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15*2e8d1edaSArun Thomas  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16*2e8d1edaSArun Thomas  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17*2e8d1edaSArun Thomas  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*2e8d1edaSArun Thomas  */
19*2e8d1edaSArun Thomas 
20*2e8d1edaSArun Thomas #include "ohash_int.h"
21*2e8d1edaSArun Thomas 
22*2e8d1edaSArun Thomas void
ohash_init(struct ohash * h,unsigned int size,struct ohash_info * info)23*2e8d1edaSArun Thomas ohash_init(struct ohash *h, unsigned int size, struct ohash_info *info)
24*2e8d1edaSArun Thomas {
25*2e8d1edaSArun Thomas 	h->size = 1UL << size;
26*2e8d1edaSArun Thomas 	if (h->size < MINSIZE)
27*2e8d1edaSArun Thomas 		h->size = MINSIZE;
28*2e8d1edaSArun Thomas #ifdef STATS_HASH
29*2e8d1edaSArun Thomas 	STAT_HASH_CREATION++;
30*2e8d1edaSArun Thomas 	STAT_HASH_SIZE += h->size;
31*2e8d1edaSArun Thomas #endif
32*2e8d1edaSArun Thomas 	/* Copy info so that caller may free it.  */
33*2e8d1edaSArun Thomas 	h->info.key_offset = info->key_offset;
34*2e8d1edaSArun Thomas 	h->info.halloc = info->halloc;
35*2e8d1edaSArun Thomas 	h->info.hfree = info->hfree;
36*2e8d1edaSArun Thomas 	h->info.alloc = info->alloc;
37*2e8d1edaSArun Thomas 	h->info.data = info->data;
38*2e8d1edaSArun Thomas 	h->t = (h->info.halloc)(sizeof(struct _ohash_record) * h->size,
39*2e8d1edaSArun Thomas 	    h->info.data);
40*2e8d1edaSArun Thomas 	h->total = h->deleted = 0;
41*2e8d1edaSArun Thomas }
42