a4e13ed64759b046bd57ad6ff43b2888c922ec24
[idzebra-moved-to-github.git] / isamg / isamg.c
1 /* $Id: */
2  * Copyright (c) 1995-1996, Index Data.
3  * See the file LICENSE for details.
4  *
5  * ISAM-G the general encapsulation of all our ISAM types
6  *
7  * Heikki Levanto
8  *
9  * log at the end
10  */
11
12 #include <bfile.h>
13 #include <isamg.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
20  * Local type declarations 
21  * Not to be used from outside this module
22  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23  
24 enum isam_types { 
25    isamtype_unknown=0,
26    isamtype_d=1,
27    }
28
29 /* The isam type itself. File handles, statistics, block sizes */
30 typedef struct ISAMG_file_s {
31     char *isam_type_name;
32     enum isam_types isam_type;
33
34     /* these might be better off as an union of different types. */
35     ISAMD isamd;
36     ISAMD_M isamd_m;
37     
38 } *ISAMG_file;
39
40 struct ISAMG_s {
41 /*
42     int no_files;
43     ISAMG_M method;
44     ISAMG_file files;
45 */
46 }; 
47
48
49 typedef struct ISAMG_DIFF_s *ISAMG_DIFF;
50
51 /* ISAMG position structure. Used for reading through the isam */
52 struct ISAMG_PP_s {
53 #ifdef SKIPTHIS
54     char *buf;   /* buffer for read/write operations */
55     ISAMG_BLOCK_SIZE offset; /* position for next read/write */
56     ISAMG_BLOCK_SIZE size;   /* size of actual data */
57     int cat;  /* category of this block */
58     int pos;  /* block number of this block */
59     int next; /* number of the next block */
60     int diffs; /* not used in the modern isam-d, but kept for stats compatibility */
61                /* never stored on disk, though */
62 #endif
63     ISAMG is;  /* the isam itself */
64     void *decodeClientData;  /* delta-encoder's own data */
65 #ifdef SKIPTHIS
66     ISAMG_DIFF diffinfo;
67     char *diffbuf; /* buffer for the diff block */
68     int numKeys;
69 #endif
70 };
71
72 #ifdef SKIPTHIS
73 #define ISAMG_BLOCK_OFFSET_N (sizeof(int) +  \
74                               sizeof(ISAMG_BLOCK_SIZE)) 
75 /* == 8 */
76 #define ISAMG_BLOCK_OFFSET_1 (sizeof(int) + \
77                               sizeof(ISAMG_BLOCK_SIZE) + \
78                               sizeof(ISAMG_BLOCK_SIZE)) 
79 /* == 12  (was 16) */
80 //                              sizeof(int) + 
81
82
83 int isamg_alloc_block (ISAMG is, int cat);
84 void isamg_release_block (ISAMG is, int cat, int pos);
85 int isamg_read_block (ISAMG is, int cat, int pos, char *dst);
86 int isamg_write_block (ISAMG is, int cat, int pos, char *src);
87 void isamg_free_diffs(ISAMG_PP pp);
88
89 int is_singleton(ISAMG_P ipos);
90 void singleton_decode (int code, struct it_key *k);
91 int singleton_encode(struct it_key *k);
92 #endif
93
94 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
95  * Splitter functions
96  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
97
98 ISAMG isamg_open (BFiles bfs, int writeflag, char *isam_type_name, Res res){
99     ISAMG is;
100     is = (ISAMD) xmalloc(sizeof(*is));
101     is->isam_type_name = strdup(isam_type_name);
102     if ( (0==strcmp(isam_type_name,"d") ||
103          (0==strcmp(isam_type_name,"isam_d")) {
104         is->isam_type = isamtype_isamd;
105         is->isamd = isamd_open(bfs,FNAME_ISAMD, 
106                     writeflag, key_isamd_m (res,&isamd_m)
107     }
108     else {
109         logf (LOG_FATAL, "isamg: Unknown isam type: %s", isam_type_name);
110         exit(1);
111     }
112 } /* open */
113
114 int isamg_close (ISAMG is){
115     assert(is);
116     assert(is->isam_type);
117     select (is->isam_type) {
118         case isamtype_isamd: return isams_close(is->isamd);
119     }
120 } /* close */
121
122
123
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129
130
131
132 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
133  * Log
134  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
135
136
137 /*
138  * $Log: isamg.c,v $
139  * Revision 1.1  2001-01-16 19:05:45  heikki
140  * Started to work on isamg
141  *
142  *
143  *
144  */