2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1999-02-02 14:50:20 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.5 1997/09/17 12:19:07 adam
11 * Zebra version corresponds to YAZ version 1.4.
12 * Changed Zebra server so that it doesn't depend on global common_resource.
14 * Revision 1.4 1997/09/09 13:38:01 adam
15 * Partial port to WIN95/NT.
17 * Revision 1.3 1994/09/01 17:49:37 adam
18 * Removed stupid line. Work on insertion in dictionary. Not finished yet.
22 #include <sys/types.h>
32 static void common_init (Dict_BFile bf, int block_size, int cache)
36 bf->block_size = block_size;
40 bf->hits = bf->misses = 0;
42 /* Allocate all blocks in one chunk. */
43 bf->all_data = xmalloc (block_size * cache);
45 /* Allocate and initialize hash array (as empty) */
46 bf->hash_array = xmalloc(sizeof(*bf->hash_array) * bf->hash_size);
47 for (i=bf->hash_size; --i >= 0; )
48 bf->hash_array[i] = NULL;
50 /* Allocate all block descriptors in one chunk */
51 bf->all_blocks = xmalloc (sizeof(*bf->all_blocks) * cache);
53 /* Initialize the free list */
54 bf->free_list = bf->all_blocks;
55 for (i=0; i<cache-1; i++)
56 bf->all_blocks[i].h_next = bf->all_blocks+(i+1);
57 bf->all_blocks[i].h_next = NULL;
59 /* Initialize the data for each block. Will never be moved again */
60 for (i=0; i<cache; i++)
61 bf->all_blocks[i].data = (char*) bf->all_data + i*block_size;
63 /* Initialize lru queue */
69 Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size,
74 dbf = xmalloc (sizeof(*dbf));
75 dbf->bf = bf_open (bfs, name, block_size, rw);
78 common_init (dbf, block_size, cache);