AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
per_state_bitset.h
1#ifndef PER_STATE_BITSET_H
2#define PER_STATE_BITSET_H
3
4#include "downward/per_state_array.h"
5
6#include <vector>
7
8class BitsetMath {
9public:
10 using Block = unsigned int;
11 static_assert(
12 !std::numeric_limits<Block>::is_signed,
13 "Block type must be unsigned");
14
15 static const Block zeros = Block(0);
16 // MSVC's bitwise negation always returns a signed type.
17 static const Block ones = Block(~Block(0));
18 static const int bits_per_block = std::numeric_limits<Block>::digits;
19
20 static int compute_num_blocks(std::size_t num_bits);
21 static std::size_t block_index(std::size_t pos);
22 static std::size_t bit_index(std::size_t pos);
23 static Block bit_mask(std::size_t pos);
24};
25
26class ConstBitsetView {
27 ConstArrayView<BitsetMath::Block> data;
28 int num_bits;
29
30public:
31 ConstBitsetView(ConstArrayView<BitsetMath::Block> data, int num_bits)
32 : data(data)
33 , num_bits(num_bits)
34 {
35 }
36
37 ConstBitsetView(const ConstBitsetView& other) = default;
38 ConstBitsetView& operator=(const ConstBitsetView& other) = default;
39
40 bool test(int index) const;
41 int size() const;
42};
43
44class BitsetView {
45 ArrayView<BitsetMath::Block> data;
46 int num_bits;
47
48public:
49 BitsetView(ArrayView<BitsetMath::Block> data, int num_bits)
50 : data(data)
51 , num_bits(num_bits)
52 {
53 }
54
55 BitsetView(const BitsetView& other) = default;
56 BitsetView& operator=(const BitsetView& other) = default;
57
58 operator ConstBitsetView() const { return ConstBitsetView(data, num_bits); }
59
60 void set(int index);
61 void reset(int index);
62 void reset();
63 bool test(int index) const;
64 void intersect(const BitsetView& other);
65 int size() const;
66};
67
68class PerStateBitset {
69 int num_bits_per_entry;
70 PerStateArray<BitsetMath::Block> data;
71
72public:
73 explicit PerStateBitset(const std::vector<bool>& default_bits);
74
75 PerStateBitset(const PerStateBitset&) = delete;
76 PerStateBitset& operator=(const PerStateBitset&) = delete;
77
78 BitsetView operator[](const State& state);
79 ConstBitsetView operator[](const State& state) const;
80};
81
82#endif