Most of the functionality in place.
[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.3  1994-09-26 16:08:42  quinn
8  * Most of the functionality in place.
9  *
10  * Revision 1.2  1994/09/14  13:10:35  quinn
11  * Small changes
12  *
13  * Revision 1.1  1994/09/12  08:02:07  quinn
14  * Not functional yet
15  *
16  */
17
18 #ifndef ISAM_H
19 #define ISAM_H
20
21 #include <bfile.h>
22 #include <isam.h>
23
24 #define IS_MAX_BLOCKTYPES 4
25 #define IS_MAX_RECORD 512
26 #define IS_DEF_REPACK_PERCENT "30" /* how much relative change before repack */
27
28 typedef unsigned int SYSNO; /* should be somewhere else */
29 typedef unsigned int ISAM_P;
30
31 /*
32  * Description of a blocktype (part of an isam file)
33  */
34 typedef struct isam_blocktype
35 {
36     BFile bf;                    /* blocked file */
37     int blocksize;
38     int first_block;             /* position of first data block */
39     int max_keys_block;          /* max num of keys per block */
40     int max_keys_block0;         /* max num of keys in first block */
41     int nice_keys_block;         /* nice number of keys per block */
42     int max_keys;                /* max number of keys per table */
43     int freelist;                /* fist free block */
44     int top;                     /* first unused block */
45     int index;                   /* placeholder. Always 0. */
46     char *dbuf;                  /* buffer for use in I/O operations */
47 } isam_blocktype;
48
49 /*
50  * Handle to an open isam complex.
51  */
52 typedef struct isam_struct
53 {
54     isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */
55     int num_types;                /* number of block types used */
56     int writeflag;
57     int keysize;                  /* size of the keys (records) used */
58     int repack;                   /* how many percent to grow before repack */
59     int (*cmp)(const void *k1, const void *k2); /* compare function */
60 } isam_struct, *ISAM;
61
62 typedef struct ispt_struct
63 {
64     ISAM is;                       /* which file do we belong to? */
65     int ptr;                       /* current key offset */
66
67     struct ispt_struct *next;      /* freelist */
68 } ispt_struct, *ISPT; 
69
70 #define is_type(x) ((x) & 3)      /* type part of position */
71 #define is_block(x) ((x) >> 2)     /* block # part of position */
72
73 #define is_keysize(is) ((is)->keysize)
74
75 /*
76  * Public Prototypes.
77  *******************************************************************
78  */
79
80 /*
81  * Open isam file.
82  */
83 ISAM is_open(const char *name, int writeflag);
84
85 /*
86  * Close isam file.
87  */
88 int is_close(ISAM is);
89
90 /*
91  * Locate a table of keys in an isam file. The ISPT is an individual
92  * position marker for that table.
93  */
94 ISPT is_position(ISAM is, ISAM_P pos);
95
96 /*
97  * Release ISPT.
98  */
99 void is_pt_free(ISPT ip);
100
101 /*
102  * Read a key from a table.
103  */
104 int is_readkey(ISPT ip, void *buf);
105
106 int is_writekey(ISPT ip, const void *buf);
107
108 ISAM_P is_merge(ISAM is, ISAM_P pos, int num, const char *data);
109
110 #endif