00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_UTIL_BITSET_H_
00019 #define _DECAF_UTIL_BITSET_H_
00020
00021 #include <decaf/util/Config.h>
00022
00023 #include <string>
00024
00025 namespace decaf {
00026 namespace util {
00027
00046 class DECAF_API BitSet {
00047 private:
00048
00049
00050 unsigned long long* bits;
00051 int bitsSize;
00052
00053
00054 bool needClear;
00055
00056
00057 mutable int actualArrayLength;
00058 mutable bool isLengthActual;
00059
00060 private:
00061
00062 BitSet(unsigned long long* bits, int bitsSize, bool needClear, int actualArrayLength, bool isLengthActual);
00063
00064 public:
00065
00069 BitSet();
00070
00082 BitSet(int bitCount);
00083
00087 BitSet(const BitSet& set);
00088
00092 BitSet& operator= (const BitSet& set);
00093
00094 virtual ~BitSet();
00095
00102 bool operator==(const BitSet& other) const {
00103 return this->equals(other);
00104 }
00105
00112 bool operator!=(const BitSet& other) const {
00113 return !this->equals(other);
00114 }
00115
00116 public:
00117
00127 void AND(const BitSet& set);
00128
00137 void OR(const BitSet& set);
00138
00145 void andNot(const BitSet& set);
00146
00152 int cardinality();
00153
00157 void clear();
00158
00167 void clear(int index);
00168
00181 void clear(int fromIndex, int toIndex);
00182
00194 bool equals(const BitSet& set) const;
00195
00204 void flip(int index);
00205
00218 void flip(int fromIndex, int toIndex);
00219
00231 bool get(int index) const;
00232
00247 BitSet get(int fromIndex, int toIndex) const;
00248
00258 bool intersects(const BitSet& set) const;
00259
00265 bool isEmpty() const;
00266
00273 int length() const;
00274
00286 int nextClearBit(int index) const;
00287
00299 int nextSetBit(int index) const;
00300
00309 void set(int index);
00310
00321 void set(int index, bool value);
00322
00335 void set(int fromIndex, int toIndex);
00336
00351 void set(int fromIndex, int toIndex, bool value);
00352
00359 int size() const;
00360
00370 std::string toString() const;
00371
00384 void XOR(const BitSet& set);
00385
00386 private:
00387
00395 void ensureCapacity(int length);
00396
00405 int getActualArrayLength() const;
00406
00407 };
00408
00409 }}
00410
00411 #endif