diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-10-18 21:54:38 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-10-18 21:54:38 +0400 |
commit | 39664ac8f48c44fa4a81ff63de7ff2d31a956b5e (patch) | |
tree | f0928f6ff3f63bb1f68ca0b08009173a9968d85d /search/vertex.hh | |
parent | 05e91def21d90d848b5f804f2fc9bd974bc496df (diff) |
Support arbitrary arity
Also, some windows fixes in util.
Diffstat (limited to 'search/vertex.hh')
-rw-r--r-- | search/vertex.hh | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/search/vertex.hh b/search/vertex.hh index 2c2e46d3c..52bc1dfe7 100644 --- a/search/vertex.hh +++ b/search/vertex.hh @@ -18,7 +18,7 @@ class ContextBase; class VertexNode { public: - VertexNode() : end_(NULL) {} + VertexNode() {} void InitRoot() { extend_.clear(); @@ -26,7 +26,7 @@ class VertexNode { state_.left.length = 0; state_.right.length = 0; right_full_ = false; - end_ = NULL; + end_ = Final(); } lm::ngram::ChartState &MutableState() { return state_; } @@ -36,19 +36,20 @@ class VertexNode { extend_.push_back(next); } - void SetEnd(Final *end) { end_ = end; } + void SetEnd(Final end) { + assert(!end_.Valid()); + end_ = end; + } - Final &MutableEnd() { return *end_; } - void SortAndSet(ContextBase &context, VertexNode **parent_pointer); // Should only happen to a root node when the entire vertex is empty. bool Empty() const { - return !end_ && extend_.empty(); + return !end_.Valid() && extend_.empty(); } bool Complete() const { - return end_; + return end_.Valid(); } const lm::ngram::ChartState &State() const { return state_; } @@ -62,8 +63,8 @@ class VertexNode { return state_.left.length + state_.right.length; } - // May be NULL. - const Final *End() const { return end_; } + // Will be invalid unless this is a leaf. + const Final End() const { return end_; } const VertexNode &operator[](size_t index) const { return *extend_[index]; @@ -80,7 +81,7 @@ class VertexNode { bool right_full_; Score bound_; - Final *end_; + Final end_; }; class PartialVertex { @@ -96,7 +97,7 @@ class PartialVertex { const lm::ngram::ChartState &State() const { return back_->State(); } bool RightFull() const { return back_->RightFull(); } - Score Bound() const { return Complete() ? back_->End()->Bound() : (*back_)[index_].Bound(); } + Score Bound() const { return Complete() ? back_->End().GetScore() : (*back_)[index_].Bound(); } unsigned char Length() const { return back_->Length(); } @@ -120,8 +121,8 @@ class PartialVertex { return ret; } - const Final &End() const { - return *back_->End(); + const Final End() const { + return back_->End(); } private: @@ -135,16 +136,16 @@ class Vertex { PartialVertex RootPartial() const { return PartialVertex(root_); } - const Final *BestChild() const { + const Final BestChild() const { PartialVertex top(RootPartial()); if (top.Empty()) { - return NULL; + return Final(); } else { PartialVertex continuation; while (!top.Complete()) { top.Split(continuation); } - return &top.End(); + return top.End(); } } |