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