要素のソートを維持できる優れたデータ構造を探しています。現在、Boost.Heapを試しています。
データ構造を整然とトラバースし、何らかのプロパティに基づいて要素に到達したら、その優先度を更新する必要があることがよくあります。Boost.Heap 優先度キューは、順序付けされた反復子と順序付けられていない反復子を提供します。要素の更新はノード ハンドルを介して発生します。ハンドルは通常の順序付けされていないイテレータから取得できますが、次の例のように順序付けられたイテレータから直接取得することはできません。
#include <iostream>
#include <algorithm>
#include <boost/heap/fibonacci_heap.hpp>
using namespace boost::heap;
int main()
{
fibonacci_heap<int> fib_heap;
fib_heap.push(1);
fib_heap.push(2);
fib_heap.push(3);
for(auto i = fib_heap.ordered_begin(); i != fib_heap.ordered_end(); ++i)
{
// no viable conversion here
auto h = fibonacci_heap<int>::s_handle_from_iterator(i);
if(*h == 2) // dumb test
{
fib_heap.increase(h, *h + 2);
break;
}
}
std::for_each(fib_heap.ordered_begin(), fib_heap.ordered_end(),
[](const int &e)
{
std::cout << e << std::endl;
});
}
キューを整然とトラバースし、トラバーサル内の要素を更新するにはどうすればよいですか?
更新後にトラバーサルを残すことに注意してください。
(そのような目的のための代替ライブラリの提案は大歓迎です)