Bump year. Change Aps->ApS
[idzebra-moved-to-github.git] / dict / dict-p.h
1 /* $Id: dict-p.h,v 1.3 2005-01-15 19:38:21 adam Exp $
2    Copyright (C) 1995-2005
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 Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
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 struct Dict_head {
37     char magic_str[8];
38     int page_size;
39     int compact_flag;
40     Dict_ptr root, last, freelist;
41 };
42
43 struct Dict_file_block
44 {
45     struct Dict_file_block *h_next, **h_prev;
46     struct Dict_file_block *lru_next, *lru_prev;
47     void *data;
48     int dirty;
49     int no;
50     int nbytes;
51 };
52
53 typedef struct Dict_file_struct
54 {
55     int cache;
56     BFile bf;
57     
58     struct Dict_file_block *all_blocks;
59     struct Dict_file_block *free_list;
60     struct Dict_file_block **hash_array;
61     
62     struct Dict_file_block *lru_back, *lru_front;
63     int hash_size;
64     void *all_data;
65     
66     int  block_size;
67     int  hits;
68     int  misses;
69     int  compact_flag;
70 } *Dict_BFile;
71
72 struct Dict_struct {
73     int rw;
74     Dict_BFile dbf;
75     const char **(*grep_cmap)(void *vp, const char **from, int len);
76     void *grep_cmap_data;
77     struct Dict_head head;
78 };
79
80 int        dict_bf_readp (Dict_BFile bf, int no, void **bufp);
81 int        dict_bf_newp (Dict_BFile bf, int no, void **bufp, int nbytes);
82 int        dict_bf_touch (Dict_BFile bf, int no);
83 void       dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush);
84 Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size,
85                          int cache, int rw);
86 int        dict_bf_close (Dict_BFile dbf);
87 void       dict_bf_compact (Dict_BFile dbf);
88
89 #define DICT_EOS        0
90 #define DICT_type(x)    0[(Dict_ptr*) x]
91 #define DICT_backptr(x) 1[(Dict_ptr*) x]
92 #define DICT_bsize(x)   2[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
93 #define DICT_nodir(x)   0[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
94 #define DICT_size(x)    1[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
95 #define DICT_infoffset  (2*sizeof(Dict_ptr)+3*sizeof(short))
96 #define DICT_xxxxpagesize(x) ((x)->head.page_size)
97
98 #define DICT_to_str(x)  sizeof(Dict_info)+sizeof(Dict_ptr)
99
100 /*
101    type            type of page
102    backptr         pointer to parent
103    nextptr         pointer to next page (if any)
104    nodir           no of words
105    size            size of strings,info,ptr entries
106
107    dir[0..nodir-1]
108    ptr,info,string
109  */
110      
111 YAZ_END_CDECL
112
113 #endif