2012-10-15 16:58:33 +04:00
|
|
|
#ifndef SEARCH_EDGE__
|
|
|
|
#define SEARCH_EDGE__
|
|
|
|
|
|
|
|
#include "lm/state.hh"
|
2012-10-18 21:54:38 +04:00
|
|
|
#include "search/header.hh"
|
2012-10-15 16:58:33 +04:00
|
|
|
#include "search/types.hh"
|
|
|
|
#include "search/vertex.hh"
|
2012-10-16 20:35:27 +04:00
|
|
|
#include "util/pool.hh"
|
2012-10-15 16:58:33 +04:00
|
|
|
|
2012-10-16 15:57:18 +04:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-10-15 16:58:33 +04:00
|
|
|
|
|
|
|
namespace search {
|
|
|
|
|
2012-10-16 15:57:18 +04:00
|
|
|
// Copyable, but the copy will be shallow.
|
2012-10-18 21:54:38 +04:00
|
|
|
class PartialEdge : public Header {
|
2012-10-16 15:57:18 +04:00
|
|
|
public:
|
|
|
|
// Allow default construction for STL.
|
2012-10-18 21:54:38 +04:00
|
|
|
PartialEdge() {}
|
2012-10-16 15:57:18 +04:00
|
|
|
|
2012-10-18 21:54:38 +04:00
|
|
|
PartialEdge(util::Pool &pool, Arity arity)
|
|
|
|
: Header(pool.Allocate(Size(arity, arity + 1)), arity) {}
|
|
|
|
|
|
|
|
PartialEdge(util::Pool &pool, Arity arity, Arity chart_states)
|
|
|
|
: Header(pool.Allocate(Size(arity, chart_states)), arity) {}
|
2012-10-17 19:49:41 +04:00
|
|
|
|
2012-10-16 15:57:18 +04:00
|
|
|
// Non-terminals
|
|
|
|
const PartialVertex *NT() const {
|
2012-10-18 21:54:38 +04:00
|
|
|
return reinterpret_cast<const PartialVertex*>(After());
|
2012-10-16 15:57:18 +04:00
|
|
|
}
|
|
|
|
PartialVertex *NT() {
|
2012-10-18 21:54:38 +04:00
|
|
|
return reinterpret_cast<PartialVertex*>(After());
|
2012-10-16 15:57:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const lm::ngram::ChartState &CompletedState() const {
|
|
|
|
return *Between();
|
|
|
|
}
|
|
|
|
const lm::ngram::ChartState *Between() const {
|
2012-10-18 21:54:38 +04:00
|
|
|
return reinterpret_cast<const lm::ngram::ChartState*>(After() + GetArity() * sizeof(PartialVertex));
|
2012-10-16 15:57:18 +04:00
|
|
|
}
|
|
|
|
lm::ngram::ChartState *Between() {
|
2012-10-18 21:54:38 +04:00
|
|
|
return reinterpret_cast<lm::ngram::ChartState*>(After() + GetArity() * sizeof(PartialVertex));
|
2012-10-16 15:57:18 +04:00
|
|
|
}
|
2012-10-15 16:58:33 +04:00
|
|
|
|
2012-10-16 15:57:18 +04:00
|
|
|
private:
|
2012-10-18 21:54:38 +04:00
|
|
|
static std::size_t Size(Arity arity, Arity chart_states) {
|
|
|
|
return kHeaderSize + arity * sizeof(PartialVertex) + chart_states * sizeof(lm::ngram::ChartState);
|
2012-10-16 15:57:18 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-10-15 16:58:33 +04:00
|
|
|
} // namespace search
|
|
|
|
#endif // SEARCH_EDGE__
|