Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost heap Setting user defined compare function

Tags:

c++

heap

boost

Recently, I found Boost.Heap very useful in my project. But I could not find any example code showing how I can set up arbitrary compare function.

#include "boost/heap/fibonacci_heap.hpp"

using boost::heap::fibonacci_heap;
int main(){
    fibonacci_heap<int> pq; //default compare function std::less<int>
}

For example, how can I set std::greater< int >?

The boost.heap document says that it can be set by setting an option. But I don't know what it means. Can anyone help?

like image 386
Sungmin Avatar asked May 27 '26 14:05

Sungmin


1 Answers

Try this:

typedef boost::heap::fibonacci_heap<
        int,
        boost::heap::compare<std::greater<int> > > MyHeap;

The documentation does not show how to specify options. I had to dig through the unit test source code to find out the correct usage syntax.

like image 97
Emile Cormier Avatar answered May 30 '26 03:05

Emile Cormier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!