mosesdecoder/contrib/moses2/SCFG/Stacks.cpp

57 lines
1.1 KiB
C++
Raw Normal View History

2016-02-29 18:51:17 +03:00
#include "Stacks.h"
#include "Stack.h"
2016-04-17 21:33:21 +03:00
using namespace std;
2016-02-29 18:51:17 +03:00
namespace Moses2
{
namespace SCFG
{
2016-05-25 23:02:34 +03:00
Stacks::~Stacks()
{
for (size_t i = 0; i < m_cells.size(); ++i) {
std::vector<Stack*> &inner = m_cells[i];
for (size_t j = 0; j < inner.size(); ++j) {
Stack *stack = inner[j];
delete stack;
}
}
}
2016-02-29 18:51:17 +03:00
2016-04-17 11:47:04 +03:00
void Stacks::Init(SCFG::Manager &mgr, size_t size)
2016-02-29 18:51:17 +03:00
{
2016-03-31 23:00:16 +03:00
m_cells.resize(size);
for (size_t startPos = 0; startPos < size; ++startPos) {
std::vector<Stack*> &inner = m_cells[startPos];
inner.reserve(size - startPos);
for (size_t endPos = startPos; endPos < size; ++endPos) {
2016-04-17 11:47:04 +03:00
inner.push_back(new Stack(mgr));
2016-02-29 18:51:17 +03:00
}
2016-03-31 23:00:16 +03:00
}
2016-02-29 18:51:17 +03:00
}
2016-04-17 21:33:21 +03:00
void Stacks::OutputStacks() const
{
size_t size = m_cells.size();
for (size_t startPos = 0; startPos < size; ++startPos) {
cerr.width(3);
cerr << startPos << " ";
}
cerr << endl;
for (size_t width = 1; width <= size; width++) {
for( size_t space = 0; space < width-1; space++ ) {
cerr << " ";
}
for (size_t startPos = 0; startPos <= size-width; ++startPos) {
cerr.width(3);
cerr << GetStack(startPos, width).GetSize() << " ";
}
cerr << endl;
}
}
2016-02-29 18:51:17 +03:00
}
}