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