Fixed update bug. Repeated insertion in the same area sometimes caused
[idzebra-moved-to-github.git] / isam / memory.h
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: memory.h,v $
7  * Revision 1.5  1996-03-11 14:52:25  quinn
8  * Fixed update bug. Repeated insertion in the same area sometimes caused
9  * problems.
10  *
11  * Revision 1.4  1995/12/06  15:48:47  quinn
12  * Fixed update-problem.
13  *
14  * Revision 1.3  1994/09/28  16:58:33  quinn
15  * Small mod.
16  *
17  * Revision 1.2  1994/09/27  20:03:52  quinn
18  * Seems relatively bug-free.
19  *
20  * Revision 1.1  1994/09/26  17:12:32  quinn
21  * Back again
22  *
23  * Revision 1.1  1994/09/26  16:07:57  quinn
24  * Most of the functionality in place.
25  *
26  */
27
28 #ifndef MEMORY_H
29 #define MEMORY_H
30
31 extern int is_mbuf_size[3];
32
33 typedef unsigned int ISAM_P;
34
35 /*
36  * Memory buffer. Used to manage records (keys) in memory for
37  * reading and insertion/deletion.
38  */
39 typedef struct is_mbuf
40 {
41     int refcount;
42     int type;
43 #define IS_MBUF_TYPE_SMALL  0
44 #define IS_MBUF_TYPE_MEDIUM 1
45 #define IS_MBUF_TYPE_LARGE  2 
46     int offset;
47     int num;
48     int cur_record;
49     struct is_mbuf *next;
50     char *data;                 /* dummy */
51 } is_mbuf;
52
53 /*
54  * Structure describing the virtual image of a disk block.
55  * (these blocks may grow beyond the blocksize during insertion).
56  */
57 typedef struct is_mblock
58 {
59     int num_records;              /* number of records */
60     int diskpos;                  /* positive if this block is mapped */
61     int nextpos;                  /* pos of nxt blk. Only valid imm aft. rd. */
62     int bread;                    /* number of bytes read */
63     int state;                    /* state of block in rel. to disk block */
64 #define IS_MBSTATE_UNREAD  0          /* block hasn't been read */
65 #define IS_MBSTATE_PARTIAL 1          /* block has been partially read */
66 #define IS_MBSTATE_CLEAN   2          /* block is clean (unmodified) */
67 #define IS_MBSTATE_DIRTY   3          /* block has been modified */
68     is_mbuf *cur_mbuf;
69     is_mbuf *data;                /* data contained in block */
70
71     struct is_mblock *next;       /* next diskblock */
72 } is_mblock;
73
74 typedef struct isam_struct *ISAM;
75 /*
76  * Descriptor for a specific table.
77  */
78 typedef struct is_mtable
79 {
80     int num_records;               /* total number of records */
81     int pos_type;                  /* blocktype */
82     is_mblock *cur_mblock;
83     is_mbuf *last_mbuf;
84     is_mblock *data;               /* blocks contained in this table */
85     ISAM is;
86 } is_mtable;
87
88 is_mblock *xmalloc_mblock();
89 is_mbuf *xmalloc_mbuf(int type);
90 void xfree_mblock(is_mblock *p);
91 void xfree_mblocks(is_mblock *l);
92 void xfree_mbuf(is_mbuf *p);
93 void xfree_mbufs(is_mbuf *l);
94 void xrelease_mblock(is_mblock *p);
95 void is_m_establish_tab(ISAM is, is_mtable *tab, ISAM_P pos);
96 void is_m_release_tab(is_mtable *tab);
97 void is_m_rewind(is_mtable *tab);
98 void is_m_replace_record(is_mtable *tab, const void *rec);
99 int is_m_write_record(is_mtable *tab, const void *rec);
100 void is_m_unread_record(is_mtable *tab);
101 int is_m_read_record(is_mtable *tab, void *buf, int keep);
102 int is_m_seek_record(is_mtable *tab, const void *rec);
103 void is_m_delete_record(is_mtable *tab);
104 int is_m_peek_record(is_mtable *tab, void *rec);
105 int is_m_read_full(is_mtable *tab, is_mblock *mblock);
106 int is_m_num_records(is_mtable *tab);
107
108 #endif