9ecc3190cc2df72ef23ebb48d398504f89b0e7c9
[idzebra-moved-to-github.git] / include / isam.h
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: isam.h,v $
7  * Revision 1.14  1999-02-02 14:50:34  adam
8  * Updated WIN32 code specific sections. Changed header.
9  *
10  * Revision 1.13  1997/09/17 12:19:09  adam
11  * Zebra version corresponds to YAZ version 1.4.
12  * Changed Zebra server so that it doesn't depend on global common_resource.
13  *
14  * Revision 1.12  1997/09/05 15:30:00  adam
15  * Changed prototype for chr_map_input - added const.
16  * Added support for C++, headers uses extern "C" for public definitions.
17  *
18  * Revision 1.11  1996/10/29 13:43:44  adam
19  * Removed definition of SYSNO.
20  *
21  * Revision 1.10  1995/09/06 16:10:57  adam
22  * More work on boolean sets.
23  *
24  * Revision 1.9  1994/09/28  16:58:26  quinn
25  * Small mod.
26  *
27  * Revision 1.8  1994/09/28  12:56:09  quinn
28  * Added access functions (ISPT)
29  *
30  * Revision 1.7  1994/09/28  11:56:13  quinn
31  * Removed const from input to is_merge
32  *
33  * Revision 1.6  1994/09/28  11:29:28  quinn
34  * Added cmp parameter.
35  *
36  * Revision 1.5  1994/09/27  20:03:36  quinn
37  * Seems relatively bug-free.
38  *
39  * Revision 1.4  1994/09/26  17:05:54  quinn
40  * Trivial.
41  *
42  * Revision 1.3  1994/09/26  16:08:42  quinn
43  * Most of the functionality in place.
44  *
45  * Revision 1.2  1994/09/14  13:10:35  quinn
46  * Small changes
47  *
48  * Revision 1.1  1994/09/12  08:02:07  quinn
49  * Not functional yet
50  *
51  */
52
53 #ifndef ISAM_H
54 #define ISAM_H
55
56 #include <res.h>
57 #include <bfile.h>
58
59 #include "../isam/memory.h"
60 #include "../isam/physical.h"
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 #define IS_MAX_BLOCKTYPES 4
67 #define IS_MAX_RECORD 512
68 #define IS_DEF_REPACK_PERCENT "30" /* how much relative change before repack */
69
70 /*
71  * Description of a blocktype (part of an isam file)
72  */
73 typedef struct isam_blocktype
74 {
75     BFile bf;                    /* blocked file */
76     int blocksize;
77     int first_block;             /* position of first data block */
78     int max_keys_block;          /* max num of keys per block */
79     int max_keys_block0;         /* max num of keys in first block */
80     int nice_keys_block;         /* nice number of keys per block */
81     int max_keys;                /* max number of keys per table */
82     int freelist;                /* first free block */
83     int top;                     /* first unused block */
84     int index;                   /* placeholder. Always 0. */
85     char *dbuf;                  /* buffer for use in I/O operations */
86 } isam_blocktype;
87
88 /*
89  * Handle to an open isam complex.
90  */
91 typedef struct isam_struct
92 {
93     isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */
94     int num_types;                /* number of block types used */
95     int writeflag;
96     int keysize;                  /* size of the keys (records) used */
97     int repack;                   /* how many percent to grow before repack */
98     int (*cmp)(const void *k1, const void *k2); /* compare function */
99 } isam_struct;
100
101 typedef struct ispt_struct
102 {
103     struct is_mtable tab;
104     struct ispt_struct *next;      /* freelist */
105 } ispt_struct, *ISPT; 
106
107 #define is_type(x) ((x) & 3)      /* type part of position */
108 #define is_block(x) ((x) >> 2)     /* block # part of position */
109
110 #define is_keysize(is) ((is)->keysize)
111
112 /*
113  * Public Prototypes.
114  *******************************************************************
115  */
116
117 /*
118  * Open isam file.
119  */
120 ISAM is_open(BFiles bfs, const char *name,
121              int (*cmp)(const void *p1, const void *p2),
122              int writeflag, int keysize, Res res);
123
124 /*
125  * Close isam file.
126  */
127 int is_close(ISAM is);
128
129 /*
130  * Locate a table of keys in an isam file. The ISPT is an individual
131  * position marker for that table.
132  */
133 ISPT is_position(ISAM is, ISAM_P pos);
134
135 /*
136  * Release ISPT.
137  */
138 void is_pt_free(ISPT ip);
139
140 /*
141  * Read a key from a table.
142  */
143 int is_readkey(ISPT ip, void *buf);
144
145 int is_writekey(ISPT ip, const void *buf);
146
147 int is_numkeys(ISPT ip);
148
149 void is_rewind(ISPT ip);
150
151 ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data);
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif