Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signal name assignment bug in names_view.hpp #638

Merged
merged 9 commits into from
Apr 18, 2024
21 changes: 8 additions & 13 deletions include/mockturtle/views/names_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "../traits.hpp"

#include <map>
#include <string>

namespace mockturtle
{
Expand All @@ -64,19 +65,13 @@ class names_view : public Ntk

names_view<Ntk>& operator=( names_view<Ntk> const& named_ntk )
{
std::map<signal, std::string> new_signal_names;
std::vector<signal> current_pis;
Ntk::foreach_pi( [this, &current_pis]( auto const& n ) {
current_pis.emplace_back( Ntk::make_signal( n ) );
} );
named_ntk.foreach_pi( [&]( auto const& n, auto i ) {
if ( const auto it = _signal_names.find( current_pis[i] ); it != _signal_names.end() )
new_signal_names[named_ntk.make_signal( n )] = it->second;
} );

Ntk::operator=( named_ntk );
_signal_names = new_signal_names;
_network_name = named_ntk._network_name;
if ( this != &named_ntk ) // Check for self-assignment
{
Ntk::operator=( named_ntk );
_signal_names = named_ntk._signal_names;
_network_name = named_ntk._network_name;
_output_names = named_ntk._output_names;
}
return *this;
}

Expand Down
8 changes: 7 additions & 1 deletion test/views/names_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ void test_copy_names_view()
named_ntk.set_name( c, "c" );
named_ntk.set_output_name( 0, "f" );

// test operator= for empty and non-empty ntk.
names_view<Ntk> named_ntk_empty{};
named_ntk_empty = ntk;
CHECK( named_ntk_empty.get_network_name() == "" );

CHECK( named_ntk.has_name( a ) );
CHECK( named_ntk.has_name( b ) );
CHECK( named_ntk.has_name( c ) );
CHECK( named_ntk.has_output_name( 0 ) );

names_view<Ntk> new_named_ntk = named_ntk;
names_view<Ntk> new_named_ntk{};
new_named_ntk = named_ntk;
CHECK( new_named_ntk.has_name( a ) );
CHECK( new_named_ntk.has_name( b ) );
CHECK( new_named_ntk.has_name( c ) );
Expand Down
Loading