00001 #ifndef SEARCH_EDGE__ 00002 #define SEARCH_EDGE__ 00003 00004 #include "lm/state.hh" 00005 #include "search/header.hh" 00006 #include "search/types.hh" 00007 #include "search/vertex.hh" 00008 #include "util/pool.hh" 00009 00010 #include <functional> 00011 00012 #include <stdint.h> 00013 00014 namespace search { 00015 00016 // Copyable, but the copy will be shallow. 00017 class PartialEdge : public Header { 00018 public: 00019 // Allow default construction for STL. 00020 PartialEdge() {} 00021 00022 PartialEdge(util::Pool &pool, Arity arity) 00023 : Header(pool.Allocate(Size(arity, arity + 1)), arity) {} 00024 00025 PartialEdge(util::Pool &pool, Arity arity, Arity chart_states) 00026 : Header(pool.Allocate(Size(arity, chart_states)), arity) {} 00027 00028 // Non-terminals 00029 const PartialVertex *NT() const { 00030 return reinterpret_cast<const PartialVertex*>(After()); 00031 } 00032 PartialVertex *NT() { 00033 return reinterpret_cast<PartialVertex*>(After()); 00034 } 00035 00036 const lm::ngram::ChartState &CompletedState() const { 00037 return *Between(); 00038 } 00039 const lm::ngram::ChartState *Between() const { 00040 return reinterpret_cast<const lm::ngram::ChartState*>(After() + GetArity() * sizeof(PartialVertex)); 00041 } 00042 lm::ngram::ChartState *Between() { 00043 return reinterpret_cast<lm::ngram::ChartState*>(After() + GetArity() * sizeof(PartialVertex)); 00044 } 00045 00046 private: 00047 static std::size_t Size(Arity arity, Arity chart_states) { 00048 return kHeaderSize + arity * sizeof(PartialVertex) + chart_states * sizeof(lm::ngram::ChartState); 00049 } 00050 }; 00051 00052 00053 } // namespace search 00054 #endif // SEARCH_EDGE__