mosesdecoder/search/edge_generator.hh
Kenneth Heafield 3ced55e33d Put note into PartialEdge, delete edge_queue
Before with pop 25:
real    9m49.480s
user    9m38.389s
sys     0m10.354s

After with pop 25:
real    8m46.553s
user    8m35.138s
sys     0m10.654s
2012-10-17 16:49:41 +01:00

58 lines
1.3 KiB
C++

#ifndef SEARCH_EDGE_GENERATOR__
#define SEARCH_EDGE_GENERATOR__
#include "search/edge.hh"
#include "search/note.hh"
#include "search/types.hh"
#include <queue>
namespace lm {
namespace ngram {
class ChartState;
} // namespace ngram
} // namespace lm
namespace search {
template <class Model> class Context;
class EdgeGenerator {
public:
EdgeGenerator() {}
PartialEdge AllocateEdge(Arity arity) {
return partial_edge_pool_.Allocate(arity);
}
void AddEdge(PartialEdge edge) {
generate_.push(edge);
}
bool Empty() const { return generate_.empty(); }
// Pop. If there's a complete hypothesis, return it. Otherwise return an invalid PartialEdge.
template <class Model> PartialEdge Pop(Context<Model> &context);
template <class Model, class Output> void Search(Context<Model> &context, Output &output) {
unsigned to_pop = context.PopLimit();
while (to_pop > 0 && !generate_.empty()) {
PartialEdge got(Pop(context));
if (got.Valid()) {
output.NewHypothesis(got);
--to_pop;
}
}
output.FinishedSearch();
}
private:
PartialEdgePool partial_edge_pool_;
typedef std::priority_queue<PartialEdge> Generate;
Generate generate_;
};
} // namespace search
#endif // SEARCH_EDGE_GENERATOR__