BitArray.h

Go to the documentation of this file.
00001 //===-- BitArray.h ----------------------------------------------*- C++ -*-===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef KLEE_UTIL_BITARRAY_H
00011 #define KLEE_UTIL_BITARRAY_H
00012 
00013 namespace klee {
00014 
00015   // XXX would be nice not to have
00016   // two allocations here for allocated
00017   // BitArrays
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 } // End klee namespace
00041 
00042 #endif

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8