mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-08 04:27:53 +03:00
71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
/*
|
|
* ArcList.cpp
|
|
*
|
|
* Created on: 26 Oct 2015
|
|
* Author: hieu
|
|
*/
|
|
#include <iostream>
|
|
#include <boost/foreach.hpp>
|
|
#include "ArcLists.h"
|
|
#include "util/exception.hh"
|
|
|
|
using namespace std;
|
|
|
|
ArcLists::ArcLists() {
|
|
// TODO Auto-generated constructor stub
|
|
|
|
}
|
|
|
|
ArcLists::~ArcLists() {
|
|
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
|
|
const ArcList *arcList = collPair.second;
|
|
delete arcList;
|
|
}
|
|
}
|
|
|
|
void ArcLists::AddArc(bool added, const Hypothesis *currHypo,const Hypothesis *otherHypo)
|
|
{
|
|
//cerr << added << " " << currHypo << " " << otherHypo << endl;
|
|
if (added) {
|
|
// we're winners!
|
|
ArcList *arcList;
|
|
if (otherHypo) {
|
|
// there was a existing losing hypo
|
|
arcList = GetAndDetachArcList(otherHypo);
|
|
arcList->push_back(otherHypo);
|
|
}
|
|
else {
|
|
// there was no existing hypo
|
|
arcList = new ArcList;
|
|
}
|
|
m_coll[currHypo] = arcList;
|
|
}
|
|
else {
|
|
// we're losers!
|
|
// there should be a winner, we're not doing beam pruning
|
|
UTIL_THROW_IF2(otherHypo == NULL, "There must have been a winning hypo");
|
|
ArcList *arcList = GetArcList(otherHypo);
|
|
arcList->push_back(currHypo);
|
|
}
|
|
}
|
|
|
|
ArcList *ArcLists::GetArcList(const Hypothesis *hypo)
|
|
{
|
|
Coll::iterator iter = m_coll.find(hypo);
|
|
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
|
ArcList *arcList = iter->second;
|
|
return arcList;
|
|
}
|
|
|
|
ArcList *ArcLists::GetAndDetachArcList(const Hypothesis *hypo)
|
|
{
|
|
Coll::iterator iter = m_coll.find(hypo);
|
|
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
|
ArcList *arcList = iter->second;
|
|
|
|
m_coll.erase(iter);
|
|
|
|
return arcList;
|
|
}
|
|
|