#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 |
UINT32 * | pInts |
UINT32 * | pMasks |
Definition at line 42 of file htab.h.
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 | ) |
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 | ) |
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().
unsigned int CBitField::nBitsPer [private] |
size_t CBitField::nInts [private] |
unsigned int CBitField::nMask [private] |
unsigned int CBitField::nMaximum [private] |
unsigned int CBitField::nShift [private] |
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().