2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1994-09-01 17:49:37 adam
8 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
12 #include <sys/types.h>
20 static void common_init (Dict_BFile bf, int block_size, int cache)
24 bf->block_size = block_size;
28 bf->hits = bf->misses = 0;
30 /* Allocate all blocks in one chunk. */
31 bf->all_data = xmalloc (block_size * cache);
33 /* Allocate and initialize hash array (as empty) */
34 bf->hash_array = xmalloc(sizeof(*bf->hash_array) * bf->hash_size);
35 for (i=bf->hash_size; --i >= 0; )
36 bf->hash_array[i] = NULL;
38 /* Allocate all block descriptors in one chunk */
39 bf->all_blocks = xmalloc (sizeof(*bf->all_blocks) * cache);
41 /* Initialize the free list */
42 bf->free_list = bf->all_blocks;
43 for (i=0; i<cache-1; i++)
44 bf->all_blocks[i].h_next = bf->all_blocks+(i+1);
45 bf->all_blocks[i].h_next = NULL;
47 /* Initialize the data for each block. Will never be moved again */
48 for (i=0; i<cache; i++)
49 bf->all_blocks[i].data = (char*) bf->all_data + i*block_size;
51 /* Initialize lru queue */
57 Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw)
61 dbf = xmalloc (sizeof(*dbf));
62 dbf->bf = bf_open (name, block_size, rw);
65 common_init (dbf, block_size, cache);