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