00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef OR_TOOLS_BASE_BITMAP_H_
00015 #define OR_TOOLS_BASE_BITMAP_H_
00016
00017 #include <string.h>
00018 #include "base/basictypes.h"
00019 #include "util/bitset.h"
00020
00021 namespace operations_research {
00022
00023 class Bitmap {
00024 public:
00025
00026
00027 explicit Bitmap(uint32 size, bool fill = false)
00028 : max_size_(size),
00029 array_size_(BitLength64(size)),
00030 map_(new uint64[array_size_]) {
00031
00032 SetAll(fill);
00033 }
00034
00035
00036 ~Bitmap() {
00037 delete [] map_;
00038 }
00039
00040
00041
00042
00043 void Resize(uint32 size, bool fill = false);
00044
00045 bool Get(uint32 index) const {
00046 assert(max_size_ == 0 || index < max_size_);
00047 return IsBitSet64(map_, index);
00048 }
00049 void Set(uint32 index, bool value) {
00050 assert(max_size_ == 0 || index < max_size_);
00051 if ( value ) {
00052 SetBit64(map_, index);
00053 } else {
00054 ClearBit64(map_, index);
00055 }
00056 }
00057
00058
00059 void SetAll(bool value) {
00060 memset(map_, (value ? 0xFF : 0x00), array_size_ * sizeof(*map_));
00061 }
00062
00063
00064 void Clear() { SetAll(false); }
00065
00066 private:
00067 uint32 max_size_;
00068 uint32 array_size_;
00069 uint64* map_;
00070 };
00071
00072 }
00073
00074 #endif // OR_TOOLS_BASE_BITMAP_H_