Boost C++ Libraries: Ticket #13087: Boost::binomial_heap Merge error https://svn.boost.org/trac10/ticket/13087 <p> Configured with BOOST_HEAP_SANITYCHECKS turned on. Binomial heap hits an assertion failure during the second merge routine in the attached example. </p> <pre class="wiki">#include "boost/heap/binomial_heap.hpp" typedef boost::heap::binomial_heap&lt;int&gt; Heap; int main(int argc, char* argv[]) { Heap heap0; size_t heap0_size = 13; size_t max_range = 100; for (size_t ix = 0; ix &lt; heap0_size; ++ix) { heap0.push(rand() % max_range); } Heap heap1; size_t heap1_size = 5; for (size_t ix = 0; ix &lt; heap1_size; ++ix) { heap1.push(rand() % max_range); } heap0.merge(heap1); Heap heap2; size_t heap2_size = 1; for (size_t ix = 0; ix &lt; heap2_size; ++ix) { heap2.push(rand() % max_range); } heap2.merge(heap0); } </pre><p> When heap1 is merged into heap0, the underlying forest incorrectly contains two 2-degree trees. This error is later caught in a sanity assertion check when heap0 is merged into heap2. </p> <p> I believe the error stems the case identified by line 668 in binomial_heap.hpp. When the two root degrees are equal and a carry tree with degree less than both exist, the carry tree is inserted into trees. However, after this insertion, the this_iterator is incorrectly iterated forward which causes the algorithm to behave incorrectly. In the case provided above, this causes the merge algorithm to skip the degree-2 / degree-2 merge between this and rhs, and instead causes rhs's degree-2 tree to be simple inserted into trees. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13087 Trac 1.4.3 jun.kudo@… Tue, 20 Jun 2017 17:30:07 GMT attachment set https://svn.boost.org/trac10/ticket/13087 https://svn.boost.org/trac10/ticket/13087 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> Complete example of encountered error </p> Ticket