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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -11,7 +11,7 @@ repos:


- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
rev: v22.1.3
hooks:
- id: clang-format
types_or: [c++, c, cuda]
6 changes: 4 additions & 2 deletions include/boost/heap/binomial_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ class binomial_heap :
/// \copydoc boost::heap::priority_queue::operator=(priority_queue const &)
binomial_heap& operator=( binomial_heap const& rhs )
{
if ( this == &rhs )
return *this;
clear();
size_holder::set_size( rhs.get_size() );
static_cast< super_t& >( *this ) = rhs;
Expand Down Expand Up @@ -400,7 +402,7 @@ class binomial_heap :
size_holder::decrement();

if ( element->child_count() ) {
size_type sz = ( 1 << element->child_count() ) - 1;
size_type sz = ( size_type( 1 ) << element->child_count() ) - 1;

binomial_heap children( value_comp(), element->children, sz );
if ( trees.empty() ) {
Expand Down Expand Up @@ -543,7 +545,7 @@ class binomial_heap :
rhs.set_size( 0 );
rhs.top_element = nullptr;

super_t::set_stability_count( ( std::max )( super_t::get_stability_count(), rhs.get_stability_count() ) );
super_t::set_stability_count( (std::max)( super_t::get_stability_count(), rhs.get_stability_count() ) );
rhs.set_stability_count( 0 );
}

Expand Down
2 changes: 1 addition & 1 deletion include/boost/heap/d_ary_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class d_ary_heap : private make_heap_base< T, BoundArgs, false >::type
size_type last_child_index( size_type index ) const
{
const size_t first_index = first_child_index( index );
const size_type last_index = ( std::min )( first_index + D - 1, size() - 1 );
const size_type last_index = (std::min)( first_index + D - 1, size() - 1 );

return last_index;
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/heap/detail/ilog2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ IntType log2( IntType value )
return fn( value );
}

}} // namespace boost::heap
}} // namespace boost::heap

#endif /* BOOST_HEAP_DETAIL_ILOG2_HPP */
6 changes: 4 additions & 2 deletions include/boost/heap/detail/mutable_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ class priority_queue_mutable_wrapper
template < class... Args >
handle_type emplace( Args&&... args )
{
objects.push_front( std::make_pair( std::forward< Args >( args )..., 0 ) );
objects.emplace_front( std::piecewise_construct,
std::forward_as_tuple( std::forward< Args >( args )... ),
std::forward_as_tuple( 0 ) );
list_iterator ret = objects.begin();
q_.push( ret );
return handle_type( ret );
Expand Down Expand Up @@ -520,6 +522,6 @@ class priority_queue_mutable_wrapper
};


}}} // namespace boost::heap::detail
}}} // namespace boost::heap::detail

#endif /* BOOST_HEAP_DETAIL_MUTABLE_HEAP_HPP */
2 changes: 1 addition & 1 deletion include/boost/heap/detail/ordered_adaptor_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ class ordered_adaptor_iterator :
};


}}} // namespace boost::heap::detail
}}} // namespace boost::heap::detail

#endif /* BOOST_HEAP_DETAIL_ORDERED_ADAPTOR_ITERATOR_HPP */
10 changes: 5 additions & 5 deletions include/boost/heap/detail/stable_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,18 @@ struct heap_base< T, Cmp, constant_time_size, StabilityCounterType, true > :

internal_type make_node( T const& val )
{
stability_counter_type count = ++counter_;
if ( counter_ == ( std::numeric_limits< stability_counter_type >::max )() )
if ( counter_ == ( std::numeric_limits< stability_counter_type >::max )() - 1 )
BOOST_THROW_EXCEPTION( std::runtime_error( "boost::heap counter overflow" ) );
stability_counter_type count = ++counter_;
return internal_type( count, val );
}

template < class... Args >
internal_type make_node( Args&&... args )
{
stability_counter_type count = ++counter_;
if ( counter_ == ( std::numeric_limits< stability_counter_type >::max )() )
if ( counter_ == ( std::numeric_limits< stability_counter_type >::max )() - 1 )
BOOST_THROW_EXCEPTION( std::runtime_error( "boost::heap counter overflow" ) );
stability_counter_type count = ++counter_;
return internal_type( count, std::forward< Args >( args )... );
}

Expand Down Expand Up @@ -563,6 +563,6 @@ struct extract_allocator_types
};


}}} // namespace boost::heap::detail
}}} // namespace boost::heap::detail

#endif /* BOOST_HEAP_DETAIL_STABLE_HEAP_HPP */
3 changes: 2 additions & 1 deletion include/boost/heap/detail/tree_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <boost/core/allocator_access.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/conditional.hpp>
#include <queue>

Expand Down Expand Up @@ -343,6 +344,6 @@ class recursive_tree_iterator :
};


}}} // namespace boost::heap::detail
}}} // namespace boost::heap::detail

#endif /* BOOST_HEAP_DETAIL_TREE_ITERATOR_HPP */
15 changes: 12 additions & 3 deletions include/boost/heap/fibonacci_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class fibonacci_heap :
/// \copydoc boost::heap::priority_queue::operator=(priority_queue const &)
fibonacci_heap& operator=( fibonacci_heap const& rhs )
{
if ( this == &rhs )
return *this;
clear();
size_holder::set_size( rhs.size() );
static_cast< super_t& >( *this ) = rhs;
Expand Down Expand Up @@ -591,7 +593,7 @@ class fibonacci_heap :
rhs.top_element = nullptr;
rhs.set_size( 0 );

super_t::set_stability_count( ( std::max )( super_t::get_stability_count(), rhs.get_stability_count() ) );
super_t::set_stability_count( (std::max)( super_t::get_stability_count(), rhs.get_stability_count() ) );
rhs.set_stability_count( 0 );
}

Expand Down Expand Up @@ -699,8 +701,13 @@ class fibonacci_heap :
if ( roots.empty() )
return;

static const size_type max_log2 = sizeof( size_type ) * 8;
std::array< node_pointer, max_log2 > aux {};
// The maximum degree of any node in a Fibonacci heap with N elements is
// floor(log_phi(N)) where phi = (1+sqrt(5))/2 ~ 1.618. Since
// log_phi(N) < 1.4405 * log2(N), a safe upper bound on the degree for a
// size_type of B bits is ceil(1.4405 * B) + 2. We compute a conservative
// compile-time constant that is always large enough.
constexpr size_type max_degree = sizeof( size_type ) * 12 + 4;
std::array< node_pointer, max_degree > aux {};

node_list_iterator it = roots.begin();
top_element = static_cast< node_pointer >( &*it );
Expand All @@ -709,6 +716,7 @@ class fibonacci_heap :
node_pointer n = static_cast< node_pointer >( &*it );
++it;
size_type node_rank = n->child_count();
BOOST_ASSERT( node_rank < max_degree );

if ( aux[ node_rank ] == nullptr )
aux[ node_rank ] = n;
Expand All @@ -729,6 +737,7 @@ class fibonacci_heap :

aux[ node_rank ] = nullptr;
node_rank = n->child_count();
BOOST_ASSERT( node_rank < max_degree );
} while ( aux[ node_rank ] != nullptr );
aux[ node_rank ] = n;
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/heap/heap_concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ struct MutablePriorityQueue : PriorityQueue< C >
bool equal, not_equal;
};

}} // namespace boost::heap
}} // namespace boost::heap

#endif /* BOOST_HEAP_CONCEPTS_HPP */
4 changes: 2 additions & 2 deletions include/boost/heap/heap_merge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct heap_merge_emulate
rhs.pop();
}

lhs.set_stability_count( ( std::max )( lhs.get_stability_count(), rhs.get_stability_count() ) );
lhs.set_stability_count( (std::max)( lhs.get_stability_count(), rhs.get_stability_count() ) );
rhs.set_stability_count( 0 );
}
};
Expand Down Expand Up @@ -118,6 +118,6 @@ void heap_merge( Heap1& lhs, Heap2& rhs )
}


}} // namespace boost::heap
}} // namespace boost::heap

#endif /* BOOST_HEAP_MERGE_HPP */
4 changes: 3 additions & 1 deletion include/boost/heap/pairing_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class pairing_heap :
/// \copydoc boost::heap::priority_queue::operator=(priority_queue const & rhs)
pairing_heap& operator=( pairing_heap const& rhs )
{
if ( this == &rhs )
return *this;
clear();
size_holder::set_size( rhs.get_size() );
static_cast< super_t& >( *this ) = rhs;
Expand Down Expand Up @@ -585,7 +587,7 @@ class pairing_heap :
rhs.set_size( 0 );
rhs.root = nullptr;

super_t::set_stability_count( ( std::max )( super_t::get_stability_count(), rhs.get_stability_count() ) );
super_t::set_stability_count( (std::max)( super_t::get_stability_count(), rhs.get_stability_count() ) );
rhs.set_stability_count( 0 );
}

Expand Down
2 changes: 1 addition & 1 deletion include/boost/heap/policies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@ struct arity
{};
#endif

}} // namespace boost::heap
}} // namespace boost::heap

#endif /* BOOST_HEAP_POLICIES_HPP */
2 changes: 1 addition & 1 deletion include/boost/heap/priority_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,6 @@ class priority_queue :
}
};

}} // namespace boost::heap
}} // namespace boost::heap

#endif /* BOOST_HEAP_PRIORITY_QUEUE_HPP */
4 changes: 3 additions & 1 deletion include/boost/heap/skew_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ class skew_heap :
/// \copydoc boost::heap::priority_queue::operator=(priority_queue const & rhs)
skew_heap& operator=( skew_heap const& rhs )
{
if ( this == &rhs )
return *this;
clear();
size_holder::set_size( rhs.get_size() );
static_cast< super_t& >( *this ) = rhs;
Expand Down Expand Up @@ -554,7 +556,7 @@ class skew_heap :
rhs.root = nullptr;
sanity_check();

super_t::set_stability_count( ( std::max )( super_t::get_stability_count(), rhs.get_stability_count() ) );
super_t::set_stability_count( (std::max)( super_t::get_stability_count(), rhs.get_stability_count() ) );
rhs.set_stability_count( 0 );
}

Expand Down
2 changes: 1 addition & 1 deletion test/common_heap_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <boost/shared_ptr.hpp>

#include <boost/test/tools/old/interface.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>

#include <boost/heap/heap_concepts.hpp>
Expand Down