blob: 3e2d9ab9a52711ef7148a3087ca970afc3e4e40f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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 */
|