Use cache in dict - not in bfile.
[idzebra-moved-to-github.git] / include / dict.h
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dict.h,v $
7  * Revision 1.2  1994-08-17 13:32:33  adam
8  * Use cache in dict - not in bfile.
9  *
10  * Revision 1.1  1994/08/16  16:26:53  adam
11  * Added dict.
12  *
13  */
14
15 #ifndef DICT_H
16 #define DICT_H
17
18 #include <bfile.h>
19
20 typedef unsigned Dict_ptr;
21 typedef char Dict_char;
22
23 struct Dict_head {
24     char magic_str[8];
25     int page_size;
26     Dict_ptr free_list, last;
27 };
28
29 struct Dict_file_block
30 {
31     struct Dict_file_block *h_next, **h_prev;
32     struct Dict_file_block *lru_next, *lru_prev;
33     void *data;
34     int dirty;
35     int no;
36 };
37
38 typedef struct Dict_file_struct
39 {
40     int cache;
41     BFile bf;
42
43     struct Dict_file_block *all_blocks;
44     struct Dict_file_block *free_list;
45     struct Dict_file_block **hash_array;
46
47     struct Dict_file_block *lru_back, *lru_front;
48     int hash_size;
49     void *all_data;
50
51     int  hits;
52     int  misses;
53 } *Dict_BFile;
54
55 typedef struct Dict_struct {
56     Dict_BFile dbf;
57     struct Dict_head head;
58 } *Dict;
59
60 int dict_bf_readp (Dict_BFile bf, int no, void **bufp);
61 int dict_bf_newp (Dict_BFile bf, int no, void **bufp);
62 int dict_bf_touch (Dict_BFile bf, int no);
63 void dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush);
64 Dict_BFile dict_bf_open (const char *name, int block_size, int cache, int rw);
65 int dict_bf_close (Dict_BFile dbf);
66 #define DICT_MAGIC "dict00"
67
68 typedef int Dict_info;
69
70 #define DICT_PAGESIZE 8192
71     
72 Dict dict_open (const char *name, int cache, int rw);
73 int dict_close (Dict dict);
74 int dict_insert (Dict dict, const Dict_char *p, void *userinfo);
75 int dict_lookup (Dict dict, Dict_char *p);
76 int dict_strcmp (const Dict_char *s1, const Dict_char *s2);
77 int dict_strlen (const Dict_char *s);
78
79 #define DICT_EOS        0
80 #define DICT_type(x)    0[(Dict_ptr*) x]
81 #define DICT_backptr(x) 1[(Dict_ptr*) x]
82 #define DICT_nextptr(x) 2[(Dict_ptr*) x]
83 #define DICT_nodir(x)   0[(short*)((char*)(x)+3*sizeof(Dict_ptr))]
84 #define DICT_size(x)    1[(short*)((char*)(x)+3*sizeof(Dict_ptr))]
85 #define DICT_info(x)    ((char*)(x)+3*sizeof(Dict_ptr)+2*sizeof(short))
86
87 #define DICT_to_str(x)  sizeof(Dict_info)+sizeof(Dict_ptr)
88
89 /*
90    type            type of page
91    backptr         pointer to parent
92    nextptr         pointer to next page (if any)
93    nodir           no of words
94    size            size of strings,info,ptr entries
95
96    dir[0..nodir-1]
97    ptr,info,string
98  */
99
100    
101 #endif