don't store pointer to TrellisNode

This commit is contained in:
Hieu Hoang 2016-03-19 11:02:57 +00:00
parent fa4b673211
commit 0b3179d4d7
2 changed files with 12 additions and 12 deletions

View File

@ -15,7 +15,7 @@ namespace Moses2 {
std::ostream& operator<<(std::ostream &out, const TrellishNode &node)
{
out << "arcList=" << node.arcList.size() << " " << node.ind;
out << "arcList=" << node.arcList->size() << " " << node.ind;
return out;
}
@ -49,7 +49,7 @@ void TrellisPath::AddNodes(const Hypothesis *hypo, const ArcLists &arcLists)
//cerr << *hypo << endl;
const ArcList *list = arcLists.GetArcList(hypo);
assert(list);
TrellishNode *node = new TrellishNode(*list, 0);
TrellishNode node(*list, 0);
nodes.push_back(node);
// add prev hypos
@ -62,8 +62,8 @@ void TrellisPath::OutputToStream(std::ostream &out, const System &system) const
{
//cerr << "path=" << this << " " << nodes.size() << endl;
for (int i = nodes.size() - 1; i >= 0; --i) {
const TrellishNode *node = nodes[i];
const Hypothesis *hypo = static_cast<const Hypothesis*>(node->arcList[node->ind]);
const TrellishNode &node = nodes[i];
const Hypothesis *hypo = static_cast<const Hypothesis*>((*node.arcList)[node.ind]);
//cerr << "hypo=" << hypo << " " << *hypo << endl;
hypo->GetTargetPhrase().OutputToStream(out);
out << " ";
@ -78,9 +78,9 @@ void TrellisPath::CreateDeviantPaths(TrellisPaths &paths) const
const size_t sizePath = nodes.size();
for (size_t currEdge = prevEdgeChanged + 1 ; currEdge < sizePath ; currEdge++) {
const TrellishNode &node = *nodes[currEdge];
const TrellishNode &node = nodes[currEdge];
assert(node.ind == 0);
const ArcList &arcList = node.arcList;
const ArcList &arcList = *node.arcList;
for (size_t i = 1; i < arcList.size(); ++i) {
const Hypothesis *arcReplace = static_cast<const Hypothesis *>(arcList[i]);

View File

@ -21,23 +21,23 @@ class TrellishNode
friend std::ostream& operator<<(std::ostream &, const TrellishNode &);
public:
const ArcList &arcList;
const ArcList *arcList;
size_t ind;
TrellishNode(const ArcList &varcList, size_t vind)
:arcList(varcList)
:arcList(&varcList)
,ind(vind)
{}
};
class TrellisPath {
public:
std::vector<const TrellishNode *> nodes;
int prevEdgeChanged;
/**< the last node that was wiggled to create this path
std::vector<TrellishNode> nodes;
int prevEdgeChanged;
/**< the last node that was wiggled to create this path
, or NOT_FOUND if this path is the best trans so consist of only hypos
*/
TrellisPath(const Hypothesis *hypo, const ArcLists &arcLists);
/** create path from another path, deviate at edgeIndex by using arc instead,