Google OR-Tools: ortools/base/bitmap.h Source File

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef ORTOOLS_BASE_BITMAP_H_

15#define ORTOOLS_BASE_BITMAP_H_

16

17#include <cassert>

18#include <cstdint>

19#include <cstring>

20

23inline uint64_t OneBit64(int pos) { return uint64_t{1} << pos; }

24inline uint64_t BitPos64(uint64_t pos) { return (pos & 63); }

25inline uint64_t BitOffset64(uint64_t pos) { return (pos >> 6); }

26inline uint64_t BitLength64(uint64_t size) { return ((size + 63) >> 6); }

27inline bool IsBitSet64(const uint64_t* const bitset, uint64_t pos) {

29}

30inline void SetBit64(uint64_t* const bitset, uint64_t pos) {

32}

33inline void ClearBit64(uint64_t* const bitset, uint64_t pos) {

35}

36}

37

39 public:

40

41

42 explicit Bitmap(uint32_t size, bool fill = false)

43 : max_size_(size),

45 map_(new uint64_t[array_size_]) {

46

48 }

49

50

52

53

54

55

56 void Resize(uint32_t size, bool fill = false);

57

58 bool Get(uint32_t index) const {

59 assert(max_size_ == 0 || index < max_size_);

61 }

62 void Set(uint32_t index, bool value) {

63 assert(max_size_ == 0 || index < max_size_);

64 if (value) {

66 } else {

68 }

69 }

70

71

73 memset(map_, (value ? 0xFF : 0x00), array_size_ * sizeof(*map_));

74 }

75

76

78

79 private:

80 uint32_t max_size_;

81 uint32_t array_size_;

82 uint64_t* map_;

83};

84

85}

86

87#endif

void Resize(uint32_t size, bool fill=false)

~Bitmap()

Definition bitmap.h:51

bool Get(uint32_t index) const

Definition bitmap.h:58

void Set(uint32_t index, bool value)

Definition bitmap.h:62

Bitmap(uint32_t size, bool fill=false)

Definition bitmap.h:42

void Clear()

Definition bitmap.h:77

void SetAll(bool value)

Definition bitmap.h:72

void SetBit64(uint64_t *const bitset, uint64_t pos)

Definition bitmap.h:30

uint64_t BitLength64(uint64_t size)

Definition bitmap.h:26

uint64_t OneBit64(int pos)

Definition bitmap.h:23

uint64_t BitPos64(uint64_t pos)

Definition bitmap.h:24

bool IsBitSet64(const uint64_t *const bitset, uint64_t pos)

Definition bitmap.h:27

void ClearBit64(uint64_t *const bitset, uint64_t pos)

Definition bitmap.h:33

uint64_t BitOffset64(uint64_t pos)

Definition bitmap.h:25

uint64_t BitLength64(uint64_t size)