libboloq
A library to replesent binary functions using Binary Decision Diagram.
 全て クラス 名前空間 関数 型定義 ページ
boolean_function.h
1 #pragma once
2 
3 namespace boloq {
4 
8 template<class T>
10 private:
11  using table_type = T;
13  friend std::hash<self_type>;
14 
15 public:
19  using node_ptr = typename table_type::node_ptr;
20 
26  using label_type = typename table_type::node_type::label_type;
27 
28 private:
29  node_ptr _root;
30 
31  static table_type& table() {
32  static table_type instance;
33  return instance;
34  }
35 
36  template<class V, typename R, typename ...Args>
37  R visit_result(const Args& ...args) const {
38  V v(args...);
39  this->accept(v);
40  return v.result();
41  }
42 
43 public:
44 
45  basic_boolean_function() : _root(nullptr) {}
46 
50  explicit basic_boolean_function(const label_type& _label) :
51  _root(table().new_var(_label))
52  {}
53 
57  explicit basic_boolean_function(const node_ptr& r) :
58  _root(r)
59  {}
60 
64  static const self_type one() {
65  return self_type(table().one());
66  }
67 
71  static const self_type zero() {
72  return self_type(table().zero());
73  }
74 
78  self_type ite(const self_type& then_node, const self_type& else_node) const {
79  return self_type(table().ite(_root, then_node._root, else_node._root));
80  }
81 
87  bool operator==(const self_type& o) const {
88  return _root->index() == o._root->index();
89  }
90 
96  bool operator!=(const self_type& o) const {
97  return _root->index() != o._root->index();
98  }
99 
104  return self_type(table().apply_not(_root));
105  }
106 
110  self_type operator&(const self_type& o) const {
111  return self_type(table().apply_and(_root, o._root));
112  }
113 
118  _root = table().apply_and(_root, o._root);
119  return *this;
120  }
121 
125  self_type operator|(const self_type& o) const {
126  return self_type(table().apply_or(_root, o._root));
127  }
128 
133  _root = table().apply_or(_root, o._root);
134  return *this;
135  }
136 
137 
141  self_type operator^(const self_type& o) const {
142  return self_type(table().apply_xor(_root, o._root));
143  }
144 
149  _root = table().apply_xor(_root, o._root);
150  return *this;
151  }
152 
158  template<class V>
159  void accept(V& visitor) const {
160  _root->accept(visitor);
161  }
162 
166  template<class AssignT>
167  bool execute(const AssignT& assign) const {
168  return visit_result<execute_visitor<self_type, AssignT>, bool>(assign);
169  }
170 
174  bool is_wire() const {
175  return visit_result<is_wire_visitor<self_type>, bool>();
176  }
177 
181  bool is_negation() const {
182  return visit_result<is_negation_visitor<self_type>, bool>();
183  }
184 
188  bool is_conjunction() const {
189  return visit_result<is_conjunction_visitor<self_type>, bool>();
190  }
191 
195  bool is_disjunction() const {
196  return visit_result<is_disjunction_visitor<self_type>, bool>();
197  }
198 
203  return visit_result<is_exclusive_disjunction_visitor<self_type>, bool>();
204  }
205 
206 };
207 
212 
213 }
214 
215 namespace std {
216 
217 template<class T>
218 struct hash<boloq::basic_boolean_function<T>> {
219  std::hash<typename boloq::basic_boolean_function<T>::node_ptr> hash_fn;
220  size_t operator()(const boloq::basic_boolean_function<T>& bf) const {
221  return hash_fn(bf._root);
222  }
223 };
224 
225 }
static const self_type one()
0 定節点
Definition: boolean_function.h:64
bool is_negation() const
論理否定を表すかどうかを判定します
Definition: boolean_function.h:181
bool execute(const AssignT &assign) const
論理関数を評価します
Definition: boolean_function.h:167
boloq の名前空間
Definition: boolean_function.h:3
bool is_wire() const
f(x) = x かどうかを判定します
Definition: boolean_function.h:174
二分決定図を操作する基本的なクラスです
Definition: boolean_function.h:9
self_type & operator|=(const self_type &o)
or演算を適用します
Definition: boolean_function.h:132
Definition: boolean_function.h:215
basic_boolean_function(const label_type &_label)
コンストラクタ
Definition: boolean_function.h:50
self_type & operator&=(const self_type &o)
and演算を適用します
Definition: boolean_function.h:117
bool is_conjunction() const
論理積を表すかどうかを判定します
Definition: boolean_function.h:188
basic_boolean_function(const node_ptr &r)
visitor 内で生成するためのコンストラクタ
Definition: boolean_function.h:57
self_type operator&(const self_type &o) const
and演算を行った結果を返します
Definition: boolean_function.h:110
self_type operator^(const self_type &o) const
Definition: boolean_function.h:141
self_type & operator^=(const self_type &o)
or演算を適用します
Definition: boolean_function.h:148
void accept(V &visitor) const
visitorを受理します
Definition: boolean_function.h:159
bool operator!=(const self_type &o) const
違う論理関数を表現しているか比較します
Definition: boolean_function.h:96
self_type ite(const self_type &then_node, const self_type &else_node) const
ITE関数を実行します
Definition: boolean_function.h:78
bool operator==(const self_type &o) const
同じ論理関数を表現しているか比較します
Definition: boolean_function.h:87
bool is_exclusive_disjunction() const
排他的論理和を表すかどうかを判定します
Definition: boolean_function.h:202
bool is_disjunction() const
論理和を表すかどうかを判定します
Definition: boolean_function.h:195
static const self_type zero()
1 定節点
Definition: boolean_function.h:71
typename table_type::node_ptr node_ptr
実際に操作されるノードの型
Definition: boolean_function.h:19
self_type operator~() const
not演算を行った結果を返します
Definition: boolean_function.h:103
self_type operator|(const self_type &o) const
Definition: boolean_function.h:125
typename table_type::node_type::label_type label_type
ラベルの型を表します
Definition: boolean_function.h:26