The Boost Graph libraries have an implementation of A*
(and Dijkstra if you want) which both rely on a priority queue implementation that has more capabilities than the standard priority queue. Their priority queue implementation is also indirect which is also helpful. It supports functions like push_or_update
, update
, and contains
which is really all you need for A*
, which is lacking from the standard implementation. This queue is called d_ary_heap_indirect
and here is a simple example by daviddoria on using it (among other nice examples of BGL). There is also a slightly more feature-rich and non-BGL priority-queue implementation available in the latest version of Boost called just d_ary_heap
.
And btw, checking if a node is in the open list by checking if it is present in the priority queue is really inefficient. Most algorithms rely on a coloring scheme (or masking) meaning that you store, for each node, a status flag (or color) which tells you whether the node is open or closed (or un-discovered, or inconsistent, etc, depending on the variation of A*
that you are implementing). It's very easy, as part of your algorithm, to make sure that the state of the flag is consistent with what set or priority-queue the node is in, because you control when nodes are moved in and out of the sets. I encourage you to either use the BGL implementation of A*
or to at least check it out, see it here: