ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
DialQueue.h File Reference

A monotone bucket queue with overflow, beyond the book: the queue of Dial on a circular window of \( W \) buckets, \( W \) a power of 2, the keys out of the window in a radix heap [see RadixHeap.h]. More...

#include "ADS/Contract.h"
#include "ADS/Modification.h"
#include "ADS/priority/RadixHeap.h"
#include <bit>
#include <limits>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>
#include <vector>
#include "ADS/priority/impl/DialQueue.tpp"

Go to the source code of this file.

Classes

class  ADS::DialQueue< T, K, Policy >
 a monotone queue of items with integer keys of the type K on a circular window of buckets, the keys beyond it in a radix heap More...

Namespaces

namespace  ADS

Detailed description

A monotone bucket queue with overflow, beyond the book: the queue of Dial on a circular window of \( W \) buckets, \( W \) a power of 2, the keys out of the window in a radix heap [see RadixHeap.h].

It serves the algorithms whose extracted keys never decrease and whose pushed keys stay close to the last one extracted, \( \ell \): Dijkstra's algorithm with integer weights at most \( C < W \), where every key pushed is in \( [ \ell , \ell + C ] \), and the event simulations with bounded delays.

A key \( k \) in \( [ \ell , \ell + W ) \) goes to the bucket \( k \bmod W \), a vector used as a stack, which holds a single key since the window is \( W \) wide; a key beyond it goes to the overflow. A bit per bucket tells whether it has items, so that the next key in use is found by scanning \( W / 64 \) words at most, from the bucket of \( \ell \) around the circle. When the overflow holds a key smaller than the first bucket in use (or the buckets are empty), its items in the window \( [ \ell' , \ell' + W ) \) of its least key \( \ell' \) move to the buckets, each once, a bucket of the radix heap at a time [see RadixHeap::extractBelow()]. Hence, with all the keys pushed in \( [ \ell , \ell + C ] \), \( C < W \), the overflow is never used, push() takes \( O( 1 ) \) time and pop() \( O( 1 + W / w ) \), \( w = 64 \), against the \( O( 1 + C ) \) of the scan of the buckets one by one; a key pushed farther costs its moves in the radix heap and one move into the window. The buckets keep their memory, so that a queue in a steady state calls no allocator, and their items are contiguous.

Between two episodes of a search, rebase( k ) lets the keys pushed next start from \( k \), below the last one extracted, provided that no key in the queue is below \( k \): the items of the buckets and of the overflow are placed again for \( \ell = k \), in \( O( n + W ) \) time. peekKey() gives the least key without moving \( \ell \), and extract( theta , out ) moves to out every item of key at most \( \theta \), in increasing order of the keys, reading the least key by peekKey(), so that the keys pushed next need only be not smaller than the last one moved.

The queue tells its changes through the subject policy Policy [see Modification.h], NoObservers by default, with which every operation compiles to the code of the plain queue, by the events of RadixHeap: Inserted by push(), after it, and Erased by pop() and extract(), before the removal, both with the item as the handle and its key, Cleared after clear() and Rebuilt at the end of a mute; the moves between the overflow and the buckets, and rebase(), change neither the items nor their keys, and tell nothing. The same item may be in the queue several times, and a batch coalesces its events by its key as well [see RadixHeap.h].

The contracts [see Contract.h]: a key pushed is not smaller than the last one extracted (any key before the first and after clear()), top(), topKey() and pop() need a queue that is not empty; the invariant, checked on queues of at most 1024 items, is that the bits tell the buckets in use and that the buckets and the overflow count size() items. The operations are defined in DialQueue.tpp.

See also
R. B. Dial, Algorithm 360: shortest-path forest with topological ordering, Communications of the ACM 12(11), 632-633, 1969, doi:10.1145/363269.363610
B. V. Cherkassky, A. V. Goldberg, T. Radzik, Shortest paths algorithms: theory and experimental evaluation, Mathematical Programming 73(2), 129-174, 1996, doi:10.1007/BF02592101
R. K. Ahuja, K. Mehlhorn, J. Orlin, R. E. Tarjan, Faster algorithms for the shortest path problem, Journal of the ACM 37(2), 213-223, 1990, doi:10.1145/77600.77615
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa