diff options
author | Avneesh Saluja <asaluja@gmail.com> | 2013-03-28 18:28:16 -0700 |
---|---|---|
committer | Avneesh Saluja <asaluja@gmail.com> | 2013-03-28 18:28:16 -0700 |
commit | 3d8d656fa7911524e0e6885647173474524e0784 (patch) | |
tree | 81b1ee2fcb67980376d03f0aa48e42e53abff222 /klm/search/nbest.hh | |
parent | be7f57fdd484e063775d7abf083b9fa4c403b610 (diff) | |
parent | 96fedabebafe7a38a6d5928be8fff767e411d705 (diff) |
fixed conflicts
Diffstat (limited to 'klm/search/nbest.hh')
-rw-r--r-- | klm/search/nbest.hh | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/klm/search/nbest.hh b/klm/search/nbest.hh new file mode 100644 index 00000000..cb7651bc --- /dev/null +++ b/klm/search/nbest.hh @@ -0,0 +1,81 @@ +#ifndef SEARCH_NBEST__ +#define SEARCH_NBEST__ + +#include "search/applied.hh" +#include "search/config.hh" +#include "search/edge.hh" + +#include <boost/pool/object_pool.hpp> + +#include <cstddef> +#include <queue> +#include <vector> + +#include <assert.h> + +namespace search { + +class NBestList; + +class NBestList { + private: + class RevealedRef { + public: + explicit RevealedRef(History history) + : in_(static_cast<NBestList*>(history)), index_(0) {} + + private: + friend class NBestList; + + NBestList *in_; + std::size_t index_; + }; + + typedef GenericApplied<RevealedRef> QueueEntry; + + public: + NBestList(std::vector<PartialEdge> &existing, util::Pool &entry_pool, std::size_t keep); + + Score TopAfterConstructor() const; + + const std::vector<Applied> &Extract(util::Pool &pool, std::size_t n); + + private: + Score Visit(util::Pool &pool, std::size_t index); + + Applied Get(util::Pool &pool, std::size_t index); + + void MoveTop(util::Pool &pool); + + typedef std::vector<Applied> Revealed; + Revealed revealed_; + + typedef std::priority_queue<QueueEntry> Queue; + Queue queue_; +}; + +class NBest { + public: + typedef std::vector<PartialEdge> Combine; + + explicit NBest(const NBestConfig &config) : config_(config) {} + + void Add(std::vector<PartialEdge> &existing, PartialEdge addition) const { + existing.push_back(addition); + } + + NBestComplete Complete(std::vector<PartialEdge> &partials); + + const std::vector<Applied> &Extract(History root); + + private: + const NBestConfig config_; + + boost::object_pool<NBestList> list_pool_; + + util::Pool entry_pool_; +}; + +} // namespace search + +#endif // SEARCH_NBEST__ |