00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00125 #ifndef lno_bv_RCS_ID
00126 #define lno_bv_RCS_ID
00127 #ifdef _KEEP_RCS_ID
00128 static char *lno_bv_rcs_id = "$Source$ $Revision$";
00129 #endif
00130 #endif
00131
00132 #ifndef _lno_bv_INCLUDED
00133 #define _lno_bv_INCLUDED
00134
00135 #include "defs.h"
00136 #include "cxx_memory.h"
00137
00138 #define UINT64_size 64
00139
00140
00141
00142
00143 class BIT_VECTOR {
00144 UINT _size;
00145 UINT64* _bv;
00146 MEM_POOL *_pool;
00147 public:
00148 BIT_VECTOR() { _size=0; _pool=NULL; _bv=NULL; }
00149 ~BIT_VECTOR() {}
00150 BIT_VECTOR(UINT size, MEM_POOL *pool) {
00151 _size=size;
00152 _bv=CXX_NEW_ARRAY(UINT64, _size/UINT64_size+1, pool);
00153 for (INT i=_size-1; i>=0; i-=64)
00154 _bv[i/UINT64_size] = 0;
00155 _pool=pool;
00156 }
00157 UINT Size() const { return _size; };
00158 void Init(UINT size, MEM_POOL *pool) {
00159 _size=size;
00160 _bv=CXX_NEW_ARRAY(UINT64, _size/UINT64_size+1, pool);
00161 for (INT i=_size-1; i>=0; i-=64)
00162 _bv[i/UINT64_size] = 0;
00163 _pool=pool;
00164 }
00165 void Set(UINT bit_position);
00166 void Reset(UINT bit_position);
00167 BOOL Test(UINT bit_position);
00168 INT Least_Non_Zero();
00169 void Print(FILE *fp) {
00170 for (INT i=_size-1; i>=0; i-=64)
00171 fprintf(fp,"\t0x%16.16llX\n", _bv[i/UINT64_size]);
00172 }
00173 BOOL Intersects(BIT_VECTOR *bv) const {
00174 Is_True(bv->_size==_size,
00175 ("Uncomformable sets in BIT_VECTOR::Intersects\nn"));
00176 for (INT i=_size-1; i>=0; i-=64)
00177 if (_bv[i/UINT64_size] & bv->_bv[i/UINT64_size])
00178 return TRUE;
00179 return FALSE;
00180 }
00181 UINT Pop_Count();
00182 BOOL operator ==(const BIT_VECTOR &bv1) const {
00183 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::==().\n"));
00184 for (INT i=_size-1; i>=0; i-=64)
00185 if (_bv[i/UINT64_size] != bv1._bv[i/UINT64_size])
00186 return FALSE;
00187 return TRUE;
00188 }
00189 BOOL operator !=(const BIT_VECTOR &bv1) const {
00190 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::!=().\n"));
00191 for (INT i=_size-1; i>=0; i-=64)
00192 if (_bv[i/UINT64_size] != bv1._bv[i/UINT64_size])
00193 return TRUE;
00194 return FALSE;
00195 }
00196 BIT_VECTOR& operator &(const BIT_VECTOR &bv1) const {
00197 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::&().\n"));
00198 BIT_VECTOR* r_bv=CXX_NEW(BIT_VECTOR, _pool);
00199 r_bv->Init(_size,_pool);
00200 for (INT i=_size-1; i>=0; i-=64) {
00201 r_bv->_bv[i/UINT64_size] =
00202 _bv[i/UINT64_size] & bv1._bv[i/UINT64_size];
00203 }
00204 return *r_bv;
00205 }
00206 BIT_VECTOR& operator |(const BIT_VECTOR &bv1) const {
00207 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::|().\n"));
00208 BIT_VECTOR* r_bv=CXX_NEW(BIT_VECTOR, _pool);
00209 r_bv->Init(_size,_pool);
00210 for (INT i=_size-1; i>=0; i-=64)
00211 r_bv->_bv[i/UINT64_size] =
00212 _bv[i/UINT64_size] | bv1._bv[i/UINT64_size];
00213 return *r_bv;
00214 }
00215 BIT_VECTOR& operator -(const BIT_VECTOR &bv1) const {
00216 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::-().\n"));
00217 BIT_VECTOR* r_bv=CXX_NEW(BIT_VECTOR, _pool);
00218 r_bv->Init(_size,_pool);
00219 for (INT i=_size-1; i>=0; i-=64)
00220 r_bv->_bv[i/UINT64_size] =
00221 _bv[i/UINT64_size] & ~bv1._bv[i/UINT64_size];
00222 return *r_bv;
00223 }
00224 BIT_VECTOR& operator =(const BIT_VECTOR &bv1) {
00225 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::=().\n"));
00226 for (INT i=_size-1; i>=0; i-=64)
00227 _bv[i/UINT64_size] = bv1._bv[i/UINT64_size];
00228 return *this;
00229 }
00230 BIT_VECTOR& operator ~() const {
00231 BIT_VECTOR* r_bv=CXX_NEW(BIT_VECTOR, _pool);
00232 r_bv->Init(_size,_pool);
00233 for (INT i=_size-1; i>=0; i-=64)
00234 r_bv->_bv[i/UINT64_size]= ~_bv[i/UINT64_size];
00235 return *r_bv;
00236 }
00237 BIT_VECTOR& operator &=(const BIT_VECTOR &bv1) {
00238 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::&=().\n"));
00239 for (INT i=_size-1; i>=0; i-=64)
00240 _bv[i/UINT64_size] &= bv1._bv[i/UINT64_size];
00241 return *this;
00242 }
00243 BIT_VECTOR& operator |=(const BIT_VECTOR &bv1) {
00244 Is_True(bv1._size==_size, ("Uncomformable sets in BIT_VECTOR::|=().\n"));
00245 for (INT i=_size-1; i>=0; i-=64)
00246 _bv[i/UINT64_size] |= bv1._bv[i/UINT64_size];
00247 return *this;
00248 }
00249 };
00250
00251 #endif // _lno_bv_INCLUDED
00252