vset.h

00001 /*
00002  * ***************************************************************************
00003  * MALOC = < Minimal Abstraction Layer for Object-oriented C >
00004  * Copyright (C) 1994--2000  Michael Holst
00005  * 
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU General Public License as published by the
00008  * Free Software Foundation; either version 2 of the License, or (at your
00009  * option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00014  * See the GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * 
00020  * rcsid="$Id: vset.h,v 1.10 2002/10/01 21:29:45 mholst Exp $"
00021  * ***************************************************************************
00022  */
00023 
00024 /*
00025  * ***************************************************************************
00026  * File:     vset.h    < vset.c >
00027  *
00028  * Purpose:  Class Vset: a dynamic set object.
00029  *
00030  * Author:   Michael Holst
00031  * ***************************************************************************
00032  */
00033 
00034 #ifndef _VSET_H_
00035 #define _VSET_H_
00036 
00037 #include <maloc/maloc_base.h>
00038 
00039 #include <maloc/vnm.h>
00040 #include <maloc/vmem.h>
00041 
00042 /*
00043  * ***************************************************************************
00044  * Class Vset: Parameters and datatypes
00045  * ***************************************************************************
00046  */
00047 
00048 /*
00049  * ***************************************************************************
00050  * Class Vset: Definition
00051  * ***************************************************************************
00052  */
00053 
00054 typedef struct Vset {
00055 
00056     Vmem *vmem;         /* the memory manager                               */
00057     int  iMadeVmem;     /* did i make vmem or was it inherited              */
00058 
00059     int curT;           /* the current "T" object in our collection         */
00060 
00061     char nameT[80];     /* name of object we are managing                   */
00062     int sizeT;          /* size of the object in bytes                      */
00063 
00064     int numBlocks;      /* total number of allocated blocks                 */
00065     int numT;           /* the global "T" counter -- how many "T"s in list  */
00066     int prtT;           /* for i/o at appropriate block creation/deletion   */
00067 
00068     int maxObjects;     /* number of objects to manage (user specified)     */
00069     int blockPower;     /* power of 2 for blocksize (e.g., =10, or =16)     */
00070     int blockSize;      /* blocksize is 2^(blockPower) */
00071     int blockMax;       /* num blocks = blockMax=(maxObjects/blockSize)     */
00072     int blockModulo;    /* =blockSize-1; for determining which block fast   */
00073 
00074     char **table;       /* list of pointers to blocks of storage we manage  */
00075 
00076 } Vset;
00077 
00078 /*
00079  * ***************************************************************************
00080  * Class Vset: Inlineable methods (vset.c)
00081  * ***************************************************************************
00082  */
00083 
00084 #if !defined(VINLINE_MALOC)
00085     int Vset_num(Vset *thee);
00086     char *Vset_access(Vset *thee, int i);
00087     char *Vset_create(Vset *thee);
00088     char *Vset_first(Vset *thee);
00089     char *Vset_last(Vset *thee);
00090     char *Vset_next(Vset *thee);
00091     char *Vset_prev(Vset *thee);
00092     char *Vset_peekFirst(Vset *thee);
00093     char *Vset_peekLast(Vset *thee);
00094     void Vset_destroy(Vset *thee);
00095 #else /* if defined(VINLINE_MALOC) */
00096 #   define Vset_num(thee) ((thee)->numT)
00097 #   define Vset_access(thee,i) ( \
00098         ((i >= 0) && (i < thee->numT)) \
00099         ? &((thee)->table[ (i)>>(thee)->blockPower                 ] \
00100                          [ (thee)->sizeT*((i)&(thee)->blockModulo) ]) \
00101         : VNULL \
00102     )
00103 #   define Vset_create(thee) ( \
00104         (  ((((thee)->numT)>>(thee)->blockPower) >= (thee)->numBlocks) \
00105         || ((((thee)->numT+1)%(thee)->prtT) == 0) ) \
00106         ? (Vset_createLast((thee))) \
00107         : (++((thee)->numT), (Vset_access((thee),(thee)->numT-1))) \
00108     )
00109 #   define Vset_first(thee) ( \
00110         (thee)->curT = 0, \
00111         Vset_access((thee), (thee)->curT) \
00112     )
00113 #   define Vset_last(thee) ( \
00114         (thee)->curT = (thee)->numT-1, \
00115         Vset_access((thee), (thee)->curT) \
00116     )
00117 #   define Vset_next(thee) ( \
00118         (thee)->curT++, \
00119         ((thee)->curT < (thee)->numT) \
00120         ? Vset_access((thee), (thee)->curT) \
00121         : VNULL \
00122     )
00123 #   define Vset_prev(thee) ( \
00124         (thee)->curT--, \
00125         ((thee)->curT >= 0) \
00126         ? Vset_access((thee), (thee)->curT) \
00127         : VNULL \
00128     )
00129 #   define Vset_peekFirst(thee) ( \
00130         Vset_access((thee), 0) \
00131     )
00132 #   define Vset_peekLast(thee) ( \
00133         Vset_access((thee), (thee)->numT-1) \
00134     )
00135 #   define Vset_destroy(thee) ( \
00136         ( ((((thee)->numT-1)>>(thee)->blockPower) < (thee)->numBlocks-1) \
00137           || ((thee)->numT == 1) || ((((thee)->numT)%(thee)->prtT) == 0) ) \
00138         ? (Vset_destroyLast((thee))) : (void)(((thee)->numT)--) \
00139     )
00140 #endif /* if !defined(VINLINE_MALOC) */
00141 
00142 /*
00143  * ***************************************************************************
00144  * Class Vset: Non-Inlineable methods (vset.c)
00145  * ***************************************************************************
00146  */
00147 
00148 Vset* Vset_ctor(Vmem *vmem,
00149     const char *tname, int tsize, int tmaxNum, int ioKey);
00150 void Vset_dtor(Vset **thee);
00151 
00152 char *Vset_createLast(Vset *thee);
00153 void Vset_destroyLast(Vset *thee);
00154 void Vset_initData(Vset *thee);
00155 void Vset_reset(Vset *thee);
00156 void Vset_check(Vset *thee,
00157     int *tnum, int *tsize, int *tVecUse, int *tVecMal, int *tVecOhd);
00158 
00159 void Vset_memChk(Vset *thee);
00160 
00161 #endif /* _VSET_H_ */
00162 
00163 

Generated on Fri Aug 21 15:55:32 2009 for MALOC by  doxygen 1.4.7