summaryrefslogtreecommitdiff
path: root/klm/search/edge.hh
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-09-11 14:30:16 +0100
committerKenneth Heafield <github@kheafield.com>2012-09-11 14:31:42 +0100
commit58d7f847cd5b3c56682e834a2d9b897c6943fafc (patch)
tree04b370b0d92240a4a60dbf921548c927e0a5f00d /klm/search/edge.hh
parent7aa4baf365a80380bebacfc4d4a1ef1b9d757590 (diff)
Add search library to cdec (not used yet)
Diffstat (limited to 'klm/search/edge.hh')
-rw-r--r--klm/search/edge.hh54
1 files changed, 54 insertions, 0 deletions
diff --git a/klm/search/edge.hh b/klm/search/edge.hh
new file mode 100644
index 00000000..4d2a5cbf
--- /dev/null
+++ b/klm/search/edge.hh
@@ -0,0 +1,54 @@
+#ifndef SEARCH_EDGE__
+#define SEARCH_EDGE__
+
+#include "lm/state.hh"
+#include "search/arity.hh"
+#include "search/rule.hh"
+#include "search/types.hh"
+#include "search/vertex.hh"
+
+#include <queue>
+
+namespace search {
+
+class Edge {
+ public:
+ Edge() {
+ end_to_ = to_;
+ }
+
+ Rule &InitRule() { return rule_; }
+
+ void Add(Vertex &vertex) {
+ assert(end_to_ - to_ < kMaxArity);
+ *(end_to_++) = &vertex;
+ }
+
+ const Vertex &GetVertex(std::size_t index) const {
+ return *to_[index];
+ }
+
+ const Rule &GetRule() const { return rule_; }
+
+ private:
+ // Rule and pointers to rule arguments.
+ Rule rule_;
+
+ Vertex *to_[kMaxArity];
+ Vertex **end_to_;
+};
+
+struct PartialEdge {
+ Score score;
+ // Terminals
+ lm::ngram::ChartState between[kMaxArity + 1];
+ // Non-terminals
+ PartialVertex nt[kMaxArity];
+
+ bool operator<(const PartialEdge &other) const {
+ return score < other.score;
+ }
+};
+
+} // namespace search
+#endif // SEARCH_EDGE__