Added access functions (ISPT)
[idzebra-moved-to-github.git] / include / isam.h
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: isam.h,v $
7  * Revision 1.8  1994-09-28 12:56:09  quinn
8  * Added access functions (ISPT)
9  *
10  * Revision 1.7  1994/09/28  11:56:13  quinn
11  * Removed const from input to is_merge
12  *
13  * Revision 1.6  1994/09/28  11:29:28  quinn
14  * Added cmp parameter.
15  *
16  * Revision 1.5  1994/09/27  20:03:36  quinn
17  * Seems relatively bug-free.
18  *
19  * Revision 1.4  1994/09/26  17:05:54  quinn
20  * Trivial.
21  *
22  * Revision 1.3  1994/09/26  16:08:42  quinn
23  * Most of the functionality in place.
24  *
25  * Revision 1.2  1994/09/14  13:10:35  quinn
26  * Small changes
27  *
28  * Revision 1.1  1994/09/12  08:02:07  quinn
29  * Not functional yet
30  *
31  */
32
33 #ifndef ISAM_H
34 #define ISAM_H
35
36 #include <bfile.h>
37
38 #include "../isam/memory.h"
39 #include "../isam/physical.h"
40
41 #define IS_MAX_BLOCKTYPES 4
42 #define IS_MAX_RECORD 512
43 #define IS_DEF_REPACK_PERCENT "30" /* how much relative change before repack */
44
45 typedef unsigned int SYSNO; /* should be somewhere else */
46
47 /*
48  * Description of a blocktype (part of an isam file)
49  */
50 typedef struct isam_blocktype
51 {
52     BFile bf;                    /* blocked file */
53     int blocksize;
54     int first_block;             /* position of first data block */
55     int max_keys_block;          /* max num of keys per block */
56     int max_keys_block0;         /* max num of keys in first block */
57     int nice_keys_block;         /* nice number of keys per block */
58     int max_keys;                /* max number of keys per table */
59     int freelist;                /* first free block */
60     int top;                     /* first unused block */
61     int index;                   /* placeholder. Always 0. */
62     char *dbuf;                  /* buffer for use in I/O operations */
63 } isam_blocktype;
64
65 /*
66  * Handle to an open isam complex.
67  */
68 typedef struct isam_struct
69 {
70     isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */
71     int num_types;                /* number of block types used */
72     int writeflag;
73     int keysize;                  /* size of the keys (records) used */
74     int repack;                   /* how many percent to grow before repack */
75     int (*cmp)(const void *k1, const void *k2); /* compare function */
76 } isam_struct;
77
78 typedef struct ispt_struct
79 {
80     struct is_mtable tab;
81     struct ispt_struct *next;      /* freelist */
82 } ispt_struct, *ISPT; 
83
84 #define is_type(x) ((x) & 3)      /* type part of position */
85 #define is_block(x) ((x) >> 2)     /* block # part of position */
86
87 #define is_keysize(is) ((is)->keysize)
88
89 /*
90  * Public Prototypes.
91  *******************************************************************
92  */
93
94 /*
95  * Open isam file.
96  */
97 ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
98     int writeflag);
99
100 /*
101  * Close isam file.
102  */
103 int is_close(ISAM is);
104
105 /*
106  * Locate a table of keys in an isam file. The ISPT is an individual
107  * position marker for that table.
108  */
109 ISPT is_position(ISAM is, ISAM_P pos);
110
111 /*
112  * Release ISPT.
113  */
114 void is_pt_free(ISPT ip);
115
116 /*
117  * Read a key from a table.
118  */
119 int is_readkey(ISPT ip, void *buf);
120
121 int is_writekey(ISPT ip, const void *buf);
122
123 ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data);
124
125 #endif