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
10 changes: 7 additions & 3 deletions include/mockturtle/networks/aig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class aig_network
const auto it = _storage->hash.find( node );
if ( it != _storage->hash.end() )
{
assert( !is_dead( it->second ) );
return {it->second, 0};
}

Expand Down Expand Up @@ -510,6 +511,9 @@ class aig_network

void replace_in_outputs( node const& old_node, signal const& new_signal )
{
if ( is_dead( old_node ) )
return;

for ( auto& output : _storage->outputs )
{
if ( output.index == old_node )
Expand All @@ -525,8 +529,8 @@ class aig_network

void take_out_node( node const& n )
{
/* we cannot delete CIs or constants */
if ( n == 0 || is_ci( n ) )
/* we cannot delete CIs, constants, or already dead nodes */
if ( n == 0 || is_ci( n ) || is_dead( n ) )
return;

auto& nobj = _storage->nodes[n];
Expand Down Expand Up @@ -568,7 +572,7 @@ class aig_network

for ( auto idx = 1u; idx < _storage->nodes.size(); ++idx )
{
if ( is_ci( idx ) )
if ( is_ci( idx ) || is_dead( idx ) )
continue; /* ignore CIs */

if ( const auto repl = replace_in_node( idx, _old, _new ); repl )
Expand Down
28 changes: 28 additions & 0 deletions test/networks/aig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,31 @@ TEST_CASE( "substitute node by constant in NAND-based XOR circuit (test case 2)"
CHECK( aig.fanout_size( aig.get_node( f3 ) ) == 0u );
CHECK( aig.fanout_size( aig.get_node( f4 ) ) == 1u );
}

TEST_CASE( "invoke take_out_node two times on the same node", "[aig]" )
{
aig_network aig;
const auto x1 = aig.create_pi();
const auto x2 = aig.create_pi();

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

CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 2u );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 2u );

/* delete node */
CHECK( !aig.is_dead( aig.get_node( f1 ) ) );
aig.take_out_node( aig.get_node( f1 ) );
CHECK( aig.is_dead( aig.get_node( f1 ) ) );
CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1u );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1u );

/* ensure that double-deletion has no effect on the fanout-size of x1 and x2 */
CHECK( aig.is_dead( aig.get_node( f1 ) ) );
aig.take_out_node( aig.get_node( f1 ) );
CHECK( aig.is_dead( aig.get_node( f1 ) ) );
CHECK( aig.fanout_size( aig.get_node( x1 ) ) == 1u );
CHECK( aig.fanout_size( aig.get_node( x2 ) ) == 1u );
}