tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
n_best_iterator.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_LATTICE_NBESTITERATOR_HPP)
8#define TETENGO_LATTICE_NBESTITERATOR_HPP
9
10#include <cstddef>
11#include <functional>
12#include <iterator>
13#include <memory>
14#include <queue>
15#include <vector>
16
17#include <boost/operators.hpp>
18#include <boost/stl_interfaces/iterator_interface.hpp>
19
22
23
24namespace tetengo::lattice
25{
26 class constraint;
27 class lattice;
28
29
33 class cap : public boost::less_than_comparable<cap>
34 {
35 public:
36 // constructors and destructor
37
45 cap(std::vector<node> tail_path, int tail_path_cost, int whole_path_cost);
46
47
48 // functions
49
59 friend bool operator<(const cap& one, const cap& another);
60
66 [[nodiscard]] const std::vector<node>& tail_path() const;
67
73 [[nodiscard]] int tail_path_cost() const;
74
80 [[nodiscard]] int whole_path_cost() const;
81
82
83 private:
84 // variables
85
86 std::vector<node> m_tail_path;
87
88 int m_tail_path_cost;
89
90 int m_whole_path_cost;
91 };
92
93
98 public boost::stl_interfaces::iterator_interface<n_best_iterator, std::forward_iterator_tag, path>
99 {
100 public:
101 // constructors and destructor
102
109
119 n_best_iterator(const lattice& lattice_, node eos_node, std::unique_ptr<constraint>&& p_constraint);
120
121
122 // functions
123
129 [[nodiscard]] const path& operator*() const;
130
136 [[nodiscard]] path& operator*();
137
143 [[nodiscard]] const path* operator->() const;
144
150 [[nodiscard]] path* operator->();
151
161 friend bool operator==(const n_best_iterator& one, const n_best_iterator& another);
162
169
176
177
178 private:
179 // variables
180
181 const lattice* m_p_lattice;
182
183 std::priority_queue<cap, std::vector<cap>, std::greater<cap>> m_caps;
184
185 std::size_t m_eos_hash;
186
187 std::shared_ptr<constraint> m_p_constraint;
188
189 path m_path;
190
191 std::size_t m_index;
192 };
193
194
195}
196
197
198#endif
A cap.
Definition n_best_iterator.hpp:34
cap(std::vector< node > tail_path, int tail_path_cost, int whole_path_cost)
Creates a cap.
int tail_path_cost() const
Returns the tail path cost.
int whole_path_cost() const
Returns the whole path cost.
friend bool operator<(const cap &one, const cap &another)
Returns true if one is less than another.
const std::vector< node > & tail_path() const
Returns the tail path.
A lattice.
Definition lattice.hpp:29
An N-best lattice path iterator.
Definition n_best_iterator.hpp:99
n_best_iterator()
Creates an iterator.
path * operator->()
Returns the pointer to the value.
n_best_iterator & operator++()
Increments the iterator.
path & operator*()
Dereferences the iterator.
n_best_iterator(const lattice &lattice_, node eos_node, std::unique_ptr< constraint > &&p_constraint)
Creates an iterator.
const path * operator->() const
Returns the pointer to the value.
const path & operator*() const
Dereferences the iterator.
n_best_iterator operator++(int)
Postincrements the iterator.
friend bool operator==(const n_best_iterator &one, const n_best_iterator &another)
Returns true when one iterator is equal to another.
A node.
Definition node.hpp:27
A path.
Definition path.hpp:21
A lattice library.
A node.
A path.