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