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