Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_BitVec_h 00002 #define _included_BitVec_h 00003 00009 #include <limits.h> 00010 #include <iostream.h> 00011 #include <assert.h> 00012 00013 #include "DAGHDefaults.h" 00014 00015 #ifndef ByteWidth 00016 #define ByteWidth (8) 00017 #endif 00018 00019 /* typedef int char BitVecType; */ 00020 typedef int BitVecType; 00021 00022 #ifndef MaxBitVecSlots 00023 #define MaxBitVecSlots (4) 00024 #endif 00025 00036 class BitVec 00037 { 00038 00039 int length; 00040 short int slots; 00041 short int slot_width; 00042 BitVecType bvec[MaxBitVecSlots]; 00043 00044 private: 00045 00046 inline int GetSlot(const int loc) const 00047 {return loc/slot_width;} 00048 inline int MaskBit(const int loc) const 00049 {return (int)1 << (slot_width-(loc%slot_width)-1);} 00050 00051 public: 00052 00053 inline BitVec() 00054 : length(0), slots(0) 00055 {slot_width = (sizeof(BitVecType)*ByteWidth);} 00056 00059 BitVec(const int len); 00060 BitVec(BitVec const &other) 00061 : length(other.length), slots(other.slots), 00062 slot_width(other.slot_width) 00063 { for(register int i=0;i<slots;i++) bvec[i] = other.bvec[i]; } 00064 00065 00066 inline ~BitVec() {} 00067 00069 BitVec const &operator= (BitVec const &other); 00070 00071 int operator==(BitVec const &other) const; 00072 int operator!=(BitVec const &other) const; 00073 int operator>(BitVec const &other) const; 00074 int operator<(BitVec const &other) const; 00075 int operator>=(BitVec const &other) const; 00076 int operator<=(BitVec const &other) const; 00077 00078 inline int TestBit(const int loc) const 00079 { 00080 assert(loc >= 0 && loc < length); 00081 return(bvec[GetSlot(loc)] & MaskBit(loc)); 00082 } 00083 inline void SetBit(const int loc) 00084 { 00085 assert(loc >= 0 && loc < length); 00086 bvec[GetSlot(loc)] |= MaskBit(loc); 00087 } 00088 inline void UnsetBit(const int loc) 00089 { 00090 assert(loc >= 0 && loc < length); 00091 bvec[GetSlot(loc)] &= ~MaskBit(loc); 00092 } 00093 inline void ToggleBit(const int loc) 00094 { 00095 assert(loc >= 0 && loc < length); 00096 bvec[GetSlot(loc)] ^= MaskBit(loc); 00097 } 00100 void SwapBit(const int loc1, const int loc2); 00101 00103 int IsolateBit(const int loc, const int num=1) const; 00104 00105 inline void ResetVec(void) 00106 { register int i; for(i=0;i<slots;i++) bvec[i] = 0;} 00107 00108 inline void SetVec(void) 00109 { register int i; for(i=0;i<slots;i++) bvec[i] = (2<<slot_width) - 1; } 00110 00111 00112 00113 inline int GetLength(void) const 00114 {return length;} 00115 inline int GetSlotWidth(void) const 00116 {return slot_width;} 00117 inline int GetSlots(void) const 00118 {return slots;} 00119 00120 }; 00121 00122 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04