From 8e20394691537ca2a0fba4be53d416504d48db15 Mon Sep 17 00:00:00 2001
From: idealbuq <iryna.dealbuquerquesilva@cea.fr>
Date: Tue, 11 Mar 2025 13:56:03 +0000
Subject: [PATCH 1/5] Employ createUniqueName() in the add() function.

---
 src/graph/GraphView.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index b38f92636..182162149 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -683,8 +683,19 @@ void Aidge::GraphView::add(std::shared_ptr<Node> node, bool includeLearnablePara
   // add to the GraphView nodes
   node->addView(shared_from_this());
   mNodes.insert(node);
-  if (!(node->name()).empty())
-    mNodeRegistry.insert(std::make_pair(node->name(), node));
+  if (!(node->name()).empty()) { 
+    if (mNodeRegistry.find(node->name()) != mNodeRegistry.end()) {
+      std::string newName = node->createUniqueName(node->name());
+      while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
+          newName = node->createUniqueName(newName + "_1"); 
+      }
+      Log::notice("node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
+      node->setName(newName);
+    }
+    else {
+      mNodeRegistry.insert(std::make_pair(node->name(), node));
+    }
+  }
 
   // check if the node is an input/output node
   updateInputsOutputsNew(node);
-- 
GitLab


From d38a7d11d256484c9ba1392ce24c965a9bf5546e Mon Sep 17 00:00:00 2001
From: idealbuq <iryna.dealbuquerquesilva@cea.fr>
Date: Fri, 14 Mar 2025 13:31:16 +0000
Subject: [PATCH 2/5] Corrected logic of creating unique names in the
 GraphView.add() method.

---
 src/graph/GraphView.cpp | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index 182162149..ad70862ec 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -37,6 +37,7 @@
 #include "aidge/utils/ErrorHandling.hpp"
 #include "aidge/utils/Types.h"
 
+#include <cstdio>  // Include cstdio for printf
 
 const std::shared_ptr<Aidge::Node> Aidge::GraphView::operator[](const std::string& nodeName) const {
     return (mNodeRegistry.find(nodeName) != mNodeRegistry.cend()) ? mNodeRegistry.at(nodeName) : nullptr;
@@ -680,20 +681,37 @@ void Aidge::GraphView::add(std::shared_ptr<Node> node, bool includeLearnablePara
     mRootNode = node;
   }
 
-  // add to the GraphView nodes
+  // Add to the GraphView nodes
   node->addView(shared_from_this());
   mNodes.insert(node);
   if (!(node->name()).empty()) { 
-    if (mNodeRegistry.find(node->name()) != mNodeRegistry.end()) {
-      std::string newName = node->createUniqueName(node->name());
-      while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
-          newName = node->createUniqueName(newName + "_1"); 
+    // Check if a node with the same name exists in the registry
+    auto it = mNodeRegistry.find(node->name());
+    if (it != mNodeRegistry.end()) {
+      // Found a node with the same name, check if it's the same node (by memory address)
+      if (it->second == node) {  
+        Log::debug("Node \"{}\" is already registered and is the same instance. Skipping insertion.\n", node->name());
+      } else {
+          // Different instance with the same name – generate an unique name      
+          std::string newName = node->createUniqueName(node->name());
+          
+          while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
+              newName = node->createUniqueName(newName + "_1"); 
+          }
+          
+          Log::notice("Node name \"{}\" is a duplicate, renaming it to {}.\n", node->name(), newName);
+          node->setName(newName);
+
+          // Insert the renamed node
+          mNodeRegistry.insert(std::make_pair(node->name(), node));
+          Log::debug("Inserted renamed node \"{}\" into registry.\n", node->name());
+
       }
-      Log::notice("node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
-      node->setName(newName);
-    }
-    else {
-      mNodeRegistry.insert(std::make_pair(node->name(), node));
+
+    } else {
+        // No duplicate found, insert the node with its original name
+        mNodeRegistry.insert(std::make_pair(node->name(), node));
+        Log::debug("Inserted node \"{}\" into registry.\n", node->name());
     }
   }
 
-- 
GitLab


From 6716d3f42ec5e0bbb828e5255d9539cd9c461bfb Mon Sep 17 00:00:00 2001
From: idealbuq <iryna.dealbuquerquesilva@cea.fr>
Date: Fri, 14 Mar 2025 14:12:07 +0000
Subject: [PATCH 3/5] Added actual pointer comparison while creating unique
 names in the GraphView.add() method.

---
 src/graph/GraphView.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index ad70862ec..066832520 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -688,8 +688,8 @@ void Aidge::GraphView::add(std::shared_ptr<Node> node, bool includeLearnablePara
     // Check if a node with the same name exists in the registry
     auto it = mNodeRegistry.find(node->name());
     if (it != mNodeRegistry.end()) {
-      // Found a node with the same name, check if it's the same node (by memory address)
-      if (it->second == node) {  
+      // Found a node with the same name, check if it's the same node pointer
+      if (it->second.get() == node.get()) {  
         Log::debug("Node \"{}\" is already registered and is the same instance. Skipping insertion.\n", node->name());
       } else {
           // Different instance with the same name – generate an unique name      
-- 
GitLab


From f4f694c66b6a35b53b7be0a5abf022f50df90002 Mon Sep 17 00:00:00 2001
From: idealbuq <iryna.dealbuquerquesilva@cea.fr>
Date: Mon, 17 Mar 2025 15:46:38 +0000
Subject: [PATCH 4/5] Removed unnecessary while-loop when checking for
 duplicate node names.

---
 src/graph/GraphView.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index 066832520..b0704e0e9 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -694,11 +694,7 @@ void Aidge::GraphView::add(std::shared_ptr<Node> node, bool includeLearnablePara
       } else {
           // Different instance with the same name – generate an unique name      
           std::string newName = node->createUniqueName(node->name());
-          
-          while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
-              newName = node->createUniqueName(newName + "_1"); 
-          }
-          
+                    
           Log::notice("Node name \"{}\" is a duplicate, renaming it to {}.\n", node->name(), newName);
           node->setName(newName);
 
-- 
GitLab


From 5916d89ecb9da063c3edb61c3063223697e03460 Mon Sep 17 00:00:00 2001
From: idealbuq <iryna.dealbuquerquesilva@cea.fr>
Date: Tue, 18 Mar 2025 09:52:42 +0000
Subject: [PATCH 5/5] Removed redudant code in GraphView's add() methods.

---
 src/graph/GraphView.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp
index b0704e0e9..3f146c745 100644
--- a/src/graph/GraphView.cpp
+++ b/src/graph/GraphView.cpp
@@ -857,10 +857,7 @@ bool Aidge::GraphView::add(std::set<std::shared_ptr<Node>> otherNodes, bool incl
   for (auto node : nodesToAdd) {
     if (mNodeRegistry.find(node->name()) != mNodeRegistry.end()) {
         std::string newName = node->createUniqueName(node->name());
-        while (mNodeRegistry.find(newName) != mNodeRegistry.end()) {
-            newName = node->createUniqueName(newName + "_1");
-        }
-        Log::notice("node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
+        Log::notice("Node name \"{}\" is a duplicate, renaming to {}.\n", node->name(), newName);
         node->setName(newName);
     }
   }
-- 
GitLab