1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <yaz/xmalloc.h>
25 #include <idzebra/dict.h>
29 #define DICT_MAGIC "dict01"
31 #define DICT_DEFAULT_PAGESIZE 4096
33 typedef unsigned char Dict_char;
34 typedef unsigned Dict_ptr;
40 Dict_ptr root, last, freelist;
43 struct Dict_file_block
45 struct Dict_file_block *h_next, **h_prev;
46 struct Dict_file_block *lru_next, *lru_prev;
53 typedef struct Dict_file_struct
58 struct Dict_file_block *all_blocks;
59 struct Dict_file_block *free_list;
60 struct Dict_file_block **hash_array;
62 struct Dict_file_block *lru_back, *lru_front;
75 const char **(*grep_cmap)(void *vp, const char **from, int len);
77 /** number of split page operations, since dict_open */
79 /** number of insert operations, since dict_open */
81 /** number of lookup operations, since dict_open */
83 struct Dict_head head;
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,
92 int dict_bf_close (Dict_BFile dbf);
93 void dict_bf_compact (Dict_BFile dbf);
95 int dict_strcmp (const Dict_char *s1, const Dict_char *s2);
97 int dict_strncmp (const Dict_char *s1, const Dict_char *s2, size_t n);
99 int dict_strlen (const Dict_char *s);
103 #define DICT_type(x) 0[(Dict_ptr*) x]
104 #define DICT_backptr(x) 1[(Dict_ptr*) x]
105 #define DICT_bsize(x) 2[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
106 #define DICT_nodir(x) 0[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
107 #define DICT_size(x) 1[(short*)((char*)(x)+2*sizeof(Dict_ptr))]
108 #define DICT_infoffset (2*sizeof(Dict_ptr)+3*sizeof(short))
109 #define DICT_xxxxpagesize(x) ((x)->head.page_size)
111 #define DICT_to_str(x) sizeof(Dict_info)+sizeof(Dict_ptr)
115 backptr pointer to parent
116 nextptr pointer to next page (if any)
118 size size of strings,info,ptr entries
130 * c-file-style: "Stroustrup"
131 * indent-tabs-mode: nil
133 * vim: shiftwidth=4 tabstop=8 expandtab