Keep the order of other nodes

This commit is contained in:
mole99 2023-08-15 10:18:12 +02:00
parent bd2b67961e
commit 5a87d2fa38
1 changed files with 14 additions and 8 deletions

View File

@ -208,28 +208,34 @@ void vvp_net_t::link(vvp_net_ptr_t port_to_link)
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
}
// All other nodes connect to the tail of the linked list
// All other nodes connect after the last vvp_fun_modpath_src
else
{
// List is empty, just point to port_to_link
if (out_.ptr() == nullptr)
// List is empty or first node has no vvp_fun_modpath_src
// then just insert the node into the head of linked list
if (out_.ptr() == nullptr || ! dynamic_cast<vvp_fun_modpath_src*>(out_.ptr()->fun))
{
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
net->port[port_to_link.port()] = vvp_net_ptr_t(nullptr,0);
return;
}
vvp_net_ptr_t cur = out_;
vvp_net_ptr_t prev = vvp_net_ptr_t(nullptr,0);
// Traverse through linked list
while (cur.ptr()->port[cur.port()].ptr())
while (dynamic_cast<vvp_fun_modpath_src*>(cur.ptr()->fun))
{
prev = cur;
cur = cur.ptr()->port[cur.port()];
if (!cur.ptr()) break; // End of list
}
// Connect to the tail of list
cur.ptr()->port[cur.port()] = port_to_link;
net->port[port_to_link.port()] = vvp_net_ptr_t(nullptr,0);
assert(prev.ptr());
// Insert after last vvp_fun_modpath_src (or end of list)
net->port[port_to_link.port()] = cur;
prev.ptr()->port[prev.port()] = port_to_link;
}
}