mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-30 23:42:30 +03:00
use pointer for SeenPositionItem
This commit is contained in:
parent
572d7aec03
commit
9942fec457
@ -82,9 +82,10 @@ void QueueItem::CreateNext(
|
||||
if (tpInd + 1 < tps->GetSize()) {
|
||||
|
||||
const SCFG::TargetPhraseImpl &tp = (*tps)[tpInd + 1];
|
||||
SeenPositionItem seenItem(tp, hypoIndColl);
|
||||
SeenPositionItem *seenItem = new (pool.Allocate<SeenPositionItem>()) SeenPositionItem(tp, hypoIndColl);
|
||||
|
||||
bool unseen = seenPositions.Add(seenItem);
|
||||
unseen = true;
|
||||
if (unseen) {
|
||||
QueueItem *item = QueueItem::Create(pool, mgr);
|
||||
item->Init(pool, *symbolBind, *tps, tpInd + 1);
|
||||
@ -103,10 +104,11 @@ void QueueItem::CreateNext(
|
||||
size_t hypoInd = hypoIndColl[i] + 1;
|
||||
|
||||
if (hypoInd < hypos.GetSize()) {
|
||||
SeenPositionItem seenItem(tp, hypoIndColl);
|
||||
seenItem.hypoIndColl[i] = hypoInd;
|
||||
SeenPositionItem *seenItem = new (pool.Allocate<SeenPositionItem>()) SeenPositionItem(tp, hypoIndColl);
|
||||
seenItem->hypoIndColl[i] = hypoInd;
|
||||
|
||||
bool unseen = seenPositions.Add(seenItem);
|
||||
unseen = true;
|
||||
if (unseen) {
|
||||
QueueItem *item = QueueItem::Create(pool, mgr);
|
||||
item->Init(pool, *symbolBind, *tps, tpInd);
|
||||
@ -142,15 +144,42 @@ void SeenPositionItem::Debug(std::ostream &out, const System &system) const
|
||||
}
|
||||
}
|
||||
|
||||
bool SeenPositionItem::operator==(const SeenPositionItem &compare) const
|
||||
{
|
||||
bool ret = (tp == compare.tp);
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hypoIndColl.size() != compare.hypoIndColl.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < hypoIndColl.size(); ++i) {
|
||||
if (hypoIndColl[i] != compare.hypoIndColl[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t SeenPositionItem::hash() const
|
||||
{
|
||||
return hash_value(*this);
|
||||
}
|
||||
|
||||
size_t hash_value(const SeenPositionItem& obj)
|
||||
{
|
||||
size_t ret = boost::hash_value(obj.hypoIndColl);
|
||||
boost::hash_combine(ret, (size_t) obj.tp);
|
||||
size_t ret = (size_t) obj.tp;
|
||||
for (size_t i = 0; i < obj.hypoIndColl.size(); ++i) {
|
||||
boost::hash_combine(ret, obj.hypoIndColl[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
bool SeenPositions::Add(const SeenPositionItem &item)
|
||||
bool SeenPositions::Add(const SeenPositionItem *item)
|
||||
{
|
||||
std::pair<Coll::iterator, bool> ret = m_coll.insert(item);
|
||||
return ret.second;
|
||||
|
@ -99,11 +99,8 @@ public:
|
||||
|
||||
SeenPositionItem(const SCFG::TargetPhraseImpl &vtp, const Vector<size_t> &vhypoIndColl);
|
||||
|
||||
virtual bool operator==(const SeenPositionItem &compare) const
|
||||
{
|
||||
bool ret = (tp == compare.tp) && (hypoIndColl == compare.hypoIndColl);
|
||||
return ret;
|
||||
}
|
||||
bool operator==(const SeenPositionItem &compare) const;
|
||||
size_t hash() const;
|
||||
|
||||
void Debug(std::ostream &out, const System &system) const;
|
||||
|
||||
@ -116,14 +113,15 @@ size_t hash_value(const SeenPositionItem& obj);
|
||||
class SeenPositions
|
||||
{
|
||||
public:
|
||||
bool Add(const SeenPositionItem &item);
|
||||
bool Add(const SeenPositionItem *item);
|
||||
|
||||
void clear()
|
||||
{ m_coll.clear(); }
|
||||
|
||||
|
||||
protected:
|
||||
typedef boost::unordered_set<SeenPositionItem> Coll;
|
||||
typedef boost::unordered_set<const SeenPositionItem*,
|
||||
UnorderedComparer<SeenPositionItem>, UnorderedComparer<SeenPositionItem> > Coll;
|
||||
Coll m_coll;
|
||||
};
|
||||
|
||||
|
@ -25,8 +25,8 @@ namespace SCFG
|
||||
{
|
||||
|
||||
Manager::Manager(System &sys, const TranslationTask &task,
|
||||
const std::string &inputStr, long translationId) :
|
||||
ManagerBase(sys, task, inputStr, translationId)
|
||||
const std::string &inputStr, long translationId)
|
||||
:ManagerBase(sys, task, inputStr, translationId)
|
||||
{
|
||||
|
||||
}
|
||||
@ -78,7 +78,8 @@ void Manager::Decode()
|
||||
Decode(path, stack);
|
||||
//cerr << "AFTER DECODE path=" << path << endl;
|
||||
|
||||
if (startPos == 0 && phraseSize == 2) {
|
||||
if ((startPos == 0 && phraseSize == 2)
|
||||
|| startPos == 2 && phraseSize == 1) {
|
||||
cerr << "STACK:" << endl;
|
||||
stack.Debug(cerr, system);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user