e50fff8f8740b8674c8a496cf433f4a8363536b3
[idzebra-moved-to-github.git] / dict / dict-p.h
1 /* $Id: dict-p.h,v 1.8 2006-12-12 13:42:24 adam Exp $
2    Copyright (C) 1995-2006
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #ifndef DICT_P_H
24 #define DICT_P_H
25
26 #include <yaz/log.h>
27 #include <yaz/xmalloc.h>
28 #include <idzebra/dict.h>
29
30 YAZ_BEGIN_CDECL
31
32 #define DICT_MAGIC "dict01"
33
34 #define DICT_DEFAULT_PAGESIZE 4096
35
36 typedef unsigned char Dict_char;
37 typedef unsigned Dict_ptr;
38
39 struct Dict_head {
40     char magic_str[8];
41     int page_size;
42     int compact_flag;
43     Dict_ptr root, last, freelist;
44 };
45
46 struct Dict_file_block
47 {
48     struct Dict_file_block *h_next, **h_prev;
49     struct Dict_file_block *lru_next, *lru_prev;
50     void *data;
51     int dirty;
52     int no;
53     int nbytes;
54 };
55
56 typedef struct Dict_file_struct
57 {
58     int cache;
59     BFile bf;
60     
61     struct Dict_file_block *all_blocks;
62     struct Dict_file_block *free_list;
63     struct Dict_file_block **hash_array;
64     
65     struct Dict_file_block *lru_back, *lru_front;
66     int hash_size;
67     void *all_data;
68     
69     int  block_size;
70     int  hits;
71     int  misses;
72     int  compact_flag;
73 } *Dict_BFile;
74
75 struct Dict_struct {
76     int rw;
77     Dict_BFile dbf;
78     const char **(*grep_cmap)(void *vp, const char **from, int len);
79     void *grep_cmap_data;
80     /** number of split page operations, since dict_open */
81     zint no_split;
82     /** number of insert operations, since dict_open */
83     zint no_insert;
84     /** number of lookup operations, since dict_open */
85     zint no_lookup;
86     struct Dict_head head;
87 };
88
89 int        dict_bf_readp (Dict_BFile bf, int no, void **bufp);
90 int        dict_bf_newp (Dict_BFile bf, int no, void **bufp, int nbytes);
91 int        dict_bf_touch (Dict_BFile bf, int no);
92 void       dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush);
93 Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size,
94                          int cache, int rw);
95 int        dict_bf_close (Dict_BFile dbf);
96 void       dict_bf_compact (Dict_BFile dbf);
97
98 int dict_strcmp (const Dict_char *s1, const Dict_char *s2);
99
100 int dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n);
101
102 int dict_strlen (const Dict_char *s);
103
104
105 #define DICT_EOS        0
106 #define DICT_type(x)    0[(Dict_ptr*) x]
107 #define DICT_backptr(x) 1[(Dict_ptr*) x]
108 #define DICT_bsize(x)   2[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
109 #define DICT_nodir(x)   0[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
110 #define DICT_size(x)    1[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
111 #define DICT_infoffset  (2*sizeof(Dict_ptr)+3*sizeof(short))
112 #define DICT_xxxxpagesize(x) ((x)->head.page_size)
113
114 #define DICT_to_str(x)  sizeof(Dict_info)+sizeof(Dict_ptr)
115
116 /*
117    type            type of page
118    backptr         pointer to parent
119    nextptr         pointer to next page (if any)
120    nodir           no of words
121    size            size of strings,info,ptr entries
122
123    dir[0..nodir-1]
124    ptr,info,string
125  */
126      
127 YAZ_END_CDECL
128
129 #endif
130 /*
131  * Local variables:
132  * c-basic-offset: 4
133  * indent-tabs-mode: nil
134  * End:
135  * vim: shiftwidth=4 tabstop=8 expandtab
136  */
137