-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitArray.h
42 lines (34 loc) · 1.25 KB
/
BitArray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//===-- BitArray.h ----------------------------------------------*- C++ -*-===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef KLEE_UTIL_BITARRAY_H
#define KLEE_UTIL_BITARRAY_H
namespace klee {
// XXX would be nice not to have
// two allocations here for allocated
// BitArrays
class BitArray {
private:
uint32_t *bits;
protected:
static uint32_t length(unsigned size) { return (size+31)/32; }
public:
BitArray(unsigned size, bool value = false) : bits(new uint32_t[length(size)]) {
memset(bits, value?0xFF:0, sizeof(*bits)*length(size));
}
BitArray(const BitArray &b, unsigned size) : bits(new uint32_t[length(size)]) {
memcpy(bits, b.bits, sizeof(*bits)*length(size));
}
~BitArray() { delete[] bits; }
bool get(unsigned idx) { return (bool) ((bits[idx/32]>>(idx&0x1F))&1); }
void set(unsigned idx) { bits[idx/32] |= 1<<(idx&0x1F); }
void unset(unsigned idx) { bits[idx/32] &= ~(1<<(idx&0x1F)); }
void set(unsigned idx, bool value) { if (value) set(idx); else unset(idx); }
};
} // End klee namespace
#endif