1 /* init.c */
2
3 #include "../I2Ohash.h"
4
5 /*--------------------------------------------------------------------*/
6 /*
7 ------------------------------------------
8 initializer,
9 (1) set hashtable maximum size to nlist
10 and allocate the heads[] vector
11 (2) initialize nobj I2OP objects
12 (2) set item growth factor to grow
13
14 created -- 98jan29, cca
15 ------------------------------------------
16 */
17 void
I2Ohash_init(I2Ohash * hashtable,int nlist,int nobj,int grow)18 I2Ohash_init (
19 I2Ohash *hashtable,
20 int nlist,
21 int nobj,
22 int grow
23 ) {
24 int ii ;
25 if ( hashtable == NULL || nlist <= 0 ) {
26 fprintf(stderr, "\n\n error in I2Ohash_init(%p,%d,%d,%d)"
27 "\n hashtable is NULL or nlist = %d is nonpositive\n",
28 hashtable, nlist, nobj, grow, nlist) ;
29 exit(-1) ;
30 }
31 if ( nobj <= 0 && grow <= 0 ) {
32 fprintf(stderr, "\n\n error in I2Ohash_init(%p,%d,%d,%d)"
33 "\n nobj = %d, grow = %d\n",
34 hashtable, nlist, nobj, grow, nobj, grow) ;
35 exit(-1) ;
36 }
37 I2Ohash_clearData(hashtable) ;
38 hashtable->nlist = nlist ;
39 hashtable->grow = grow ;
40 if ( nobj > 0 ) {
41 hashtable->baseI2OP = I2OP_init(nobj+1, I2OP_FORWARD) ;
42 hashtable->freeI2OP = hashtable->baseI2OP + 1 ;
43 hashtable->baseI2OP->next = NULL ;
44 }
45 ALLOCATE(hashtable->heads, struct _I2OP *, nlist) ;
46 for ( ii = 0 ; ii < nlist ; ii++ ) {
47 hashtable->heads[ii] = NULL ;
48 }
49
50 return ; }
51
52 /*--------------------------------------------------------------------*/
53