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