Implemented isamb_unlink.
[idzebra-moved-to-github.git] / isamc / isamd-p.h
1 /* $Id: isamd-p.h,v 1.13 2003-06-23 15:36:11 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
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 #include <bfile.h>
26 #include <isamd.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef struct {
33     int lastblock;
34     int freelist;
35 } ISAMD_head;
36
37 typedef unsigned ISAMD_BLOCK_SIZE;
38
39 typedef struct ISAMD_file_s {
40     ISAMD_head head;
41     BFile bf;
42     int head_is_dirty;
43     
44     int no_writes;  /* statistics, to be used properly... */
45     int no_reads;
46     int no_skip_writes;
47     int no_allocated;
48     int no_released;
49     int no_remap;
50
51     int no_forward;  /* stats from pp_read, for isam-c compatibility */
52     int no_backward;
53     int sum_forward;
54     int sum_backward;
55     int no_next;
56     int no_prev;
57
58     int no_op_diffonly;/* number of opens without mainblock */
59     int no_op_main;    /* number of opens with a main block */
60
61     char *alloc_buf;    /* free-list handling (?) */
62     int alloc_entries_num;
63     int alloc_entries_max;
64
65     int fc_max;
66     int *fc_list;
67 } *ISAMD_file;
68
69 struct ISAMD_s {
70     int no_files;
71     int max_cat;
72     ISAMD_M *method;
73     ISAMD_file files;
74     int last_pos;   /* last read/write position for seek stats */
75     int last_cat;   /* same for category */
76     int no_read;    /* blocks read (in all categories) */
77     int no_write;   /* blocks written (in all categories) */
78     int no_op_single;/* singleton "blocks" opened */
79     int no_read_keys;/* number of keys read (occurences of words) */
80     int no_read_main;/* number of main keys read (not diffs) */
81     int no_read_eof; /* number of key sequence ends read (no of words read) */
82     int no_seek_nxt; /* seeks to the next record (fast) */
83     int no_seek_sam; /* seeks to same record (fast) */
84     int no_seek_fwd; /* seeks forward */
85     int no_seek_prv; /* seeks to previous */
86     int no_seek_bak; /* seeks backwards */
87     int no_seek_cat; /* seeks to different category (expensive) */
88     int no_op_new;  /* "open"s for new blocks */
89     int no_fbuilds;    /* number of first-time builds */
90     int no_appds;      /* number of appends */
91     int no_merges;     /* number of merges done */
92     int no_non;     /* merges without any work */
93     int no_singles; /* new items resulting in singletons */
94 }; 
95
96
97 typedef struct ISAMD_DIFF_s *ISAMD_DIFF;
98
99 struct ISAMD_PP_s {
100     char *buf;   /* buffer for read/write operations */
101     ISAMD_BLOCK_SIZE offset; /* position for next read/write */
102     ISAMD_BLOCK_SIZE size;   /* size of actual data */
103     int cat;  /* category of this block */
104     int pos;  /* block number of this block */
105     int next; /* number of the next block */
106     int diffs; /* not used in the modern isam-d, but kept for stats compatibility */
107                /* never stored on disk, though */
108     ISAMD is;
109     void *decodeClientData;  /* delta-encoder's own data */
110     ISAMD_DIFF diffinfo;
111     char *diffbuf; /* buffer for the diff block */
112     int numKeys;
113 };
114
115 #define ISAMD_BLOCK_OFFSET_N (sizeof(int) +  \
116                               sizeof(ISAMD_BLOCK_SIZE)) 
117 /* == 8 */
118 #define ISAMD_BLOCK_OFFSET_1 (sizeof(int) + \
119                               sizeof(ISAMD_BLOCK_SIZE) + \
120                               sizeof(ISAMD_BLOCK_SIZE)) 
121 /* == 12  (was 16) */
122 /*                              sizeof(int) +  */
123
124
125 int isamd_alloc_block (ISAMD is, int cat);
126 void isamd_release_block (ISAMD is, int cat, int pos);
127 int isamd_read_block (ISAMD is, int cat, int pos, char *dst);
128 int isamd_write_block (ISAMD is, int cat, int pos, char *src);
129 void isamd_free_diffs(ISAMD_PP pp);
130
131 int is_singleton(ISAMD_P ipos);
132 void singleton_decode (int code, struct it_key *k);
133 int singleton_encode(struct it_key *k);
134
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140
141
142 /*
143  * $Log: isamd-p.h,v $
144  * Revision 1.13  2003-06-23 15:36:11  adam
145  * Implemented isamb_unlink.
146  *
147  * Revision 1.12  2002/11/26 22:18:34  adam
148  * Remove // comments
149  *
150  * Revision 1.11  2002/08/02 19:26:56  adam
151  * Towards GPL
152  *
153  * Revision 1.10  2002/04/29 18:10:24  adam
154  * Newline at end of file
155  *
156  * Revision 1.9  1999/10/05 09:57:40  heikki
157  * Tuning the isam-d (and fixed a small "detail")
158  *
159  * Revision 1.8  1999/09/23 18:01:18  heikki
160  * singleton optimising
161  *
162  * Revision 1.7  1999/09/20 15:48:06  heikki
163  * Small changes
164  *
165  * Revision 1.6  1999/08/25 18:09:23  heikki
166  * Starting to optimize
167  *
168  * Revision 1.5  1999/08/20 12:25:58  heikki
169  * Statistics in isamd
170  *
171  * Revision 1.4  1999/07/21 14:24:50  heikki
172  * isamd write and read functions ok, except when diff block full.
173  * (merge not yet done)
174  *
175  * Revision 1.3  1999/07/14 15:05:30  heikki
176  * slow start on isam-d
177  *
178  * Revision 1.1  1999/07/14 12:34:43  heikki
179  * Copied from isamh, starting to change things...
180  *
181  *
182  */
183