CBitField Class Reference

#include <htab.h>


Public Member Functions

 CBitField (unsigned int max=0)
void Resize (unsigned int max)
 ~CBitField (void)
void ClearAll (void)
void Set (unsigned int i)
void Clear (unsigned int i)
bool IsSet (unsigned int i)

Private Attributes

unsigned int nBitsPer
unsigned int nShift
unsigned int nMask
unsigned int nMaximum
size_t nInts
UINT32pInts
UINT32pMasks


Detailed Description

Definition at line 42 of file htab.h.


Constructor & Destructor Documentation

CBitField::CBitField ( unsigned int  max = 0  ) 

Definition at line 4070 of file funceval.cpp.

References nBitsPer, nInts, nMask, nMaximum, nShift, pInts, pMasks, and Resize().

04071 {
04072     nMaximum = 0;
04073     nInts    = 0;
04074     pInts    = NULL;
04075     pMasks   = NULL;
04076 
04077     nBitsPer = sizeof(UINT32)*8;
04078 
04079     // Calculate Shift
04080     //
04081     nShift = 0;
04082     unsigned int i = 1;
04083     while (i < nBitsPer)
04084     {
04085         nShift++;
04086         i <<= 1;
04087     }
04088 
04089     // Calculate Mask
04090     //
04091     nMask = nBitsPer - 1;
04092 
04093     // Allocate array of UINT32s.
04094     //
04095     Resize(nMaximum_arg);
04096 }

CBitField::~CBitField ( void   ) 

Definition at line 4165 of file funceval.cpp.

References MEMFREE, pInts, and pMasks.

04166 {
04167     pInts  = NULL;
04168     if (pMasks)
04169     {
04170         MEMFREE(pMasks);
04171         pMasks = NULL;
04172     }
04173 }


Member Function Documentation

void CBitField::Clear ( unsigned int  i  ) 

Definition at line 4188 of file funceval.cpp.

References nMask, nMaximum, nShift, pInts, and pMasks.

Referenced by atr_add(), atr_clr(), atr_free(), atr_match1(), Commer(), FUNCTION(), Hearer(), look_atrs1(), and sweep_check().

04189 {
04190     if (i <= nMaximum)
04191     {
04192         pInts[i>>nShift] &= ~pMasks[i&nMask];
04193     }
04194 }

void CBitField::ClearAll ( void   ) 

Definition at line 4175 of file funceval.cpp.

References nInts, and pInts.

Referenced by FUNCTION(), and Resize().

04176 {
04177     memset(pInts, 0, nInts*sizeof(UINT32));
04178 }

bool CBitField::IsSet ( unsigned int  i  ) 

Definition at line 4196 of file funceval.cpp.

References nMask, nMaximum, nShift, pInts, and pMasks.

Referenced by atr_match1(), Commer(), FUNCTION(), Hearer(), room_list(), and sweep_check().

04197 {
04198     if (i <= nMaximum)
04199     {
04200         if (pInts[i>>nShift] & pMasks[i&nMask])
04201         {
04202             return true;
04203         }
04204     }
04205     return false;
04206 }

void CBitField::Resize ( unsigned int  max  ) 

Definition at line 4100 of file funceval.cpp.

References ClearAll(), ISOUTOFMEMORY, MEMALLOC, MEMFREE, MINIMUM_RESIZE, nBitsPer, nInts, nMaximum, nShift, pInts, and pMasks.

Referenced by CBitField(), db_grow(), and FUNCTION().

04101 {
04102     if (  0 < nMaximum_arg
04103        && nMaximum < nMaximum_arg)
04104     {
04105         unsigned int nNewMaximum = nMaximum_arg;
04106 
04107         // This provides some assurances that we are not resizing too often.
04108         //
04109         if (  pMasks
04110            && nNewMaximum < nMaximum + MINIMUM_RESIZE)
04111         {
04112             nNewMaximum = nMaximum + MINIMUM_RESIZE;
04113         }
04114 
04115         size_t  nNewInts = (nNewMaximum+nBitsPer) >> nShift;
04116         UINT32 *pNewMasks = (UINT32 *)MEMALLOC((nNewInts+nBitsPer)
04117                           * sizeof(UINT32));
04118         ISOUTOFMEMORY(pNewMasks);
04119         UINT32 *pNewInts = pNewMasks + nBitsPer;
04120 
04121         // Is this the first sizing or a re-sizing?
04122         //
04123         if (pMasks)
04124         {
04125             // Copy existing masks and bits to the new location, and
04126             // clear the new bits.
04127             //
04128             memcpy(pNewMasks, pMasks, (nInts+nBitsPer)*sizeof(UINT32));
04129             memset(pNewInts + nInts, 0, (nNewInts - nInts)*sizeof(UINT32));
04130 
04131             // Free the previous allocation.
04132             //
04133             MEMFREE(pMasks);
04134 
04135             // A reallocation.
04136             //
04137             nMaximum = nNewMaximum;
04138             nInts    = nNewInts;
04139             pMasks   = pNewMasks;
04140             pInts    = pNewInts;
04141         }
04142         else
04143         {
04144             // First allocation.
04145             //
04146             nMaximum = nNewMaximum;
04147             nInts    = nNewInts;
04148             pMasks   = pNewMasks;
04149             pInts    = pNewInts;
04150 
04151             // Initialize masks by calculating all possible single bits.
04152             //
04153             for (unsigned int i = 0; i < nBitsPer; i++)
04154             {
04155                 pMasks[i] = ((UINT32)1) << i;
04156             }
04157 
04158             // Initialize bits by clearing them all.
04159             //
04160             ClearAll();
04161         }
04162     }
04163 }

void CBitField::Set ( unsigned int  i  ) 

Definition at line 4180 of file funceval.cpp.

References nMask, nMaximum, nShift, pInts, and pMasks.

Referenced by atr_free(), atr_match1(), Commer(), FUNCTION(), Hearer(), look_atrs1(), room_list(), and sweep_check().

04181 {
04182     if (i <= nMaximum)
04183     {
04184         pInts[i>>nShift] |= pMasks[i&nMask];
04185     }
04186 }


Field Documentation

unsigned int CBitField::nBitsPer [private]

Definition at line 44 of file htab.h.

Referenced by CBitField(), and Resize().

size_t CBitField::nInts [private]

Definition at line 48 of file htab.h.

Referenced by CBitField(), ClearAll(), and Resize().

unsigned int CBitField::nMask [private]

Definition at line 46 of file htab.h.

Referenced by CBitField(), Clear(), IsSet(), and Set().

unsigned int CBitField::nMaximum [private]

Definition at line 47 of file htab.h.

Referenced by CBitField(), Clear(), IsSet(), Resize(), and Set().

unsigned int CBitField::nShift [private]

Definition at line 45 of file htab.h.

Referenced by CBitField(), Clear(), IsSet(), Resize(), and Set().

UINT32* CBitField::pInts [private]

Definition at line 49 of file htab.h.

Referenced by CBitField(), Clear(), ClearAll(), IsSet(), Resize(), Set(), and ~CBitField().

UINT32* CBitField::pMasks [private]

Definition at line 50 of file htab.h.

Referenced by CBitField(), Clear(), IsSet(), Resize(), Set(), and ~CBitField().


The documentation for this class was generated from the following files:
Generated on Mon May 28 04:40:24 2007 for MUX by  doxygen 1.4.7