summaryrefslogtreecommitdiff
path: root/klm/search/edge.hh
blob: 4d2a5cbf82df24071ea73abed18155e4ae15197d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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__