18template <
typename T,
typename Alloc>
19struct resizing_vector :
public std::vector<T, Alloc> {
20 explicit resizing_vector(
21 const T& default_value = T(),
22 const Alloc& allocator = Alloc())
23 : std::vector<T, Alloc>(allocator)
24 , default_value_(default_value)
28 typename std::vector<T, Alloc>::reference operator[](
StateID idx)
30 if (idx >= this->size()) {
31 this->resize(idx + 1, default_value_);
33 return std::vector<T, Alloc>::operator[](idx);
36 typename std::vector<T, Alloc>::const_reference
39 if (idx >= this->size()) {
40 return default_value_;
42 return std::vector<T, Alloc>::operator[](idx);
46 const T default_value_;
49template <
class Element,
class Allocator = std::allocator<Element>>
51 :
public segmented_vector::SegmentedVector<Element, Allocator> {
52 Element default_value_;
55 explicit PerStateStorage(
56 const Element& default_value = Element(),
57 const Allocator& alloc = Allocator())
58 : segmented_vector::SegmentedVector<Element>(alloc)
59 , default_value_(default_value)
63 Element& operator[](
size_t index)
65 if (index >= this->size()) {
66 this->resize(index + 1, default_value_);
68 return segmented_vector::SegmentedVector<Element, Allocator>::
72 const Element& operator[](
size_t index)
const
74 if (index >= this->size()) {
75 return default_value_;
77 return segmented_vector::SegmentedVector<Element, Allocator>::
84 return this->size() == 0;
90 typename Hash = std::hash<StateID>,
91 typename Equal = std::equal_to<StateID>,
92 typename Alloc = std::allocator<std::pair<const StateID, T>>>
96 typename std::unordered_map<StateID, T, Hash, Equal, Alloc>::iterator;
98 explicit StateHashMap(
99 const T& default_value = T(),
100 const Hash& h = Hash(),
101 const Equal& e = Equal(),
102 const Alloc& a = Alloc())
103 : store_(1024, h, e, a)
104 , default_value_(default_value)
110 auto res = store_.emplace(idx, default_value_);
111 return res.first->second;
114 const T& operator[](
StateID idx)
const
116 auto it = store_.find(idx);
117 return it != store_.end() ? it->second : default_value_;
121 bool contains(
StateID idx)
const
123 return store_.find(idx) != store_.end();
129 return store_.size();
135 return store_.empty();
138 void clear() { store_.clear(); }
140 iterator begin() {
return store_.begin(); }
142 iterator end() {
return store_.end(); }
144 iterator erase(iterator it) {
return store_.erase(it); }
146 template <
class Pred>
147 typename std::unordered_map<StateID, T, Hash, Equal, Alloc>::size_type
150 return std::erase_if(store_, pred);
154 std::unordered_map<StateID, T, Hash, Equal, Alloc> store_;
155 const T default_value_;
158template <
typename Alloc>
159class PerStateStorage<bool, Alloc> :
public resizing_vector<bool, Alloc> {
161 using resizing_vector<bool, Alloc>::resizing_vector;
164template <
typename State>
165using StateHashSet = std::unordered_set<State>;
167using StateIDHashSet = std::unordered_set<StateID>;