Using the new ylog.h everywhere, and fixing what that breaks!
[idzebra-moved-to-github.git] / isamg / isamg.c
1 /* $Id: isamg.c,v 1.4 2004-11-19 10:27:10 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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 <isamg.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
33  * Local type declarations 
34  * Not to be used from outside this module
35  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
36  
37 enum isam_types { 
38    isamtype_unknown=0,
39    isamtype_d=1,
40    }
41
42 /* The isam type itself. File handles, statistics, block sizes */
43 typedef struct ISAMG_file_s {
44     char *isam_type_name;
45     enum isam_types isam_type;
46
47     /* these might be better off as an union of different types. */
48     ISAMD isamd;
49     ISAMD_M isamd_m;
50     
51 } *ISAMG_file;
52
53 struct ISAMG_s {
54 /*
55     int no_files;
56     ISAMG_M method;
57     ISAMG_file files;
58 */
59 }; 
60
61
62 typedef struct ISAMG_DIFF_s *ISAMG_DIFF;
63
64 /* ISAMG position structure. Used for reading through the isam */
65 struct ISAMG_PP_s {
66 #ifdef SKIPTHIS
67     char *buf;   /* buffer for read/write operations */
68     ISAMG_BLOCK_SIZE offset; /* position for next read/write */
69     ISAMG_BLOCK_SIZE size;   /* size of actual data */
70     int cat;  /* category of this block */
71     int pos;  /* block number of this block */
72     int next; /* number of the next block */
73     int diffs; /* not used in the modern isam-d, but kept for stats compatibility */
74                /* never stored on disk, though */
75 #endif
76     ISAMG is;  /* the isam itself */
77     void *decodeClientData;  /* delta-encoder's own data */
78 #ifdef SKIPTHIS
79     ISAMG_DIFF diffinfo;
80     char *diffbuf; /* buffer for the diff block */
81     int numKeys;
82 #endif
83 };
84
85 #ifdef SKIPTHIS
86 #define ISAMG_BLOCK_OFFSET_N (sizeof(int) +  \
87                               sizeof(ISAMG_BLOCK_SIZE)) 
88 /* == 8 */
89 #define ISAMG_BLOCK_OFFSET_1 (sizeof(int) + \
90                               sizeof(ISAMG_BLOCK_SIZE) + \
91                               sizeof(ISAMG_BLOCK_SIZE)) 
92 /* == 12  (was 16) */
93
94
95 int isamg_alloc_block (ISAMG is, int cat);
96 void isamg_release_block (ISAMG is, int cat, int pos);
97 int isamg_read_block (ISAMG is, int cat, int pos, char *dst);
98 int isamg_write_block (ISAMG is, int cat, int pos, char *src);
99 void isamg_free_diffs(ISAMG_PP pp);
100
101 int is_singleton(ISAMG_P ipos);
102 void singleton_decode (int code, struct it_key *k);
103 int singleton_encode(struct it_key *k);
104 #endif
105
106 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
107  * Splitter functions
108  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
109
110 ISAMG isamg_open (BFiles bfs, int writeflag, char *isam_type_name, Res res){
111     ISAMG is;
112     is = (ISAMD) xmalloc(sizeof(*is));
113     is->isam_type_name = strdup(isam_type_name);
114     if ( (0==strcmp(isam_type_name,"d") ||
115          (0==strcmp(isam_type_name,"isam_d")) {
116         is->isam_type = isamtype_isamd;
117         is->isamd = isamd_open(bfs,FNAME_ISAMD, 
118                     writeflag, key_isamd_m (res,&isamd_m)
119     }
120     else {
121         yaz_log (YLOG_FATAL, "isamg: Unknown isam type: %s", isam_type_name);
122         exit(1);
123     }
124 } /* open */
125
126 int isamg_close (ISAMG is){
127     assert(is);
128     assert(is->isam_type);
129     select (is->isam_type) {
130         case isamtype_isamd: return isams_close(is->isamd);
131     }
132 } /* close */
133
134
135
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141
142
143
144 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
145  * Log
146  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
147
148
149 /*
150  * $Log: isamg.c,v $
151  * Revision 1.4  2004-11-19 10:27:10  heikki
152  * Using the new ylog.h everywhere, and fixing what that breaks!
153  *
154  * Revision 1.3  2003/04/02 19:01:47  adam
155  * Remove // comment
156  *
157  * Revision 1.2  2002/08/02 19:26:56  adam
158  * Towards GPL
159  *
160  * Revision 1.1  2001/01/16 19:05:45  heikki
161  * Started to work on isamg
162  *
163  *
164  *
165  */