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