Ignore all .log
[idzebra-moved-to-github.git] / include / dict.h
1 /* $Id: dict.h,v 1.34 2004-11-19 10:26:55 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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
24
25 #ifndef DICT_H
26 #define DICT_H
27
28 #include <bfile.h>
29 #include <yaz/ylog.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 typedef unsigned Dict_ptr;
36 typedef unsigned char Dict_char;
37
38 struct Dict_head {
39     char magic_str[8];
40     int page_size;
41     int compact_flag;
42     Dict_ptr root, last, freelist;
43 };
44
45 struct Dict_file_block
46 {
47     struct Dict_file_block *h_next, **h_prev;
48     struct Dict_file_block *lru_next, *lru_prev;
49     void *data;
50     int dirty;
51     int no;
52     int nbytes;
53 };
54
55 typedef struct Dict_file_struct
56 {
57     int cache;
58     BFile bf;
59     
60     struct Dict_file_block *all_blocks;
61     struct Dict_file_block *free_list;
62     struct Dict_file_block **hash_array;
63     
64     struct Dict_file_block *lru_back, *lru_front;
65     int hash_size;
66     void *all_data;
67     
68     int  block_size;
69     int  hits;
70     int  misses;
71     int  compact_flag;
72 } *Dict_BFile;
73
74 typedef struct Dict_struct {
75     int rw;
76     Dict_BFile dbf;
77     const char **(*grep_cmap)(void *vp, const char **from, int len);
78     void *grep_cmap_data;
79     struct Dict_head head;
80 } *Dict;
81
82 #define DICT_MAGIC "dict01"
83
84 #define DICT_DEFAULT_PAGESIZE 4096
85
86 int        dict_bf_readp (Dict_BFile bf, int no, void **bufp);
87 int        dict_bf_newp (Dict_BFile bf, int no, void **bufp, int nbytes);
88 int        dict_bf_touch (Dict_BFile bf, int no);
89 void       dict_bf_flush_blocks (Dict_BFile bf, int no_to_flush);
90 Dict_BFile dict_bf_open (BFiles bfs, const char *name, int block_size,
91                          int cache, int rw);
92 int        dict_bf_close (Dict_BFile dbf);
93 void       dict_bf_compact (Dict_BFile dbf);
94      
95 Dict       dict_open (BFiles bfs, const char *name, int cache, int rw,
96                       int compact_flag, int page_size);
97 int        dict_close (Dict dict);
98 int        dict_insert (Dict dict, const char *p, int userlen, void *userinfo);
99 int        dict_delete (Dict dict, const char *p);
100 int        dict_delete_subtree (Dict dict, const char *p, void *client,
101                                 int (*f)(const char *info, void *client));
102 char      *dict_lookup (Dict dict, const char *p);
103 int        dict_lookup_ec (Dict dict, char *p, int range,
104                            int (*f)(char *name));
105 int        dict_lookup_grep (Dict dict, const char *p, int range, void *client,
106                              int *max_pos, int init_pos,
107                              int (*f)(char *name, const char *info,
108                                       void *client));
109 int        dict_strcmp (const Dict_char *s1, const Dict_char *s2);
110 int        dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n);
111 int        dict_strlen (const Dict_char *s);
112 int        dict_scan (Dict dict, char *str, 
113                       int *before, int *after, void *client,
114                       int (*f)(char *name, const char *info, int pos,
115                                void *client));
116
117 void       dict_grep_cmap (Dict dict, void *vp,
118                            const char **(*cmap)(void *vp,
119                                                 const char **from, int len));
120 int        dict_copy_compact (BFiles bfs, const char *from, const char *to);
121
122
123 #define DICT_EOS        0
124 #define DICT_type(x)    0[(Dict_ptr*) x]
125 #define DICT_backptr(x) 1[(Dict_ptr*) x]
126 #define DICT_bsize(x)   2[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
127 #define DICT_nodir(x)   0[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
128 #define DICT_size(x)    1[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
129 #define DICT_infoffset  (2*sizeof(Dict_ptr)+3*sizeof(short))
130 #define DICT_xxxxpagesize(x) ((x)->head.page_size)
131
132 #define DICT_to_str(x)  sizeof(Dict_info)+sizeof(Dict_ptr)
133
134 /*
135    type            type of page
136    backptr         pointer to parent
137    nextptr         pointer to next page (if any)
138    nodir           no of words
139    size            size of strings,info,ptr entries
140
141    dir[0..nodir-1]
142    ptr,info,string
143  */
144 #ifdef __cplusplus
145 }
146 #endif
147
148    
149 #endif