Skip to content

Commit b779794

Browse files
committed
Use std::stable_sort instead of std::sort everywhere
Test results currently depend on how compare-equal elements are sorted by `std::sort`'s`unstable sort. Defaulting to `std::stable_sort` avoids that problem and generally increases the determinism of the code, which is good. If there are specific cases where the (fairly small) performance overhead of stable sorting is a concern, those can be switched back to unstable sorting as an optimization, but first one would need to verify that that doesn't break the tests (e.g., by running the tests with a shuffle before each call to unstable sort). Resolves #654
1 parent 50ffa10 commit b779794

33 files changed

+65
-65
lines changed

include/mockturtle/algorithms/aig_balancing.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class aig_balance_impl
122122
assert( storage[level].size() > 1 );
123123

124124
/* sort by decreasing level */
125-
std::sort( storage[level].begin(), storage[level].end(), [this]( auto const& a, auto const& b ) {
125+
std::stable_sort( storage[level].begin(), storage[level].end(), [this]( auto const& a, auto const& b ) {
126126
return ntk.level( ntk.get_node( a ) ) > ntk.level( ntk.get_node( b ) );
127127
} );
128128

include/mockturtle/algorithms/akers_synthesis.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class unitized_table
269269
}
270270
}
271271

272-
std::sort( to_be_removed.begin(), to_be_removed.end() );
272+
std::stable_sort( to_be_removed.begin(), to_be_removed.end() );
273273
to_be_removed.erase( std::unique( to_be_removed.begin(), to_be_removed.end() ), to_be_removed.end() );
274274

275275
std::reverse( std::begin( to_be_removed ), std::end( to_be_removed ) );

include/mockturtle/algorithms/aqfp/aqfp_db.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class aqfp_db
286286
auto input_ind = 1u;
287287

288288
auto tmp_input_slots = net.input_slots;
289-
std::sort( tmp_input_slots.begin(), tmp_input_slots.end() );
289+
std::stable_sort( tmp_input_slots.begin(), tmp_input_slots.end() );
290290
assert( tmp_input_slots == net.input_slots );
291291

292292
for ( auto i : net.input_slots )

include/mockturtle/algorithms/aqfp/aqfp_fanout_resyn.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct aqfp_fanout_resyn
108108

109109
auto offsets = balanced_splitter_tree_offsets( ntk_src.fanout_size( n ) );
110110

111-
std::sort( fanouts_n.begin(), fanouts_n.end(), [&]( auto f1, auto f2 ) { return ( ntk_src.depth() - ntk_src.level( f1 ) ) > ( ntk_src.depth() - ntk_src.level( f2 ) ) ||
111+
std::stable_sort( fanouts_n.begin(), fanouts_n.end(), [&]( auto f1, auto f2 ) { return ( ntk_src.depth() - ntk_src.level( f1 ) ) > ( ntk_src.depth() - ntk_src.level( f2 ) ) ||
112112
( ( ntk_src.depth() - ntk_src.level( f1 ) ) == ( ntk_src.depth() - ntk_src.level( f2 ) ) && ( f1 < f2 ) ); } );
113113

114114
auto n_dest = ntk_dest.get_node( f );

include/mockturtle/algorithms/aqfp/aqfp_retiming.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class aqfp_retiming_impl
527527
}
528528
} );
529529

530-
std::sort( classes.begin(), classes.end(), [&]( std::vector<node> const& a, std::vector<node> const& b ) { return a.size() > b.size(); } );
530+
std::stable_sort( classes.begin(), classes.end(), [&]( std::vector<node> const& a, std::vector<node> const& b ) { return a.size() > b.size(); } );
531531

532532
return classes;
533533
}

include/mockturtle/algorithms/aqfp/buffer_insertion.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ class buffer_insertion
979979
} );
980980

981981
/* sort by descending order of levels */
982-
std::sort( level_assignment.begin(), level_assignment.end(), std::greater<uint32_t>() );
982+
std::stable_sort( level_assignment.begin(), level_assignment.end(), std::greater<uint32_t>() );
983983

984984
/* simulate splitter tree reconstruction */
985985
uint32_t nodes_in_level = 0;
@@ -1076,7 +1076,7 @@ class buffer_insertion
10761076
}
10771077

10781078
/* sort by descending order of levels */
1079-
std::sort( level_assignment.begin(), level_assignment.end(), []( auto const& a, auto const& b ) {
1079+
std::stable_sort( level_assignment.begin(), level_assignment.end(), []( auto const& a, auto const& b ) {
10801080
return a[1] > b[1];
10811081
} );
10821082

include/mockturtle/algorithms/aqfp/detail/dag.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ struct aqfp_dag
7575
{
7676
auto x1 = nodes[i];
7777
auto x2 = rhs.nodes[i];
78-
std::sort( x1.begin(), x1.end() );
79-
std::sort( x2.begin(), x2.end() );
78+
std::stable_sort( x1.begin(), x1.end() );
79+
std::stable_sort( x2.begin(), x2.end() );
8080
if ( x1 != x2 )
8181
return false;
8282
}
8383

8484
auto y1 = input_slots;
8585
auto y2 = rhs.input_slots;
86-
std::sort( y1.begin(), y1.end() );
87-
std::sort( y2.begin(), y2.end() );
86+
std::stable_sort( y1.begin(), y1.end() );
87+
std::stable_sort( y2.begin(), y2.end() );
8888
if ( y1 != y2 )
8989
return false;
9090

include/mockturtle/algorithms/aqfp/detail/dag_cost.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class dag_aqfp_cost
211211
{
212212
rellev.push_back( lev - curlev[fo] );
213213
}
214-
std::sort( rellev.begin(), rellev.end() );
214+
std::stable_sort( rellev.begin(), rellev.end() );
215215

216216
return fanout_cc( rellev );
217217
}

include/mockturtle/algorithms/aqfp/detail/dag_gen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class dags_from_partial_dag
9393
{
9494
std::vector<NodeT> leaves = net.last_layer_leaves;
9595
leaves.insert( leaves.end(), net.other_leaves.begin(), net.other_leaves.end() );
96-
std::sort( leaves.begin(), leaves.end() );
96+
std::stable_sort( leaves.begin(), leaves.end() );
9797

9898
auto max_counts = net.max_equal_fanins();
9999

include/mockturtle/algorithms/aqfp/detail/dag_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ struct sublist_generator
299299
for ( auto i = last_count; i > 0; --i )
300300
{
301301
t.push_back( last_elem );
302-
std::sort( t.begin(), t.end() );
302+
std::stable_sort( t.begin(), t.end() );
303303
result.insert( t );
304304
}
305305
}

include/mockturtle/algorithms/aqfp/detail/db_builder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class aqfp_db_builder
257257
auto input_ind = 1u;
258258

259259
auto tmp_input_slots = net.input_slots;
260-
std::sort( tmp_input_slots.begin(), tmp_input_slots.end() );
260+
std::stable_sort( tmp_input_slots.begin(), tmp_input_slots.end() );
261261
assert( tmp_input_slots == net.input_slots );
262262

263263
for ( auto i : net.input_slots )

include/mockturtle/algorithms/aqfp/mig_algebraic_rewriting_splitters.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class mig_algebraic_depth_rewriting_splitter_impl
305305
{
306306
std::array<signal<Ntk>, 3> children;
307307
ntk.foreach_fanin( n, [&children]( auto const& f, auto i ) { children[i] = f; } );
308-
std::sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
308+
std::stable_sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
309309
return ntk.level( ntk.get_node( c1 ) ) < ntk.level( ntk.get_node( c2 ) );
310310
} );
311311
return children;

include/mockturtle/algorithms/cut_enumeration/spectr_cut.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct lut_mapping_update_cuts<cut_enumeration_spectr_cut>
123123
}
124124
} );
125125

126-
std::sort( node_to_cut[n].begin(), node_to_cut[n].end() );
126+
std::stable_sort( node_to_cut[n].begin(), node_to_cut[n].end() );
127127
node_to_cut[n].erase( unique( node_to_cut[n].begin(), node_to_cut[n].end() ), node_to_cut[n].end() );
128128
}
129129

include/mockturtle/algorithms/emap.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,7 @@ class emap_impl
51575157
class_list.push_back( it );
51585158
}
51595159

5160-
std::sort( class_list.begin(), class_list.end(), [&]( auto const& a, auto const& b ) {
5160+
std::stable_sort( class_list.begin(), class_list.end(), [&]( auto const& a, auto const& b ) {
51615161
return a.first[2] > b.first[2];
51625162
} );
51635163

@@ -5300,7 +5300,7 @@ class emap_impl
53005300
}
53015301
}
53025302

5303-
std::sort( order.begin(), order.end(), [&]( size_t a, size_t b ) {
5303+
std::stable_sort( order.begin(), order.end(), [&]( size_t a, size_t b ) {
53045304
return tts[a] < tts[b];
53055305
} );
53065306

include/mockturtle/algorithms/experimental/cost_resyn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class cost_resyn
209209
{
210210
l.score = kitty::count_ones( ( l.lit & 0x1 ? ~get_div( l.lit >> 1 ) : get_div( l.lit >> 1 ) ) & on_off_sets[on_off] );
211211
}
212-
std::sort( pos_unate_lits.begin(), pos_unate_lits.end(), [&]( unate_lit const& l1, unate_lit const& l2 ) {
212+
std::stable_sort( pos_unate_lits.begin(), pos_unate_lits.end(), [&]( unate_lit const& l1, unate_lit const& l2 ) {
213213
return l1.score > l2.score; // descending order
214214
} );
215215
}
@@ -221,7 +221,7 @@ class cost_resyn
221221
p.score = ( p.lit1 > p.lit2 ) ? kitty::count_ones( ( ( p.lit1 & 0x1 ? ~get_div( p.lit1 >> 1 ) : get_div( p.lit1 >> 1 ) ) ^ ( p.lit2 & 0x1 ? ~get_div( p.lit2 >> 1 ) : get_div( p.lit2 >> 1 ) ) ) & on_off_sets[on_off] )
222222
: kitty::count_ones( ( p.lit1 & 0x1 ? ~get_div( p.lit1 >> 1 ) : get_div( p.lit1 >> 1 ) ) & ( p.lit2 & 0x1 ? ~get_div( p.lit2 >> 1 ) : get_div( p.lit2 >> 1 ) ) & on_off_sets[on_off] );
223223
}
224-
std::sort( unate_pairs.begin(), unate_pairs.end(), [&]( fanin_pair const& p1, fanin_pair const& p2 ) {
224+
std::stable_sort( unate_pairs.begin(), unate_pairs.end(), [&]( fanin_pair const& p1, fanin_pair const& p2 ) {
225225
return p1.score > p2.score; // descending order
226226
} );
227227
}

include/mockturtle/algorithms/lut_mapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ class lut_map_impl
21722172
}
21732173

21742174
/* sort leaves in topo order */
2175-
std::sort( leaves.begin(), leaves.end() );
2175+
std::stable_sort( leaves.begin(), leaves.end() );
21762176

21772177
ntk.add_to_mapping( n, leaves.begin(), leaves.end() );
21782178

include/mockturtle/algorithms/mig_algebraic_rewriting.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class mig_algebraic_depth_rewriting_impl
274274
{
275275
std::array<signal<Ntk>, 3> children;
276276
ntk.foreach_fanin( n, [&children]( auto const& f, auto i ) { children[i] = f; } );
277-
std::sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
277+
std::stable_sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
278278
return ntk.level( ntk.get_node( c1 ) ) < ntk.level( ntk.get_node( c2 ) );
279279
} );
280280
return children;

include/mockturtle/algorithms/reconv_cut.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class reconvergence_driven_cut_impl2
303303
bool construct_cut()
304304
{
305305
assert( leaves.size() <= ps.max_leaves && "cut-size overflow" );
306-
std::sort( std::begin( leaves ), std::end( leaves ),
306+
std::stable_sort( std::begin( leaves ), std::end( leaves ),
307307
[this]( node const& a, node const& b ) {
308308
return cost( a ) < cost( b );
309309
} );

include/mockturtle/algorithms/resyn_engines/xag_resyn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ class xag_resyn_decompose
576576
{
577577
l.score = kitty::count_ones( ( l.lit & 0x1 ? ~get_div( l.lit >> 1 ) : get_div( l.lit >> 1 ) ) & on_off_sets[on_off] );
578578
}
579-
std::sort( unate_lits.begin(), unate_lits.end(), [&]( unate_lit const& l1, unate_lit const& l2 ) {
579+
std::stable_sort( unate_lits.begin(), unate_lits.end(), [&]( unate_lit const& l1, unate_lit const& l2 ) {
580580
return l1.score > l2.score; // descending order
581581
} );
582582
}
@@ -595,7 +595,7 @@ class xag_resyn_decompose
595595
p.score = kitty::count_ones( ( p.lit1 & 0x1 ? ~get_div( p.lit1 >> 1 ) : get_div( p.lit1 >> 1 ) ) & ( p.lit2 & 0x1 ? ~get_div( p.lit2 >> 1 ) : get_div( p.lit2 >> 1 ) ) & on_off_sets[on_off] );
596596
}
597597
}
598-
std::sort( unate_pairs.begin(), unate_pairs.end(), [&]( fanin_pair const& p1, fanin_pair const& p2 ) {
598+
std::stable_sort( unate_pairs.begin(), unate_pairs.end(), [&]( fanin_pair const& p1, fanin_pair const& p2 ) {
599599
return p1.score > p2.score; // descending order
600600
} );
601601
}

include/mockturtle/algorithms/xag_balancing.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class xag_balance_impl
139139
assert( storage[level].size() > 1 );
140140

141141
/* sort by decreasing level */
142-
std::sort( storage[level].begin(), storage[level].end(), [this]( auto const& a, auto const& b ) {
142+
std::stable_sort( storage[level].begin(), storage[level].end(), [this]( auto const& a, auto const& b ) {
143143
return ntk.level( ntk.get_node( a ) ) > ntk.level( ntk.get_node( b ) );
144144
} );
145145

include/mockturtle/algorithms/xmg_algebraic_rewriting.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class xmg_algebraic_depth_rewriting_impl
421421
{
422422
std::array<signal<Ntk>, 3> children;
423423
ntk.foreach_fanin( n, [&children]( auto const& f, auto i ) { children[i] = f; } );
424-
std::sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
424+
std::stable_sort( children.begin(), children.end(), [this]( auto const& c1, auto const& c2 ) {
425425
return ntk.level( ntk.get_node( c1 ) ) < ntk.level( ntk.get_node( c2 ) );
426426
} );
427427
return children;

include/mockturtle/algorithms/xmg_resub.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct xmg_resub_functor
214214
auto const& tt_s = sim.get_tt( s );
215215
sorted_divs.emplace_back( static_cast<uint32_t>( *it ), static_cast<uint32_t>( relative_distinguishing_power( tt_s, tt ) ) );
216216
}
217-
std::sort( std::rbegin( sorted_divs ), std::rend( sorted_divs ),
217+
std::stable_sort( std::rbegin( sorted_divs ), std::rend( sorted_divs ),
218218
[&]( auto const& u, auto const& v ) {
219219
if ( u.entropy == v.entropy )
220220
return u.node < v.node;

include/mockturtle/generators/self_dualize.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ inline aig_network self_dualize_aig( aig_network const& src_aig )
7979

8080
src_aig.foreach_po( [&]( const auto& f ) {
8181
auto leaves = cut_generator.run( { src_aig.get_node( f ) } ).first;
82-
std::sort( std::begin( leaves ), std::end( leaves ) );
82+
std::stable_sort( std::begin( leaves ), std::end( leaves ) );
8383

8484
/* check if all leaves are pis */
8585
for ( const auto& l : leaves )

include/mockturtle/networks/aqfp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class aqfp_network
310310
return children[0u];
311311
}
312312

313-
std::sort( children.begin(), children.end(), []( auto f, auto s ) { return f.index < s.index; } );
313+
std::stable_sort( children.begin(), children.end(), []( auto f, auto s ) { return f.index < s.index; } );
314314

315315
for ( auto i = 1u; i < children.size(); i++ )
316316
{

include/mockturtle/properties/aqfpcost.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class fanout_net_cost
121121

122122
std::vector<uint32_t> new_config( config.begin(), config.begin() + ( config.size() - size ) );
123123
new_config.push_back( sp_lev );
124-
std::sort( new_config.begin(), new_config.end() );
124+
std::stable_sort( new_config.begin(), new_config.end() );
125125

126126
temp += cost_for_config( new_config, ignore_initial_buffers );
127127

@@ -209,7 +209,7 @@ struct aqfp_network_cost
209209

210210
if ( rellev.size() > 1u || ( rellev.size() == 1u && rellev[0] > 0 ) )
211211
{
212-
std::sort( rellev.begin(), rellev.end() );
212+
std::stable_sort( rellev.begin(), rellev.end() );
213213
auto net_cost = fanout_cc( rellev, ntk.is_ci( n ) && !assume.balance_pis );
214214
if ( net_cost == std::numeric_limits<double>::infinity() )
215215
{

include/mockturtle/utils/struct_library.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class struct_library
295295
uint32_t shift = 0;
296296

297297
/* sort cells by increasing order of area */
298-
std::sort( indexes.begin(), indexes.end(),
298+
std::stable_sort( indexes.begin(), indexes.end(),
299299
[&]( auto const& a, auto const& b ) -> bool {
300300
return _supergates[a].area < _supergates[b].area;
301301
} );

include/mockturtle/utils/tech_library.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,15 +816,15 @@ class tech_library
816816

817817
std::iota( order.begin(), order.end(), 0 );
818818

819-
std::sort( order.begin(), order.end(), [&]( size_t a, size_t b ) {
819+
std::stable_sort( order.begin(), order.end(), [&]( size_t a, size_t b ) {
820820
return static_tts[a] < static_tts[b];
821821
} );
822822

823823
std::transform( order.begin(), order.end(), sorted_tts.begin(), [&]( size_t a ) {
824824
return static_tts[a];
825825
} );
826826

827-
// std::sort( static_tts.begin(), static_tts.end() );
827+
// std::stable_sort( static_tts.begin(), static_tts.end() );
828828

829829
auto& v = _multi_lib[sorted_tts];
830830

@@ -1406,14 +1406,14 @@ class exact_library
14061406
rewriting_fn( _database, function, pis.begin(), pis.end(), add_supergate );
14071407
if ( supergates_pos.size() > 0 )
14081408
{
1409-
std::sort( supergates_pos.begin(), supergates_pos.end(), [&]( auto const& a, auto const& b ) {
1409+
std::stable_sort( supergates_pos.begin(), supergates_pos.end(), [&]( auto const& a, auto const& b ) {
14101410
return a.area < b.area;
14111411
} );
14121412
_super_lib.insert( { entry, supergates_pos } );
14131413
}
14141414
if ( _ps.np_classification && supergates_neg.size() > 0 )
14151415
{
1416-
std::sort( supergates_neg.begin(), supergates_neg.end(), [&]( auto const& a, auto const& b ) {
1416+
std::stable_sort( supergates_neg.begin(), supergates_neg.end(), [&]( auto const& a, auto const& b ) {
14171417
return a.area < b.area;
14181418
} );
14191419
_super_lib.insert( { not_entry, supergates_neg } );

include/mockturtle/utils/window_utils.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ void levelized_expand_towards_tfo( Ntk const& ntk, std::vector<typename Ntk::nod
721721
}
722722
}
723723

724-
std::sort( std::begin( used ), std::end( used ) );
724+
std::stable_sort( std::begin( used ), std::end( used ) );
725725

726726
for ( uint32_t index = 0u; index < used.size(); ++index )
727727
{
@@ -761,7 +761,7 @@ void levelized_expand_towards_tfo( Ntk const& ntk, std::vector<typename Ntk::nod
761761
if ( std::find( std::begin( used ), std::end( used ), node_level ) == std::end( used ) )
762762
{
763763
used.push_back( node_level );
764-
std::sort( std::begin( used ), std::end( used ) );
764+
std::stable_sort( std::begin( used ), std::end( used ) );
765765
}
766766
}
767767

@@ -841,7 +841,7 @@ std::vector<typename Ntk::node> cover( Ntk const& ntk, typename Ntk::node const&
841841
detail::cover_recursive( ntk, root, nodes );
842842

843843
/* remove duplicates */
844-
std::sort( std::begin( nodes ), std::end( nodes ) );
844+
std::stable_sort( std::begin( nodes ), std::end( nodes ) );
845845
auto last = std::unique( std::begin( nodes ), std::end( nodes ) );
846846
nodes.erase( last, std::end( nodes ) );
847847

@@ -923,7 +923,7 @@ class create_window_impl
923923
*nodes = cover( ntk, pivot, inputs );
924924

925925
/* expand the nodes towards the TFO */
926-
std::sort( std::begin( inputs ), std::end( inputs ) );
926+
std::stable_sort( std::begin( inputs ), std::end( inputs ) );
927927
detail::levelized_expand_towards_tfo( ntk, inputs, *nodes, levels );
928928
}
929929

@@ -933,8 +933,8 @@ class create_window_impl
933933
}
934934

935935
/* top. sort nodes */
936-
std::sort( std::begin( inputs ), std::end( inputs ) );
937-
std::sort( std::begin( *nodes ), std::end( *nodes ) );
936+
std::stable_sort( std::begin( inputs ), std::end( inputs ) );
937+
std::stable_sort( std::begin( *nodes ), std::end( *nodes ) );
938938

939939
/* collect the nodes with fanout outside of nodes */
940940
std::vector<signal> outputs = collect_outputs( ntk, inputs, *nodes, refs );

include/mockturtle/views/mffc_view.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ class mffc_view : public immutable_view<Ntk>
217217

218218
void compute_sets()
219219
{
220-
// std::sort( _nodes.begin(), _nodes.end(),
220+
// std::stable_sort( _nodes.begin(), _nodes.end(),
221221
// [&]( auto const& n1, auto const& n2 ) { return static_cast<Ntk*>( this )->node_to_index( n1 ) < static_cast<Ntk*>( this )->node_to_index( n2 ); } );
222-
std::sort( _nodes.begin(), _nodes.end() );
222+
std::stable_sort( _nodes.begin(), _nodes.end() );
223223

224224
for ( auto const& n : _nodes )
225225
{

0 commit comments

Comments
 (0)