klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_UTIL_BITARRAY_H
11 #define KLEE_UTIL_BITARRAY_H
12 
13 namespace klee {
14 
15  // XXX would be nice not to have
16  // two allocations here for allocated
17  // BitArrays
18 class BitArray {
19 private:
20  uint32_t *bits;
21 
22 protected:
23  static uint32_t length(unsigned size) { return (size+31)/32; }
24 
25 public:
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
BitArray(unsigned size, bool value=false)
Definition: BitArray.h:26
BitArray(const BitArray &b, unsigned size)
Definition: BitArray.h:29
uint32_t * bits
Definition: BitArray.h:20
void unset(unsigned idx)
Definition: BitArray.h:36
void set(unsigned idx, bool value)
Definition: BitArray.h:37
void set(unsigned idx)
Definition: BitArray.h:35
static uint32_t length(unsigned size)
Definition: BitArray.h:23