Boost: Priority Queue, which supports finding an item in O (log n) time

I am wondering if Boost supports the implementation of the priority queue, which also supports searching for an item in O (log n) time?

I could achieve this functionality using the Boost Fibonacci Heap, and save the handles on std :: map along with my index and update this information after inserting the heap, but I was hoping for a version of the heap that already offers this functionality.

Note. I deleted the previous version of my question because it was too ambiguous.

+4
source share
3 answers

(?) , .

, , Boost Multi-Index , Active Object Boost Asio:

, Multi-Index /

+2

  • (multi)set<pair<priority, item> >
  • multimap<priority, item>
  • (multi)set<item> , .

.

O(1) , , , , .

, , . O(n*log(n)), , set , .

+1

, , - .

, , , libpqueue, : https://github.com/vy/libpqueue.

cmppri(), getpri(), setpri(), getpos(), setpos(), , .

- , :

typedef struct {
    pqueue_pri_t pri;
    void *data;
    size_t pos;
} node_t;

, :

static size_t get_pos(void *a) {
    return ((node_t *) a)->pos;
}

static void set_pos(void *a, size_t pos) {
    ((node_t *) a)->pos = pos;
}

node O(1) . ( node_t), std::unordered_map .

libpqueue - C Apache.

0
source

Source: https://habr.com/ru/post/1545911/


All Articles