diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-10-14 10:46:34 +0100 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-10-14 10:46:34 +0100 |
commit | f568b392f82fd94b788a1b38094855234d318205 (patch) | |
tree | 37c09a6c2a006afd719e04009b0908117960354a /klm/search/vertex.hh | |
parent | b7005385f267596436dd07b1a9e798023ef1c30a (diff) |
Update to faster but less cute search
Diffstat (limited to 'klm/search/vertex.hh')
-rw-r--r-- | klm/search/vertex.hh | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/klm/search/vertex.hh b/klm/search/vertex.hh index 7ef29efc..e1a9ad11 100644 --- a/klm/search/vertex.hh +++ b/klm/search/vertex.hh @@ -16,8 +16,6 @@ namespace search { class ContextBase; -class Edge; - class VertexNode { public: VertexNode() : end_(NULL) {} @@ -103,6 +101,10 @@ class PartialVertex { unsigned char Length() const { return back_->Length(); } + bool HasAlternative() const { + return index_ + 1 < back_->Size(); + } + // Split into continuation and alternative, rendering this the alternative. bool Split(PartialVertex &continuation) { assert(!Complete()); @@ -128,35 +130,26 @@ extern PartialVertex kBlankPartialVertex; class Vertex { public: - Vertex() -#ifdef DEBUG - : finished_adding_(false) -#endif - {} - - void Add(Edge &edge) { -#ifdef DEBUG - assert(!finished_adding_); -#endif - edges_.push_back(&edge); - } - - void FinishedAdding() { -#ifdef DEBUG - assert(!finished_adding_); - finished_adding_ = true; -#endif - } + Vertex() {} PartialVertex RootPartial() const { return PartialVertex(root_); } + const Final *BestChild() const { + PartialVertex top(RootPartial()); + if (top.Empty()) { + return NULL; + } else { + PartialVertex continuation; + while (!top.Complete()) { + top.Split(continuation); + top = continuation; + } + return &top.End(); + } + } + private: friend class VertexGenerator; - std::vector<Edge*> edges_; - -#ifdef DEBUG - bool finished_adding_; -#endif VertexNode root_; }; |