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