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

The heaps of ADS as heaps of LEMON, beyond the book: models of the concept lemon::concepts::Heap< PR , IM , CMP > (the file lemon/concepts/heap.h of LEMON 1.3 and of abLEMON), so that an algorithm of LEMON that takes its heap by its traits (Dijkstra, Prim, AStar, the bidirectional Dijkstra, CapacityScaling and the others) runs on a heap of ADS by one named template parameter, e.g.,. More...

#include "ADS/Contract.h"
#include "ADS/Modification.h"
#include "ADS/priority/IndexedDaryHeap.h"
#include <cstddef>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  ADS::lemon_interop::CmpKey< PR, CMP >
 a priority of LEMON as a key of ADS, ordered by the comparator CMP More...
class  ADS::lemon_interop::DaryHeap< PR, IM, CMP, D, Policy >
 an IndexedDaryHeap of ADS as a heap of LEMON, on the cross-reference map IM of the caller More...
class  ADS::lemon_interop::MonotoneHeap< Q, PR, IM >
 a monotone queue of ADS without decrease-key, Q either DialQueue< int , K > or RadixHeap< int , K >, as a heap of LEMON by the lazy deletion More...

Namespaces

namespace  ADS
namespace  ADS::lemon_interop

Detailed description

The heaps of ADS as heaps of LEMON, beyond the book: models of the concept lemon::concepts::Heap< PR , IM , CMP > (the file lemon/concepts/heap.h of LEMON 1.3 and of abLEMON), so that an algorithm of LEMON that takes its heap by its traits (Dijkstra, Prim, AStar, the bidirectional Dijkstra, CapacityScaling and the others) runs on a heap of ADS by one named template parameter, e.g.,.

using H = ADS::lemon_interop::DaryHeap< int , GR::NodeMap< int > >;
lemon::Dijkstra< GR , LM >::SetStandardHeap< H >::Create d( g , l );

(see Interoperation with LEMON). LEMON's protocol has two parts that are not in the signatures: the cross-reference map, from the items to int, is owned by the caller, and the algorithm writes it directly (Dijkstra::init() sets PRE_HEAP for every node without calling the heap), so that a heap derives the state of an item from the value in the map alone.

  • DaryHeap< PR , IM , CMP , D , Policy > runs on IndexedDaryHeap< K , D , Policy > [see IndexedDaryHeap.h]: the map holds, for an item in the heap, a slot of the heap of ADS (\( \ge 0 \)), and PRE_HEAP or POST_HEAP otherwise, as LEMON's FibHeap does; the slots are recycled by a list of the free ones, so that the heap of ADS has as many ids as the largest frontier, and the space is \( ( 4 + k ) s + 4 f + w f \) bytes for \( s \) items, \( f \) slots, keys of \( k \) bytes and items of \( w \). Each operation costs that of the heap of ADS, in \( O( \log_D s ) \) or \( O( D \log_D s ) \), plus one read of the map; with Policy = Dynamic<> an observer attached to subject() receives the events of the heap of ADS for every operation of the algorithm on its frontier, the handles being the slots (item() gives their items), which no heap of LEMON tells. The comparator must be stateless, since the heap of ADS compares its keys by <.
  • MonotoneHeap< Q , PR , IM > puts under the same concept a monotone queue without decrease-key, DialQueue or RadixHeap [see DialQueue.h, RadixHeap.h]: decrease() and increase() push a second copy of the slot, and the copies whose key is not the present priority of their slot, or whose slot left, are skipped when they reach the top (the lazy deletion); a slot is never reused before clear(). It is valid while every key pushed is not less than the last one popped, i.e., for Dijkstra's algorithm with nonnegative integer lengths, where a node is pushed at most once and the slots are at most \( n \); the window of DialQueue takes \( O( C ) \) buckets for lengths at most \( C \).

The concurrent queues of ADS (MultiQueue, LockFreePriorityQueue) are relaxed, and cannot be given to an algorithm of LEMON that takes a popped item as final.

The contracts [see Contract.h]: those of the concept of LEMON (top(), prio() and pop() on a heap that is not empty, decrease() and increase() on an item in the heap with a priority not greater, or not less, than its own), checked by those of the heap of ADS below, and, for MonotoneHeap, the monotone use. The heaps are defined in this file.

See also
B. Dezső, A. Jüttner, P. Kovács, LEMON - an open source C++ graph template library, Electronic Notes in Theoretical Computer Science 264(5), 23-45, 2011, doi:10.1016/j.entcs.2011.06.003
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
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa