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