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