tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
node.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_LATTICE_NODE_HPP)
8#define TETENGO_LATTICE_NODE_HPP
9
10#include <any>
11#include <cassert>
12#include <cstddef>
13#include <vector>
14
15#include <boost/operators.hpp>
16
19
20
21namespace tetengo::lattice
22{
26 class node : public boost::equality_comparable<node>
27 {
28 public:
29 // static functions
30
40 [[nodiscard]] static node bos(const std::vector<int>* p_preceding_edge_costs);
41
54 [[nodiscard]] static node
55 eos(std::size_t preceding_step,
56 const std::vector<int>* p_preceding_edge_costs,
57 std::size_t best_preceding_node,
58 int path_cost);
59
60
61 // constructors and destructor
62
75 constexpr node(
76 const input* p_key,
77 const std::any* p_value,
78 std::size_t index_in_step,
79 std::size_t preceding_step,
80 const std::vector<int>* p_preceding_edge_costs,
81 std::size_t best_preceding_node,
82 int node_cost,
83 int path_cost) :
84 m_p_key{ p_key },
85 m_p_value{ p_value },
86 m_index_in_step{ index_in_step },
87 m_preceding_step{ preceding_step },
88 m_p_preceding_edge_costs{ p_preceding_edge_costs },
89 m_best_preceding_node{ best_preceding_node },
90 m_node_cost{ node_cost },
91 m_path_cost{ path_cost }
92 {}
93
106 constexpr node(
107 const entry_view& entry,
108 std::size_t index_in_step,
109 std::size_t preceding_step,
110 const std::vector<int>* p_preceding_edge_costs,
111 std::size_t best_preceding_node,
112 int path_cost) :
114 p_preceding_edge_costs, best_preceding_node, entry.cost(), path_cost }
115 {}
116
117
118 // functions
119
129 friend constexpr bool operator==(const node& one, const node& another)
130 {
131 return ((!one.p_key() && !another.p_key()) ||
132 (one.p_key() && another.p_key() && *one.p_key() == *another.p_key())) &&
133 one.preceding_step() == another.preceding_step() &&
134 one.best_preceding_node() == another.best_preceding_node() &&
135 one.node_cost() == another.node_cost() && one.path_cost() == another.path_cost();
136 }
137
143 [[nodiscard]] constexpr const input* p_key() const
144 {
145 return m_p_key;
146 }
147
153 [[nodiscard]] constexpr const std::any& value() const
154 {
155 assert(m_p_value);
156 return *m_p_value;
157 }
158
164 [[nodiscard]] constexpr std::size_t index_in_step() const
165 {
166 return m_index_in_step;
167 }
168
174 [[nodiscard]] constexpr std::size_t preceding_step() const
175 {
176 return m_preceding_step;
177 }
178
184 [[nodiscard]] constexpr const std::vector<int>& preceding_edge_costs() const
185 {
186 assert(m_p_preceding_edge_costs);
187 return *m_p_preceding_edge_costs;
188 }
189
195 [[nodiscard]] constexpr std::size_t best_preceding_node() const
196 {
197 return m_best_preceding_node;
198 }
199
205 [[nodiscard]] constexpr int node_cost() const
206 {
207 return m_node_cost;
208 }
209
215 [[nodiscard]] constexpr int path_cost() const
216 {
217 return m_path_cost;
218 }
219
226 [[nodiscard]] bool is_bos() const;
227
228
229 private:
230 // variables
231
232 const input* m_p_key;
233
234 const std::any* m_p_value;
235
236 std::size_t m_index_in_step;
237
238 std::size_t m_preceding_step;
239
240 const std::vector<int>* m_p_preceding_edge_costs;
241
242 std::size_t m_best_preceding_node;
243
244 int m_node_cost;
245
246 int m_path_cost;
247 };
248
249
250}
251
252
253#endif
An entry view.
Definition entry.hpp:110
An entry.
Definition entry.hpp:26
An input.
Definition input.hpp:24
A node.
Definition node.hpp:27
constexpr node(const input *p_key, const std::any *p_value, std::size_t index_in_step, std::size_t preceding_step, const std::vector< int > *p_preceding_edge_costs, std::size_t best_preceding_node, int node_cost, int path_cost)
Creates a node.
Definition node.hpp:75
bool is_bos() const
Returns true is this node is the BOS.
constexpr std::size_t index_in_step() const
Returns the index in the step.
Definition node.hpp:164
constexpr int node_cost() const
Returns the node cost.
Definition node.hpp:205
static node eos(std::size_t preceding_step, const std::vector< int > *p_preceding_edge_costs, std::size_t best_preceding_node, int path_cost)
Returns an EOS (End of Sequence).
static node bos(const std::vector< int > *p_preceding_edge_costs)
Returns the BOS (Beginning of Sequence).
constexpr std::size_t preceding_step() const
Returns the preceding step.
Definition node.hpp:174
friend constexpr bool operator==(const node &one, const node &another)
Returns true if one node is equal to another.
Definition node.hpp:129
constexpr int path_cost() const
Returns the path cost.
Definition node.hpp:215
constexpr const input * p_key() const
Returns the key.
Definition node.hpp:143
constexpr const std::vector< int > & preceding_edge_costs() const
Returns the preceding edge costs.
Definition node.hpp:184
constexpr const std::any & value() const
Returns the value.
Definition node.hpp:153
constexpr node(const entry_view &entry, std::size_t index_in_step, std::size_t preceding_step, const std::vector< int > *p_preceding_edge_costs, std::size_t best_preceding_node, int path_cost)
Creates a node from a vocabulary entry.
Definition node.hpp:106
constexpr std::size_t best_preceding_node() const
Returns the index of the best preceding node.
Definition node.hpp:195
An entry.
An input.
A lattice library.