I’m trying to write a simple C++ program that uses Berkeley DB for storage. The key of the database is of type time_t and the data is an integer.
I need to take the difference between two adjacent data in a between two key. I open a cursor with the flag DB_SET_RANGE and then i use DB_NEXT to iterate.
My problem is that the cursor returns unsorted data. Is there a way to specify a custom sorter function for the cursor?
Some of the reasons why you may want to provide a custom sorting function are:
You set a BTree’s key comparison function using DB->set_bt_compare().
For example, an example routine that is used to sort integer keys in the database is: