20 #ifndef LIMI_INTERNAL_META_STATE_H
21 #define LIMI_INTERNAL_META_STATE_H
38 template <
class StateB,
class Symbol,
class Independence = independence<Symbol>>
42 std::vector<Symbol> early_;
43 std::vector<Symbol> late_;
46 typedef typename std::vector<Symbol>::const_iterator vector_iterator;
47 meta_state(StateB inner_state) : inner_state_(inner_state), hash_(std::hash<StateB>()(inner_state)) {}
57 inline StateB inner_state()
const {
return inner_state_; }
59 inline void inner_state(StateB new_inner_state) {
60 hash_ = hash_ ^ std::hash<StateB>()(inner_state_);
61 inner_state_ = new_inner_state;
62 hash_ = hash_ ^ std::hash<StateB>()(inner_state_);
65 inline const std::vector<Symbol>& early()
const {
return early_; }
66 inline const std::vector<Symbol>& late()
const {
return late_; }
68 inline void add_early(
const Symbol& symbol,
const Independence&
independence = Independence()) {
69 hash_ = hash_ ^ std::hash<Symbol>()(symbol);
72 for(position = early_.size()-1; position>=0; --position) {
73 if (symbol > early_[position] || !
independence(symbol, early_[position]))
76 early_.insert(early_.begin()+(position+1), symbol);
79 inline void add_late(
const Symbol& symbol,
const Independence&
independence = Independence()) {
80 hash_ = hash_ ^ ~
std::hash<Symbol>()(symbol);
82 for(position = late_.size()-1; position>=0; --position) {
83 if (symbol > late_[position] || !
independence(symbol, late_[position]))
86 late_.insert(late_.begin()+(position+1), symbol);
89 inline void erase_early(
unsigned position) {
90 hash_ = hash_ ^ std::hash<Symbol>()(early_[position]);
91 early_.erase(early_.begin() + position);
94 inline void erase_late(
unsigned position) {
95 hash_ = hash_ ^ ~
std::hash<Symbol>()(late_[position]);
96 late_.erase(late_.begin() + position);
99 inline unsigned size() {
100 return early_.size();
104 if (&other ==
this)
return true;
105 if (!std::equal_to<StateB>()(inner_state(), other.inner_state()))
107 if (early().size() != other.early().size() || !std::equal(early().begin(), early().end(), other.early().begin(), std::equal_to<Symbol>()))
109 if (late().size() != other.late().size() || !std::equal(late().begin(), late().end(), other.late().begin(), std::equal_to<Symbol>()))
116 template<
class InnerStateB,
class Symbol,
class Independence>
117 struct printer<
std::shared_ptr<Limi::internal::meta_state<InnerStateB, Symbol,Independence>>> :
printer_base<std::shared_ptr<Limi::internal::meta_state<InnerStateB, Symbol,Independence>>> {
120 out <<
"(" << printerS(state->inner_state());
123 internal::print_vector(state->early(), out, printerSy);
125 internal::print_vector(state->late(), out, printerSy);
129 const printer_base<InnerStateB>& printerS;
130 const printer_base<Symbol>& printerSy;
133 template<
class InnerStateB,
class Symbol,
class Independence>
134 std::ostream& operator<<(std::ostream& out, Limi::internal::meta_state<InnerStateB, Symbol,Independence>& state) {
135 out <<
"(" << state.inner_state();
137 internal::print_vector(state.early(), out);
139 internal::print_vector(state.late(), out);
148 template<
class StateB,
class Symbol,
class Independence>
struct hash<
Limi::internal::meta_state<StateB,Symbol,Independence>> {
153 template<
class StateB,
class Symbol,
class Independence>
struct hash<shared_ptr<
Limi::internal::meta_state<StateB,Symbol,Independence>>> {
155 return hash<Limi::internal::meta_state<StateB,Symbol,Independence>>()(*val);
159 template<
class StateB,
class Symbol,
class Independence>
struct equal_to<shared_ptr<
Limi::internal::meta_state<StateB,Symbol,Independence>>> {
161 return equal_to<Limi::internal::meta_state<StateB,Symbol,Independence>>()(*a,*b);
167 #endif // LIMI_INTERNAL_META_STATE_H
The printer base is what custom printers need to inherit from.
Definition: generics.h:81
The main namespace of the library.
Definition: antichain_algo.h:40
Definition: generics.h:30
The template for the independence relation.
Definition: generics.h:53
virtual void print(const Key &item, std::ostream &out) const override
Prints an item to the out stream.
Definition: generics.h:105
The default implementation of Limi::printer_base.
Definition: generics.h:104