diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-10-18 19:49:54 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-10-18 19:49:54 +0400 |
commit | 05e91def21d90d848b5f804f2fc9bd974bc496df (patch) | |
tree | 8b2e7449c5856f7838f7224692a165afd9bf0b0e /search/vertex_generator.hh | |
parent | bedc7136b830d11f1ef32664038658d44688e032 (diff) |
Change VertexGenerator to batch, Remove kScoreInf
Diffstat (limited to 'search/vertex_generator.hh')
-rw-r--r-- | search/vertex_generator.hh | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/search/vertex_generator.hh b/search/vertex_generator.hh index 96df3e0a8..8122aaa5f 100644 --- a/search/vertex_generator.hh +++ b/search/vertex_generator.hh @@ -1,13 +1,11 @@ #ifndef SEARCH_VERTEX_GENERATOR__ #define SEARCH_VERTEX_GENERATOR__ -#include "search/note.hh" +#include "search/edge.hh" #include "search/vertex.hh" #include <boost/unordered_map.hpp> -#include <queue> - namespace lm { namespace ngram { class ChartState; @@ -18,40 +16,29 @@ namespace search { class ContextBase; class Final; -struct PartialEdge; class VertexGenerator { public: VertexGenerator(ContextBase &context, Vertex &gen); - void NewHypothesis(PartialEdge partial); - - void FinishedSearch() { - root_.under->SortAndSet(context_, NULL); + void NewHypothesis(PartialEdge partial) { + const lm::ngram::ChartState &state = partial.CompletedState(); + std::pair<Existing::iterator, bool> ret(existing_.insert(std::make_pair(hash_value(state), partial))); + if (ret.second && ret.first->second < partial) { + ret.first->second = partial; + } } + void FinishedSearch(); + const Vertex &Generating() const { return gen_; } private: - // Parallel structure to VertexNode. - struct Trie { - Trie() : under(NULL) {} - - VertexNode *under; - boost::unordered_map<uint64_t, Trie> extend; - }; - - Trie &FindOrInsert(Trie &node, uint64_t added, const lm::ngram::ChartState &state, unsigned char left, bool left_full, unsigned char right, bool right_full); - - Final *CompleteTransition(Trie &node, const lm::ngram::ChartState &state, PartialEdge partial); - ContextBase &context_; Vertex &gen_; - Trie root_; - - typedef boost::unordered_map<uint64_t, Final*> Existing; + typedef boost::unordered_map<uint64_t, PartialEdge> Existing; Existing existing_; }; |