diff options
Diffstat (limited to 'contrib/moses2/TrellisPaths.h')
-rw-r--r-- | contrib/moses2/TrellisPaths.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/contrib/moses2/TrellisPaths.h b/contrib/moses2/TrellisPaths.h new file mode 100644 index 000000000..3e2d9ab9a --- /dev/null +++ b/contrib/moses2/TrellisPaths.h @@ -0,0 +1,69 @@ +/* + * TrellisPaths.h + * + * Created on: 16 Mar 2016 + * Author: hieu + */ +#pragma once + +#include <vector> +#include <queue> +#include "PhraseBased/TrellisPath.h" + +namespace Moses2 +{ + +template<typename T> +struct CompareTrellisPath +{ + bool operator()(const T* pathA, const T* pathB) const + { + return (pathA->GetFutureScore() < pathB->GetFutureScore()); + } +}; + +template<typename T> +class TrellisPaths +{ +public: + TrellisPaths() {} + + virtual ~TrellisPaths() + { + while (!empty()) { + T *path = Get(); + delete path; + } + } + + bool empty() const + { + return m_coll.empty(); + } + + //! add a new entry into collection + void Add(T *trellisPath) + { + m_coll.push(trellisPath); + } + + T *Get() + { + T *top = m_coll.top(); + + // Detach + m_coll.pop(); + return top; + } + + size_t GetSize() const + { return m_coll.size(); } + +protected: + typedef std::priority_queue<T*, std::vector<T*>, + CompareTrellisPath<T> > CollectionType; + CollectionType m_coll; +}; + +} /* namespace Moses2 */ + |