How do I get elements from boost::fibonacci_heap by handle?

boost, c++, fibonacci-heap

Solution

You should be able to dereference the handle. An example of this is provided here: http://www.boost.org/doc/libs/1_50_0/doc/html/heap/concepts.html

Example from site

fibonacci_heap<heap_data> heap;
heap_data f;
fibonacci_heap<heap_data>::handle_type handle = heap.push(f);
(*handle).handle = handle; // store handle in node

So simply call

(*handle)

to get the reference to your class stored in the heap.

Problem

I am using the `boost::fibonacci_heap` class from Boost 1.53.0 to maintain an updateable priority queue. When I want to update an element I need to compare the element in the heap with the new element that I want to replace it with. I only want to replace elements in the heap with "smaller" versions so I want to compare them before I update. When I insert elements I store their handle (`boost::fibonacci_heap::handle_type`). All the functions I have seen in the documentation for `fibonacci_heap` that take a handle type only provide some sort of write access (`update()`, `decrease()`, `increase()` etc.) and don't allow me to inspect the element identified by the handle before I update it. Is there some way to look at an element in a `fibonacci_heap` by using its handle only?

Original source