BitArray.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef KLEE_UTIL_BITARRAY_H
00011 #define KLEE_UTIL_BITARRAY_H
00012
00013 namespace klee {
00014
00015
00016
00017
00018 class BitArray {
00019 private:
00020 uint32_t *bits;
00021
00022 protected:
00023 static uint32_t length(unsigned size) { return (size+31)/32; }
00024
00025 public:
00026 BitArray(unsigned size, bool value = false) : bits(new uint32_t[length(size)]) {
00027 memset(bits, value?0xFF:0, sizeof(*bits)*length(size));
00028 }
00029 BitArray(const BitArray &b, unsigned size) : bits(new uint32_t[length(size)]) {
00030 memcpy(bits, b.bits, sizeof(*bits)*length(size));
00031 }
00032 ~BitArray() { delete[] bits; }
00033
00034 bool get(unsigned idx) { return (bool) ((bits[idx/32]>>(idx&0x1F))&1); }
00035 void set(unsigned idx) { bits[idx/32] |= 1<<(idx&0x1F); }
00036 void unset(unsigned idx) { bits[idx/32] &= ~(1<<(idx&0x1F)); }
00037 void set(unsigned idx, bool value) { if (value) set(idx); else unset(idx); }
00038 };
00039
00040 }
00041
00042 #endif