Enhance createUniqueName() implementation
Description
The API currently exposes a method for creating a unique name for a designated node : Aidge::Node::createUniqueName(std::string name)
This method appends underscores until the proposed name is unique. The problem is that very deep networks lead to large trails of underscores. This is harmful for debugging with visual editors like Mermaid Live. We propose reformat it, so that it would append a trailing number rather than several underscores.
Code
Here is the current source code :
std::string Aidge::Node::createUniqueName(std::string name){
for (auto graphView : views()){
if (graphView->inView(name)){
return createUniqueName(name.append("_"));
}
}
return name;
}
And here is a proposal for the new implementation :
std::string Aidge::Node::createUniqueName(std::string baseName) {
int index = 0;
bool isInside = true;
std::string newName;
while (isInside)
{
std::string suffix = "_" + std::to_string(index);
newName = (index == 0) ? baseName : baseName + suffix;
isInside = false;
for (auto graphView : views()) {
if (graphView->inView(newName)) {
isInside = true;
break;
}
}
index++;
}
return newName;
}
EDIT : Fixed by @cmoineau !
Edited by Benjamin Halimi