mosesdecoder/moses/Bitmaps.cpp

59 lines
1.2 KiB
C++
Raw Normal View History

#include <boost/foreach.hpp>
#include "Bitmaps.h"
#include "Util.h"
using namespace std;
namespace Moses
{
Bitmaps::Bitmaps(size_t inputSize, const std::vector<bool> &initSourceCompleted)
{
2015-10-25 16:07:25 +03:00
m_initBitmap = new Bitmap(inputSize, initSourceCompleted);
2015-10-20 22:16:07 +03:00
m_coll[m_initBitmap];
}
Bitmaps::~Bitmaps()
{
2015-10-20 22:16:07 +03:00
BOOST_FOREACH (const Coll::value_type& myPair, m_coll) {
2015-10-25 16:07:25 +03:00
const Bitmap *bm = myPair.first;
2015-10-20 22:16:07 +03:00
delete bm;
}
}
2015-10-25 16:37:59 +03:00
const Bitmap &Bitmaps::GetNextBitmap(const Bitmap &bm, const Range &range)
{
Bitmap *newBM = new Bitmap(bm, range);
Coll::const_iterator iter = m_coll.find(newBM);
2015-10-18 15:30:02 +03:00
if (iter == m_coll.end()) {
m_coll[newBM] = NextBitmaps();
return *newBM;
} else {
2015-10-20 22:16:07 +03:00
delete newBM;
return *iter->first;
}
}
2015-10-25 16:37:59 +03:00
const Bitmap &Bitmaps::GetBitmap(const Bitmap &bm, const Range &range)
{
Coll::iterator iter = m_coll.find(&bm);
assert(iter != m_coll.end());
2015-10-25 16:07:25 +03:00
const Bitmap *newBM;
NextBitmaps &next = iter->second;
NextBitmaps::const_iterator iterNext = next.find(range);
if (iterNext == next.end()) {
2015-10-20 22:16:07 +03:00
// not seen the link yet.
newBM = &GetNextBitmap(bm, range);
next[range] = newBM;
} else {
// link exist
//std::cerr << "link exists" << endl;
newBM = iterNext->second;
2015-10-18 15:30:02 +03:00
}
return *newBM;
}
}