Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/mockturtle/networks/aig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class aig_network
storage::element_type::node_type _hash_obj;
_hash_obj.children[0] = child0;
_hash_obj.children[1] = child1;
if ( const auto it = _storage->hash.find( _hash_obj ); it != _storage->hash.end() )
if ( const auto it = _storage->hash.find( _hash_obj ); it != _storage->hash.end() && it->second != old_node )
{
return std::make_pair( n, signal( it->second, 0 ) );
}
Expand Down
33 changes: 33 additions & 0 deletions test/networks/aig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,36 @@ TEST_CASE( "invoke take_out_node two times on the same node", "[aig]" )
CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1u );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1u );
}

TEST_CASE( "substitute node and restrash", "[aig]" )
{
aig_network aig;
auto const x1 = aig.create_pi();
auto const x2 = aig.create_pi();

auto const f1 = aig.create_and( x1, x2 );
auto const f2 = aig.create_and( f1, x2 );
aig.create_po( f2 );

CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1 );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 2 );
CHECK( aig.fanout_size( aig.get_node( f1 ) ) == 1 );
CHECK( aig.fanout_size( aig.get_node( f2 ) ) == 1 );

CHECK( simulate<kitty::static_truth_table<2u>>( aig )[0]._bits == 0x8 );

/* substitute f1 with x1
*
* this is a very interesting test case because replacing f1 with x1
* in f2 makes f2 and f1 equal. a correct implementation will
* create a new entry in the hash, although (x1, x2) is already
* there, because (x1, x2) will be deleted in the next step.
*/
aig.substitute_node( aig.get_node( f1 ), x1 );
CHECK( simulate<kitty::static_truth_table<2u>>( aig )[0]._bits == 0x8 );

CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1 );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1 );
CHECK( aig.fanout_size( aig.get_node( f1 ) ) == 0 );
CHECK( aig.fanout_size( aig.get_node( f2 ) ) == 1 );
}