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

The capabilities of the structures, beyond the book: what an algorithm may ask of its argument to choose the faster path at compile time, in one vocabulary shared by all the areas (see Capabilities). More...

#include "ADS/memory/Prefetch.h"
#include "ADS/priority/PriorityQueue.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <ranges>
#include <span>
#include <type_traits>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

struct  ADS::forwarding_query
 the base of the tags of the queries that a wrapper forwards to what it wraps More...
struct  ADS::stable_references_t
 the query of whether the items keep their addresses; by default enable_stable_references< S >, and both structures of a composition must have them More...
struct  ADS::thread_safe_reads_t
 the query of whether reads may run with other reads and with writes from other threads; false by default, and both structures of a composition must allow them More...
struct  ADS::rank_complexity_t
 the query of the time of rank(), so that an \( O( n ) \) rank is not taken for an \( O( 1 ) \) one; linear by default, the worse of the two in a composition More...
struct  ADS::event_set_t
 the query of the events of a structure, as std::type_identity of a mod::list; by default modifications_of< S >, and with no meet: a composition emits the events it declares More...

Namespaces

namespace  ADS
namespace  ADS::mod

Concepts

concept  ADS::declares_monotone
 whether S declares the only direction in which its values move
concept  ADS::forwarding_query_tag
 a tag of a forwarded query
concept  ADS::meetable_query
 whether the query T composes two answers
concept  ADS::bulk_insertable
 insert_bulk( r ) of the range \( r \) of items as one operation (the generic insertion of a range, the event BulkInserted)
concept  ADS::bulk_erasable
 erase_bulk( r ) of the range \( r \) of keys as one operation (the event BulkErased)
concept  ADS::splittable
 std::move( s ).split( k ), the keys before \( k \), its value and the keys after it (the set operations of Blelloch, Ferizovic and Sun, the cut of a batch)
concept  ADS::joinable
 S::join2( l , r ), the tree of the keys of \( l \) and of \( r \) when those of \( l \) are smaller (the union of Blelloch, Ferizovic and Sun in \( O( m \log( n / m + 1 ) ) \), the link of a batch)
concept  ADS::rankable
 rank( k ), the number of keys smaller than \( k \) (the order statistics); its time is the query rank_complexity_t
concept  ADS::selectable
 select( i ), the key of rank \( i \) (the order statistics); with an augmentation G, augSelect( p ), the first key whose prefix of the values of G satisfies the monotone predicate \( p \)
concept  ADS::prefetchable
 prefetch( k ), a hint that \( k \) (a key or its hash) is looked up next (a batch of lookups by group prefetching)
concept  ADS::reservable
 reserve( n ), room for \( n \) items (the builders)
concept  ADS::augmented_by
 augRange( lo , hi ), the values of the augmentation G of the keys in \( [ \mathit{lo} , \mathit{hi} ] \) combined, kept by the structure as S::Augmented (the aggregates of a range without a scan)
concept  ADS::range_actionable
 applyRange( lo , hi , a ), the action \( a \) applied to every value of the keys in \( [ \mathit{lo} , \mathit{hi} ] \) in \( O( \log n ) \) by a lazy tag (the lazy updates of a range)
concept  ADS::addressable
 an AddressablePriorityQueue with increase( h , p ) and erase( h ) on its handles as well (the open lists whose priorities rise, the native decrease-key)
concept  ADS::observes_values
 update( id ), the key of the item \( \mathit{id} \) read again from the table the queue observes (the queue of the open nodes as an observer of the node table, in the form of LaB-PQ, e.g., TableHeap)
concept  ADS::batch_extract
 extract( theta , out ), every item of priority at most \( \theta \) moved to out at once (the stepping algorithms, the bulk-synchronous search; IndexedDaryHeap, TableHeap, RadixHeap, DialQueue and BucketQueue, by its first key)
concept  ADS::shiftable_keys
 shift_all( delta ), every key moved by \( \delta \) in \( O( 1 ) \) (D* Lite, Generalized Adaptive A*)
concept  ADS::monotone_extract
 a queue whose extractions never decrease, with rebase(), which lets the next episode start below the last key extracted (the radix and Dial queues between the episodes of a search, RadixHeap and DialQueue)
concept  ADS::rekeyable
 rekey( f ), the key of each item recomputed by \( f \) and the order rebuilt in \( O( n ) \) (the change of the key function; IndexedDaryHeap)
concept  ADS::erasable
 erase( k ) of a key (the node tables that reuse their places within an episode)
concept  ADS::epoch_clearable
 clear() in \( O( 1 ) \) by epochs: a policy of clear(), T::Clear, that stamps the places, and epoch() (the node tables of a sequence of searches)
concept  ADS::undoable
 checkpoint() and rollback( t ) back to a checkpoint (a speculative change, a batch that exits by an exception)
concept  ADS::snapshotable
 snapshot(), a view of the present state in \( O( 1 ) \) which later changes do not touch (the audits, a persistent structure)
concept  ADS::in_arcs
 forEachIn( v , f ), the arcs entering \( v \) (the observers that repair a tree from the heads of the arcs that changed)
concept  ADS::stable_edge_ids
 arcId( u , v ), an id of the arc that does not change while the arc is in the graph (the observers that keep their data by arc)
concept  ADS::batch_updatable
 batch(), a group of changes told as one (the observers of a batch of changes)

Typedefs

template<class S>
using ADS::key_type_t = typename detail::key_type_of< S >::type
 the keys of S, which its lookups take: S::Key, else S::key_type, else S::value_type, else std::size_t (a position)
template<class S>
using ADS::modifications_of = typename detail::modifications_of< S >::type
 the events of S [see Modification.h], S::modifications if it declares them, the empty list otherwise: what an observer is checked against when it is attached
template<class Q>
using ADS::priority_t = typename detail::priority_of< Q >::type
 the priorities of the queue Q: Q::Priority, else Q::Key (the first key of a queue of two, e.g., BucketQueue), else its items

Enumerations

enum class  ADS::complexity { ADS::complexity::constant , ADS::complexity::logarithmic , ADS::complexity::linear }
 a class of time, from the cheapest More...
enum class  ADS::decrease_key_kind { ADS::decrease_key_kind::none , ADS::decrease_key_kind::lazy , ADS::decrease_key_kind::native }
 how a priority queue lowers the priority of an item: it cannot (none), by a new insertion and the stale copies skipped when they come out (lazy), by decrease() on its handle (native) More...

Functions

template<class S>
constexpr unsigned ADS::monotone_of (void)
 the directions in which the values of S may move, as the bits up and down of mod::effect: S::monotone if it declares it (e.g., static constexpr unsigned monotone = mod::effect::down; for a table of \( g \) under A*), every bit otherwise; an observer compiles out the path of a direction whose bit is not set
template<class Q>
constexpr decrease_key_kind ADS::decrease_key_of (void)
 how the queue Q lowers a priority: Q::decrease_key if it declares it (e.g., a queue whose decrease() is an insertion), else native if queue_decrease( q , h , p ) of QueueCustomization.h takes its handles (its member decrease( h , p ), or a free function for a queue of another library), else lazy if it is a PriorityQueue, else none (the shortest paths and Prim's algorithm)

Variables

template<class S>
constexpr bool ADS::enable_stable_references = false
 whether the items of S keep their addresses while they are in it, so that a handle may be a pointer and the structure never emits Relocated: an explicit opt-in, false unless a structure specializes it, since no syntax shows it; read by the default of stable_references_t, which the wrappers forward (the handles of the observers, the node tables of a search)
template<class T>
constexpr bool ADS::nonmonotone_values = false
 whether the values of the nodes of the table T may grow as well as fall, so that its concurrent fields are atomics under a seqlock instead of the monotone ones read without a lock: an explicit opt-in for the incremental searches whose \( g \) may rise (LPA*, D* Lite), false by default, so that A* pays nothing.
constexpr stable_references_t ADS::stable_references {}
 the tags of the queries
constexpr thread_safe_reads_t ADS::thread_safe_reads {}
constexpr rank_complexity_t ADS::rank_complexity {}
constexpr event_set_t ADS::event_set {}
template<class S, forwarding_query_tag T>
constexpr auto ADS::query_v
 the answer of S to the query T, at compile time: the static S::query( T() ) if it has one, T::fallback< S >() otherwise
template<class A, class B, meetable_query T>
constexpr auto ADS::query_meet_v
 the answer of the composition of A and B to the query T
constexpr detail::Query ADS::query {}
 the answer of \( s \) to the query of the tag \( t \), query_v< S , T >
constexpr detail::Reserve ADS::reserve {}
 room for \( n \) items in \( s \): s.reserve( n ), else reserve( s , n ) found by ADL, else nothing (the builders)
constexpr detail::Prefetch ADS::prefetch {}
 a hint that \( k \) is looked up next: s.prefetch( k ), else prefetch( s , k ) found by ADL, else nothing (a batch of lookups that prefetches the next ones, by group prefetching); on a pointer \( p \), prefetch( p ) and prefetch( p , l ) bring the line of \( p \) into the cache [see Prefetch.h]
constexpr detail::InsertBulk ADS::insert_bulk {}
 the items of the range \( r \) inserted in \( s \): s.insert_bulk( r ), else insert_bulk( s , r ) found by ADL, else s.insert( x ) for each item \( x \) of \( r \)

Detailed description

The capabilities of the structures, beyond the book: what an algorithm may ask of its argument to choose the faster path at compile time, in one vocabulary shared by all the areas (see Capabilities).

A capability is of one of three forms.

  • A syntactic capability is a concept on members, e.g., splittable< S > for split(), addressable< Q > for the handles of a priority queue with decrease(), increase() and erase(), undoable< S > for checkpoint() and rollback( t ). A concept proves the syntax only.
  • A semantic capability, which the syntax cannot show, is an explicit opt-in, as std::ranges::enable_borrowed_range of the standard: the variable templates enable_stable_references< S > (the addresses of the items do not change while they are in the structure) and nonmonotone_values< T >, the static members Q::decrease_key (how decrease_key_of() should take the queue) and S::monotone (the only direction in which the values of a structure move, read by monotone_of()).
  • A property that a wrapper must forward without knowing it is a query, s.query( ADS::stable_references_t{} ), in the form of the environments of P2300: a tag derived from forwarding_query, answered by a static member query( tag ) of the structure if it has one and by the default of the tag otherwise, and read at compile time by query_v< S , Tag > or by the customization point object query(). ObservedGraph and Observable forward every query to the graph they wrap (and answer the events themselves), Shadow intersects the answers of the two observers it composes by the meet() of the tag.

decrease_key_of< Q >() says how a priority queue lowers a key: native if it has decrease( h , p ) on its handles, lazy if it is a PriorityQueue without them, so that an item whose priority improves is inserted again and its stale copies are skipped when they come out, none if it is not a priority queue; the opt-in Q::decrease_key wins. The shortest paths and Prim's algorithm choose by it.

The free customization point objects, in the form of Niebler, exist only for the operations that a type ADS does not own may lack, one per operation and each with a default: reserve( s , n ) (nothing), prefetch( s , k ) (nothing, and on a pointer the line of memory of Prefetch.h) and insert_bulk( s , r ) (one insertion per item); those of the priority queues are in PriorityQueue.h.

Every capability says, in its comment, the algorithm that uses it; a capability whose members no structure of ADS has yet is defined all the same, since it is the name under which the next one will be found.

See also
E. Niebler, Suggested design for customization points, ISO/IEC JTC1 SC22 WG21 N4381, 2015, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
M. Dominiak, G. Evtushenko, L. Baker, L. R. Teodorescu, L. Howes, K. Shoop, M. Garland, E. Niebler, B. A. Lelbach, std::execution, ISO/IEC JTC1 SC22 WG21 P2300R10, 2024, https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html
G. E. Blelloch, D. Ferizovic, Y. Sun, Just join for parallel ordered sets, Proceedings of SPAA, 253-264, 2016, doi:10.1145/2935764.2935768
M. Chen, R. A. Chowdhury, V. Ramachandran, D. Lan Roche, L. Tong, Priority queues and Dijkstra's algorithm, Technical Report TR-07-54, The University of Texas at Austin, 2007, https://www3.cs.stonybrook.edu/~rezaul/papers/TR-07-54.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa