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