9 static void common_init (Dict_BFile bf, int block_size, int cache)
13 bf->block_size = block_size;
17 bf->hits = bf->misses = 0;
19 /* Allocate all blocks in one chunk. */
20 bf->all_data = xmalloc (block_size * cache);
22 /* Allocate and initialize hash array (as empty) */
23 bf->hash_array = xmalloc(sizeof(*bf->hash_array) * bf->hash_size);
24 for (i=bf->hash_size; --i >= 0; )
25 bf->hash_array[i] = NULL;
27 /* Allocate all block descriptors in one chunk */
28 bf->all_blocks = xmalloc (sizeof(*bf->all_blocks) * cache);
30 /* Initialize the free list */
31 bf->free_list = bf->all_blocks;
32 for (i=0; i<cache-1; i++)
33 bf->all_blocks[i].h_next = bf->all_blocks+(i+1);
34 bf->all_blocks[i].h_next = NULL;
36 /* Initialize the data for each block. Will never be moved again */
37 for (i=0; i<cache; i++)
38 bf->all_blocks[i].data = (char*) bf->all_data + i*block_size;
40 /* Initialize lru queue */
46 Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw)
50 dbf = xmalloc (sizeof(*dbf));
51 dbf->bf = bf_open (name, block_size, rw);
54 common_init (dbf, block_size, cache);