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