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