Towards GPL
[idzebra-moved-to-github.git] / include / isam.h
1 /* $Id: isam.h,v 1.15 2002-08-02 19:26:55 adam 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 #ifndef ISAM_H
26 #define ISAM_H
27
28 #include <res.h>
29 #include <bfile.h>
30
31 #include "../isam/memory.h"
32 #include "../isam/physical.h"
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define IS_MAX_BLOCKTYPES 4
39 #define IS_MAX_RECORD 512
40 #define IS_DEF_REPACK_PERCENT "30" /* how much relative change before repack */
41
42 /*
43  * Description of a blocktype (part of an isam file)
44  */
45 typedef struct isam_blocktype
46 {
47     BFile bf;                    /* blocked file */
48     int blocksize;
49     int first_block;             /* position of first data block */
50     int max_keys_block;          /* max num of keys per block */
51     int max_keys_block0;         /* max num of keys in first block */
52     int nice_keys_block;         /* nice number of keys per block */
53     int max_keys;                /* max number of keys per table */
54     int freelist;                /* first free block */
55     int top;                     /* first unused block */
56     int index;                   /* placeholder. Always 0. */
57     char *dbuf;                  /* buffer for use in I/O operations */
58 } isam_blocktype;
59
60 /*
61  * Handle to an open isam complex.
62  */
63 typedef struct isam_struct
64 {
65     isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */
66     int num_types;                /* number of block types used */
67     int writeflag;
68     int keysize;                  /* size of the keys (records) used */
69     int repack;                   /* how many percent to grow before repack */
70     int (*cmp)(const void *k1, const void *k2); /* compare function */
71 } isam_struct;
72
73 typedef struct ispt_struct
74 {
75     struct is_mtable tab;
76     struct ispt_struct *next;      /* freelist */
77 } ispt_struct, *ISPT; 
78
79 #define is_type(x) ((x) & 3)      /* type part of position */
80 #define is_block(x) ((x) >> 2)     /* block # part of position */
81
82 #define is_keysize(is) ((is)->keysize)
83
84 /*
85  * Public Prototypes.
86  *******************************************************************
87  */
88
89 /*
90  * Open isam file.
91  */
92 ISAM is_open(BFiles bfs, const char *name,
93              int (*cmp)(const void *p1, const void *p2),
94              int writeflag, int keysize, Res res);
95
96 /*
97  * Close isam file.
98  */
99 int is_close(ISAM is);
100
101 /*
102  * Locate a table of keys in an isam file. The ISPT is an individual
103  * position marker for that table.
104  */
105 ISPT is_position(ISAM is, ISAM_P pos);
106
107 /*
108  * Release ISPT.
109  */
110 void is_pt_free(ISPT ip);
111
112 /*
113  * Read a key from a table.
114  */
115 int is_readkey(ISPT ip, void *buf);
116
117 int is_writekey(ISPT ip, const void *buf);
118
119 int is_numkeys(ISPT ip);
120
121 void is_rewind(ISPT ip);
122
123 ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data);
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif