MALOC  0.1
vset.h
1 /*
2  * ***************************************************************************
3  * MALOC = < Minimal Abstraction Layer for Object-oriented C >
4  * Copyright (C) 1994--2000 Michael Holst
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * rcsid="$Id: vset.h,v 1.10 2002/10/01 21:29:45 mholst Exp $"
21  * ***************************************************************************
22  */
23 
24 /*
25  * ***************************************************************************
26  * File: vset.h < vset.c >
27  *
28  * Purpose: Class Vset: a dynamic set object.
29  *
30  * Author: Michael Holst
31  * ***************************************************************************
32  */
33 
34 #ifndef _VSET_H_
35 #define _VSET_H_
36 
37 #include <maloc/maloc_base.h>
38 
39 #include <maloc/vnm.h>
40 #include <maloc/vmem.h>
41 
42 /*
43  * ***************************************************************************
44  * Class Vset: Parameters and datatypes
45  * ***************************************************************************
46  */
47 
48 /*
49  * ***************************************************************************
50  * Class Vset: Definition
51  * ***************************************************************************
52  */
53 
54 typedef struct Vset {
55 
56  Vmem *vmem; /* the memory manager */
57  int iMadeVmem; /* did i make vmem or was it inherited */
58 
59  int curT; /* the current "T" object in our collection */
60 
61  char nameT[80]; /* name of object we are managing */
62  int sizeT; /* size of the object in bytes */
63 
64  int numBlocks; /* total number of allocated blocks */
65  int numT; /* the global "T" counter -- how many "T"s in list */
66  int prtT; /* for i/o at appropriate block creation/deletion */
67 
68  int maxObjects; /* number of objects to manage (user specified) */
69  int blockPower; /* power of 2 for blocksize (e.g., =10, or =16) */
70  int blockSize; /* blocksize is 2^(blockPower) */
71  int blockMax; /* num blocks = blockMax=(maxObjects/blockSize) */
72  int blockModulo; /* =blockSize-1; for determining which block fast */
73 
74  char **table; /* list of pointers to blocks of storage we manage */
75 
76 } Vset;
77 
78 /*
79  * ***************************************************************************
80  * Class Vset: Inlineable methods (vset.c)
81  * ***************************************************************************
82  */
83 
84 #if !defined(VINLINE_MALOC)
85  int Vset_num(Vset *thee);
86  char *Vset_access(Vset *thee, int i);
87  char *Vset_create(Vset *thee);
88  char *Vset_first(Vset *thee);
89  char *Vset_last(Vset *thee);
90  char *Vset_next(Vset *thee);
91  char *Vset_prev(Vset *thee);
92  char *Vset_peekFirst(Vset *thee);
93  char *Vset_peekLast(Vset *thee);
94  void Vset_destroy(Vset *thee);
95 #else /* if defined(VINLINE_MALOC) */
96 # define Vset_num(thee) ((thee)->numT)
97 # define Vset_access(thee,i) ( \
98  ((i >= 0) && (i < thee->numT)) \
99  ? &((thee)->table[ (i)>>(thee)->blockPower ] \
100  [ (thee)->sizeT*((i)&(thee)->blockModulo) ]) \
101  : VNULL \
102  )
103 # define Vset_create(thee) ( \
104  ( ((((thee)->numT)>>(thee)->blockPower) >= (thee)->numBlocks) \
105  || ((((thee)->numT+1)%(thee)->prtT) == 0) ) \
106  ? (Vset_createLast((thee))) \
107  : (++((thee)->numT), (Vset_access((thee),(thee)->numT-1))) \
108  )
109 # define Vset_first(thee) ( \
110  (thee)->curT = 0, \
111  Vset_access((thee), (thee)->curT) \
112  )
113 # define Vset_last(thee) ( \
114  (thee)->curT = (thee)->numT-1, \
115  Vset_access((thee), (thee)->curT) \
116  )
117 # define Vset_next(thee) ( \
118  (thee)->curT++, \
119  ((thee)->curT < (thee)->numT) \
120  ? Vset_access((thee), (thee)->curT) \
121  : VNULL \
122  )
123 # define Vset_prev(thee) ( \
124  (thee)->curT--, \
125  ((thee)->curT >= 0) \
126  ? Vset_access((thee), (thee)->curT) \
127  : VNULL \
128  )
129 # define Vset_peekFirst(thee) ( \
130  Vset_access((thee), 0) \
131  )
132 # define Vset_peekLast(thee) ( \
133  Vset_access((thee), (thee)->numT-1) \
134  )
135 # define Vset_destroy(thee) ( \
136  ( ((((thee)->numT-1)>>(thee)->blockPower) < (thee)->numBlocks-1) \
137  || ((thee)->numT == 1) || ((((thee)->numT)%(thee)->prtT) == 0) ) \
138  ? (Vset_destroyLast((thee))) : (void)(((thee)->numT)--) \
139  )
140 #endif /* if !defined(VINLINE_MALOC) */
141 
142 /*
143  * ***************************************************************************
144  * Class Vset: Non-Inlineable methods (vset.c)
145  * ***************************************************************************
146  */
147 
148 Vset* Vset_ctor(Vmem *vmem,
149  const char *tname, int tsize, int tmaxNum, int ioKey);
150 void Vset_dtor(Vset **thee);
151 
152 char *Vset_createLast(Vset *thee);
153 void Vset_destroyLast(Vset *thee);
154 void Vset_initData(Vset *thee);
155 void Vset_reset(Vset *thee);
156 void Vset_check(Vset *thee,
157  int *tnum, int *tsize, int *tVecUse, int *tVecMal, int *tVecOhd);
158 
159 void Vset_memChk(Vset *thee);
160 
161 #endif /* _VSET_H_ */
162 
Vset
Definition: vset.h:54
Vmem
Definition: vmem.h:51