mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
reuse bitmap key for BitmapContainer
This commit is contained in:
parent
b700f99afb
commit
7d98df2b0c
@ -202,7 +202,7 @@ public:
|
||||
class BitmapContainer
|
||||
{
|
||||
private:
|
||||
WordsBitmap m_bitmap;
|
||||
const WordsBitmap &m_bitmap;
|
||||
HypothesisStackCubePruning &m_stack;
|
||||
HypothesisSet m_hypotheses;
|
||||
BackwardsEdgeSet m_edges;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Bitmaps.h"
|
||||
#include "Util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -26,7 +27,7 @@ const WordsBitmap &Bitmaps::GetNextBitmap(const WordsBitmap &bm, const WordsRang
|
||||
|
||||
Coll::const_iterator iter = m_coll.find(newBM);
|
||||
if (iter == m_coll.end()) {
|
||||
m_coll[newBM];
|
||||
m_coll[newBM] = NextBitmaps();
|
||||
return *newBM;
|
||||
} else {
|
||||
return *iter->first;
|
||||
@ -48,6 +49,7 @@ const WordsBitmap &Bitmaps::GetBitmap(const WordsBitmap &bm, const WordsRange &r
|
||||
}
|
||||
else {
|
||||
// link exist
|
||||
//std::cerr << "link exists" << endl;
|
||||
newBM = iterNext->second;
|
||||
}
|
||||
return *newBM;
|
||||
|
@ -48,6 +48,7 @@ void HypothesisStackCubePruning::RemoveAll()
|
||||
// delete all bitmap accessors;
|
||||
_BMType::iterator iter;
|
||||
for (iter = m_bitmapAccessor.begin(); iter != m_bitmapAccessor.end(); ++iter) {
|
||||
delete iter->first;
|
||||
delete iter->second;
|
||||
}
|
||||
}
|
||||
@ -149,7 +150,8 @@ void HypothesisStackCubePruning::AddInitial(Hypothesis *hypo)
|
||||
"Should have added hypothesis " << *hypo);
|
||||
|
||||
const WordsBitmap &bitmap = hypo->GetWordsBitmap();
|
||||
m_bitmapAccessor[bitmap] = new BitmapContainer(bitmap, *this, m_deterministic);
|
||||
WordsBitmap *newBitmap = new WordsBitmap(bitmap);
|
||||
m_bitmapAccessor[newBitmap] = new BitmapContainer(*newBitmap, *this, m_deterministic);
|
||||
}
|
||||
|
||||
void HypothesisStackCubePruning::PruneToSize(size_t newSize)
|
||||
@ -255,12 +257,13 @@ void HypothesisStackCubePruning::SetBitmapAccessor(const WordsBitmap &newBitmap
|
||||
, const SquareMatrix &futureScore
|
||||
, const TranslationOptionList &transOptList)
|
||||
{
|
||||
_BMType::iterator bcExists = m_bitmapAccessor.find(newBitmap);
|
||||
_BMType::iterator bcExists = m_bitmapAccessor.find(&newBitmap);
|
||||
|
||||
BitmapContainer *bmContainer;
|
||||
if (bcExists == m_bitmapAccessor.end()) {
|
||||
bmContainer = new BitmapContainer(newBitmap, stack, m_deterministic);
|
||||
m_bitmapAccessor[newBitmap] = bmContainer;
|
||||
WordsBitmap *bm = new WordsBitmap(newBitmap);
|
||||
bmContainer = new BitmapContainer(*bm, stack, m_deterministic);
|
||||
m_bitmapAccessor[bm] = bmContainer;
|
||||
} else {
|
||||
bmContainer = bcExists->second;
|
||||
}
|
||||
@ -297,7 +300,7 @@ HypothesisStackCubePruning::AddHypothesesToBitmapContainers()
|
||||
for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) {
|
||||
Hypothesis *h = *iter;
|
||||
const WordsBitmap &bitmap = h->GetWordsBitmap();
|
||||
BitmapContainer *container = m_bitmapAccessor[bitmap];
|
||||
BitmapContainer *container = m_bitmapAccessor[&bitmap];
|
||||
container->AddHypothesis(h);
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include "Hypothesis.h"
|
||||
#include "BitmapContainer.h"
|
||||
#include "HypothesisStack.h"
|
||||
#include "Util.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -36,7 +38,7 @@ class BitmapContainer;
|
||||
class TranslationOptionList;
|
||||
class Manager;
|
||||
|
||||
typedef std::map<WordsBitmap, BitmapContainer*> _BMType;
|
||||
typedef boost::unordered_map<const WordsBitmap*, BitmapContainer*, UnorderedComparer<WordsBitmap>, UnorderedComparer<WordsBitmap> > _BMType;
|
||||
|
||||
/** A stack for phrase-based decoding with cube-pruning. */
|
||||
class HypothesisStackCubePruning : public HypothesisStack
|
||||
|
@ -181,7 +181,7 @@ void SearchCubePruning::CreateForwardTodos(HypothesisStackCubePruning &stack)
|
||||
stack.AddHypothesesToBitmapContainers();
|
||||
|
||||
for (iterAccessor = bitmapAccessor.begin() ; iterAccessor != bitmapAccessor.end() ; ++iterAccessor) {
|
||||
const WordsBitmap &bitmap = iterAccessor->first;
|
||||
const WordsBitmap &bitmap = *iterAccessor->first;
|
||||
BitmapContainer &bitmapContainer = *iterAccessor->second;
|
||||
|
||||
if (bitmapContainer.GetHypothesesSize() == 0) {
|
||||
|
@ -183,26 +183,6 @@ public:
|
||||
return m_bitmap.size();
|
||||
}
|
||||
|
||||
//! transitive comparison of WordsBitmap
|
||||
inline int Compare (const WordsBitmap &compare) const {
|
||||
// -1 = less than
|
||||
// +1 = more than
|
||||
// 0 = same
|
||||
|
||||
size_t thisSize = GetSize()
|
||||
,compareSize = compare.GetSize();
|
||||
|
||||
if (thisSize != compareSize) {
|
||||
return (thisSize < compareSize) ? -1 : 1;
|
||||
}
|
||||
return std::memcmp(
|
||||
&m_bitmap[0], &compare.m_bitmap[0], thisSize * sizeof(bool));
|
||||
}
|
||||
|
||||
bool operator< (const WordsBitmap &compare) const {
|
||||
return Compare(compare) < 0;
|
||||
}
|
||||
|
||||
inline size_t GetEdgeToTheLeftOf(size_t l) const {
|
||||
if (l == 0) return l;
|
||||
while (l && !m_bitmap[l-1]) {
|
||||
@ -271,5 +251,10 @@ public:
|
||||
TO_STRING();
|
||||
};
|
||||
|
||||
inline size_t hash_value(const WordsBitmap &bm)
|
||||
{
|
||||
return bm.hash();
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user