Commit 385b7f62 by xiaotong

bug fix in XLink::Replace

parent 863f4585
......@@ -45,11 +45,11 @@ int main( int argc, const char ** argv )
//_CrtSetBreakAlloc(123);
/* a tiny test */
if(false)
if(true)
SmallTest();
//_CrtDumpMemoryLeaks();
//return 0;
return 0;
if(argc > 1 && !strcmp(argv[1], "-test"))
Test();
......
......@@ -112,6 +112,8 @@ void XLink::ClearOutgoing(XTensor * node)
}
outgo.ClearTail();
outgo.typeID = 0;
outgo.type[0] = 0;
}
/*
......@@ -148,6 +150,8 @@ void XLink::ClearIncoming(XTensor * node)
}
income.ClearTail();
income.typeID = 0;
income.type[0] = 0;
}
/*
......@@ -360,32 +364,34 @@ void XLink::Replace(const XTensor * oldOne, XTensor * newOne)
XLink::ClearOutgoing(newOne);
XLink::ClearIncoming(newOne);
if(newIncome.tailNum < oldOne->income.tailNum){
delete[] newIncome.tails;
newIncome.tails = new XTensor*[oldOne->income.tailNum];
}
/* incoming nodes */
newIncome.SetType(oldOne->income.typeID);
newIncome.head = newOne;
newIncome.tailNum = oldOne->income.tailNum;
memcpy(newIncome.tails, oldOne->income.tails, sizeof(XTensor*) * newIncome.tailNum);
/* update the link to each child node */
for(int i = 0; i < newIncome.tailNum; i++){
XTensor * child = newIncome.tails[i];
XLink &childOutgo = child->outgo;
bool hit = false;
for(int j = 0; j < childOutgo.tailNum; j++){
if(childOutgo.tails[j] == oldOne){
childOutgo.tails[j] = newOne;
hit = true;
break;
}
if(oldOne->income.typeID != 0){
if(newIncome.tailNum < oldOne->income.tailNum){
delete[] newIncome.tails;
newIncome.tails = new XTensor*[oldOne->income.tailNum];
}
newIncome.SetType(oldOne->income.typeID);
newIncome.head = newOne;
newIncome.tailNum = oldOne->income.tailNum;
memcpy(newIncome.tails, oldOne->income.tails, sizeof(XTensor*) * newIncome.tailNum);
/* update the link to each child node */
for(int i = 0; i < newIncome.tailNum; i++){
XTensor * child = newIncome.tails[i];
XLink &childOutgo = child->outgo;
bool hit = false;
for(int j = 0; j < childOutgo.tailNum; j++){
if(childOutgo.tails[j] == oldOne){
childOutgo.tails[j] = newOne;
hit = true;
break;
}
}
if(childOutgo.tailNum > 0){
CheckNTErrors(hit, "No proper node found in child.outgo edge!");
if(childOutgo.tailNum > 0){
CheckNTErrors(hit, "No proper node found in child.outgo edge!");
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论