2015-10-20 15:04:35 +03:00
|
|
|
#include <boost/foreach.hpp>
|
2015-10-18 03:19:35 +03:00
|
|
|
#include "Bitmaps.h"
|
|
|
|
#include "Util.h"
|
|
|
|
|
2015-10-20 15:04:35 +03:00
|
|
|
using namespace std;
|
2015-10-18 03:19:35 +03:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2015-10-20 15:04:35 +03:00
|
|
|
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];
|
2015-10-20 15:04:35 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 03:19:35 +03:00
|
|
|
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-18 03:19:35 +03:00
|
|
|
}
|
|
|
|
|
2015-10-25 16:37:59 +03:00
|
|
|
const Bitmap &Bitmaps::GetNextBitmap(const Bitmap &bm, const Range &range)
|
2015-10-18 03:19:35 +03:00
|
|
|
{
|
2015-10-26 12:20:08 +03:00
|
|
|
Bitmap *newBM = new Bitmap(bm, range);
|
2015-10-20 15:04:35 +03:00
|
|
|
|
|
|
|
Coll::const_iterator iter = m_coll.find(newBM);
|
2015-10-18 15:30:02 +03:00
|
|
|
if (iter == m_coll.end()) {
|
2015-10-20 15:04:35 +03:00
|
|
|
m_coll[newBM] = NextBitmaps();
|
2015-10-19 19:22:48 +03:00
|
|
|
return *newBM;
|
|
|
|
} else {
|
2015-10-20 22:16:07 +03:00
|
|
|
delete newBM;
|
|
|
|
return *iter->first;
|
2015-10-20 15:04:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 16:37:59 +03:00
|
|
|
const Bitmap &Bitmaps::GetBitmap(const Bitmap &bm, const Range &range)
|
2015-10-20 15:04:35 +03:00
|
|
|
{
|
|
|
|
Coll::iterator iter = m_coll.find(&bm);
|
|
|
|
assert(iter != m_coll.end());
|
|
|
|
|
2015-10-25 16:07:25 +03:00
|
|
|
const Bitmap *newBM;
|
2015-10-20 15:04:35 +03:00
|
|
|
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
|
|
|
}
|
2015-10-20 15:04:35 +03:00
|
|
|
return *newBM;
|
2015-10-18 03:19:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|