ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS Namespace Reference

Namespaces

namespace  distributed
namespace  eigen
namespace  graphblas
namespace  kahip
namespace  lemon_interop
namespace  metis
namespace  mod
namespace  networkit

Classes

class  AdaptiveRadixTree
 an ordered map from strings to values of type V on an adaptive radix tree More...
class  AhoCorasick
 the automaton of Aho and Corasick of a set of patterns More...
class  AliasTable
 < Philox4x64-10 More...
struct  AllPairs
 the distances, the predecessors and whether there is a negative cycle More...
struct  Amortized
 the policy of a sliding window whose operations cost \( O( 1 ) \) amortized time, by the algorithm that suits the algebra More...
class  Arena
 an arena of objects of type T in blocks of \( n \) More...
class  ArenaResource
 an arena of bytes in blocks of \( n \), the resource of a PoolAllocator More...
class  ArrayBinaryTree
 a binary tree in a positional vector More...
class  ArrayGraph
 a static graph with vectors of adjacency, all in one vector More...
class  ArrayQueue
 a QUEUE realized with a circular vector of a given capacity More...
class  ArraySequence
 a SEQUENCE realized with a vector that doubles when it is full More...
class  ArraySSet
 an SSet on a sorted vector, ordered by C More...
class  ArrayStack
 a STACK realized with a vector of a given capacity More...
class  ArrayUSet
 a USet on a vector in no order, the items equal by Eq More...
class  ArrowColumn
 a column of Arrow of numbers of type \( T \), taken without copy: its values stay in the memory of its producer, which this object releases when destroyed More...
struct  AssemblyWorkspace
 the scratch of compressTriplets(), which keeps its memory from one call to the next More...
class  Assignment
 an assignment of least cost of \( n \) rows to \( n \) columns, kept optimal after the changes of the costs, by the code of ADS or, if E is not void, by the engine E More...
class  AssignmentObserver
 the assignment of least cost of the \( k \) rows \( 0 , \ldots , k - 1 \) of \( g \) to its \( k \) columns \( k , \ldots , 2 k - 1 \), the weights of the edges between them the costs, kept up to date [see Assignment.h] More...
struct  AugmentEngine
 the engine of ADS, both solves by the augmentations how of FlowNetwork::maxFlow() [see MaxFlow.h] More...
struct  AVLBalance
 the AVL trees [see AVLJoin] More...
struct  AVLJoin
 the join of the AVL trees; A gives also height( t ), -1 for nil, which connect() keeps More...
class  AVLTree
 a DICTIONARY on an AVL tree, with the operations based on join [see Joinable] More...
struct  AVLTreeNodes
 the adaptor of the nodes of an AVLTree [see JoinAdaptor] More...
class  Backoff
 the exponential backoff of a waiting thread: \( 2^k \) pauses at the \( k \)-th call up to \( S \), then a yield to the system More...
class  Bag
 a USet that keeps the items equal to one another, on a hash table of groups More...
class  BalancedParentheses
 a static sequence of balanced parentheses with a range min-max tree More...
class  BasicCdcl
 conflict-driven clause learning with two watched literals, the free variables by activity in a Heap of pairs \( ( \mathit{activity} , v ) \), the largest on top: std::priority_queue by default, or a heap of Boost or of ADS [see DaryHeap.h], with the same decisions and conflicts, since the pairs are ordered totally More...
class  BasicCsrMatrix
 a sparse \( m \times n \) matrix of values T in compressed sparse rows, the columns of the type I and the offsets of the rows of the type P More...
class  BasicEliasFano
 a non-decreasing sequence of integers in the Elias-Fano representation, the inventories of select of \( H \) built in the constructor if not Lazy and at the first select of each value if Lazy [see RankSelect.h] More...
class  BasicRankSelect
 a static vector of bits with rank and select in \( O( 1 ) \) time, the inventories of select built in the constructor if not Lazy, and at the first select of each value if Lazy More...
class  Batch
 a batch of RAII on the structure \( s \) [see batch()] More...
class  BigInteger
 an integer of any length, sign and magnitude in base \( 2^{64} \) More...
class  BinaryFuseFilter
 a static filter of the keys of type T with fingerprints of type F, 3 places per key in 3 consecutive segments More...
class  BinaryTree
 a binary tree with pointers to the parent and to the two children More...
class  BinaryTrie
 a binary trie of the integers of \( w \) bits with the list of the leaves and the jump pointers, a SORTED SET with a value per key More...
class  BinnedSearch
 the search by interpolation of a sorted array of integers by bins More...
class  BinnedStringSearch
 the search by interpolation of a sorted array of strings by bins More...
class  BitmapTrie
 a trie of strings with the bitmaps of the children, the list of the strings and the smallest and largest string below each node More...
class  BitReader
 a stream of bits read forward from a place of a BitVector, which must outlive the reader More...
class  BitVector
 a vector of bits packed in words of 64 bits More...
class  BitWriter
 a stream of bits written at its end, on a BitVector More...
class  BlockBTree
 a B-tree of keys whose nodes are the blocks of a BlockStore More...
class  BlockedBloomFilter
 a filter of Bloom in blocks of 256 bits, 8 bits per item More...
class  BlockStore
 a disk of blocks of type T, read and written one at a time More...
class  BloomFilter
 a filter of Bloom of \( m \) bits and \( k \) hashes More...
class  BoolSet
 a set of integers in \( [ 0 , N ) \) as a boolean vector More...
struct  BoostMPICodec
 the bytes of a message by Boost.Serialization, in the packed archives of Boost.MPI, for MPICodec< Msg > More...
struct  Both
 the static observers of St, then those attached at run time More...
struct  Both< Static< O... >, Dynamic< L > >
 the static observers O..., then those attached at run time More...
class  BoundaryTagAllocator
 the dynamic storage allocation with boundary tags More...
struct  BoundedEdge
 an edge \( ( u , v ) \) with lower and upper bounds on its flow More...
class  BPlusTree
 a B+-tree of order \( m \), with the removal of exercise 14.8 of Morin's book More...
class  BPTree
 an ordered tree in \( 2 n \) bits by balanced parentheses, its nodes in preorder More...
class  BrentHashTable
 a hash table with double hashing and the insertion of Brent More...
class  BTree
 a DICTIONARY on a B-tree of minimum degree \( t \), its changes told through Policy More...
class  BTreeMap
 an ordered map on a B+-tree of nodes of \( B \) bytes, by the order less(), with the counts of the pairs below each child if R (the ranks) More...
class  BucketCuckooTable
 a DICTIONARY on the cuckoo hashing with buckets of 4 places More...
class  BucketHeap
 a BucketQueue behind the interface of a heap of pairs \( ( k , x ) \), the key \( k \) of packFG(): the inner queue of a MultiQueue over such keys [see MultiQueue.h], whose pushes and pops take \( O( 1 ) \) amortized time with bounded keys where those of a heap take \( O( \log n ) \). More...
class  BucketingFilter
 a static range filter of the keys of type T, \( B \) bits per key: the buckets of \( 2^w / ( n \, 2^{B-2} ) \) keys that hold a key of the set, \( w \) the bits of T, with no bound on the false positives of the queries near a key More...
class  BucketQueue
 a two-level bucket queue: least \( f \) first, then largest (or, by the policy Tie, least) \( g \), then LIFO More...
class  Buckets
 the structure with buckets of exercise 19.17: for \( k = 0 , 1 \) the nodes by the number \( h \) of their edges to \( V_k \), bucket( k , h ), its size dim( k , h ), and the least and largest bucket not empty; a node leaves a bucket in \( O( 1 ) \) by its place in it More...
class  BuddyAllocator
 the buddy system on \( 2^m \) words More...
class  BVGraph
 a static directed graph with the lists compressed by reference, copy blocks, intervals and gaps More...
struct  BWT
 the transform of Burrows and Wheeler: the last column of \( M' \) without the \( \$ \), and the row of the \( \$ \) More...
class  CanonicalHuffman
 the canonical prefix code of the given lengths of the symbols of type C More...
class  CarterWegmanHash
 \( h( k ) = ( ( a k + b ) \bmod p ) \bmod m \), of the class \( H_{p,m} \) of Carter and Wegman More...
class  CellHeap
 a heap of cells of two fields, with a mark-and-sweep collector More...
class  ChainedHashTable
 a hash table with lists of overflow More...
class  ChannelPort
 the channels of a family seen by one worker More...
struct  ChannelsOf
 the family of channels of an executor, as measured by bench/runtime.cpp (see Channels between workers): the mesh on every executor, which won the batches of 1 and of 64 messages and the round trips on the pool, OpenMP and FastFlow, with the trees a tie; a specialization may give an executor a family of its own More...
class  ChildListTree
 an ordered tree whose nodes keep the list of their children More...
class  Chooser
 the simulation of choice(), success and failure More...
class  CircularIterator
 the random-access iterator on the items of a circular vector of the capacity \( c \) whose first item is at the place \( \mathit{head} \), the item \( i \) at the place \( ( \mathit{head} + i ) \bmod c \) More...
struct  CoalesceBy
 the coalescing of the messages of one key in an outbox of Mailbox: K()( x ) the key of the message \( x \), and M the map from a key to the place of its last message in an outbox (try_emplace(), clear() and empty() as those of std::unordered_map, or of DenseHashMap and FlatHashTable, which allocate no node per key), by default (void) a std::unordered_map of the keys to std::size_t More...
class  CoalescedHashTable
 a hash table with coalesced lists in the table and a cellar More...
class  CompactRankSelect
 a static vector of bits with rank and select in 3.125% of its bits more for the rank and less than 0.8% for each select More...
class  CompoundHash
 the hash code of an object of \( r \) parts of section 5.3.2 of Morin's book, \( h( x_0 , \ldots , x_{r-1} ) = ( ( z \sum_i z_i x_i ) \bmod 2^{2w} ) \operatorname{div} 2^w \) with \( w = 64 \), the \( z_i \) random words and \( z \) a random odd integer of \( 2 w \) bits: two distinct tuples collide with probability at most \( 3 / 2^w \) (Theorem 5.3 of Morin's book), where the XOR or the sum of the parts make large sets of tuples collide (exercises 5.7 to 5.9) More...
class  CompressedPGMIndex
 the compressed PGM-index on a sorted array of arithmetic keys K, with the error \( \epsilon = E \) More...
class  ConcurrentCuckooTable
 a DICTIONARY shared by threads, by cuckoo hashing with a lock per region More...
class  ConcurrentFlatTable
 a DICTIONARY shared by threads, by linear probing on atomic words, that grows while they work and never removes; cleared in \( O( 1 ) \) by the policy EpochClear More...
class  ConcurrentPoolResource
 pools of the size classes of 8 bytes up to \( M \), a heap per thread, the objects freed by any thread More...
class  ConcurrentUnionFind
 the union-find of the elements \( [ 0 , n ) \) that threads change at once More...
struct  ConnectivityOp
 an operation on a graph whose edges come and go More...
class  ContiguousDeque
 a double ended queue whose items are contiguous, rebuilt in the middle of its vector when they reach an end More...
class  contract_violation
 a contract violated: a bug of the caller (a precondition) or of ADS More...
struct  CopyPhrase
 a phrase of the parsing of Ziv and Lempel: copy length symbols from distance places back, then append next, if any More...
class  CsrInput
 the offsets and the heads of a graph as arrays of X, and its weights as an array of Y, in place where the layouts agree and copied otherwise More...
class  CubishArrayStack
 a LIST by rank in three levels, \( O( 1 ) \) access and \( O( n^{1/3} ) \) amortized insertions and removals More...
class  CuckooFilter
 a dynamic filter of the keys of type T with fingerprints of type F (8 or 16 bits), 2 buckets of 4 places per key More...
class  CuckooHashTable
 a DICTIONARY on the cuckoo hashing, with a stash More...
class  CursorBinaryTree
 a binary tree on a vector of nodes linked by their places More...
class  CursorList
 a SEQUENCE realized with cursors in a CursorSpace More...
class  CursorSpace
 the vector of the cells of some CursorList, with its free list More...
class  CursorTree
 an ordered tree on a vector of nodes linked by their places More...
class  DaryHeap
 a \( D \)-ary heap of plain items, the best one by better() on top; pop() by the walk down from the top, or from the bottom up if BottomUp More...
class  DenseHashMap
 a hash map with its pairs in a dense vector and an index of positions, its changes told through Policy More...
class  DenseMatrix
 an \( m \times n \) matrix by rows in one contiguous vector More...
class  DequeFrontier
 a deque as \( S \), the rule of Pape and D'Esopo: a node at the tail the first time, at the head afterwards, extracted from the head More...
class  Dequeue
 a DEQUEUE on a bidirectional list with pointers More...
class  DfsSchema
 the discovery and finish times and the kind of each edge, the procedure dfs-schema of the book More...
class  DialQueue
 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...
class  DictionarySet
 a set on a DICTIONARY D, an item being a key: a USet of Morin if D is a KeyedDictionary, an SSet if it is an OrderedDictionary More...
class  DirectAccessCodes
 a static sequence of integers of variable length with direct access More...
class  DirectTable
 the table with direct access of the keys in \( [ a , b ] \), \( H( k ) = k - a \): every operation in \( O( 1 ) \) time, \( b - a + 1 \) places of memory More...
class  DisjointSets
 the union of disjoint sets of \( [ 0 , n ) \), the roots joined by L, the paths shortened by C, the links of the roots told through Policy More...
class  DiskFile
 a file of items on the disk of the model, in blocks of \( B \) items More...
class  DiskReader
 reads a file through a buffer of one block, \( B \) items of the memory More...
class  DiskWriter
 appends to a file through a buffer of one block, \( B \) items of the memory; the last partial block is written by close() or by the destructor More...
class  DistributedMin
 the minimum over the processes of a value of each, by reductions that do not block More...
class  DLeftHashTable
 a DICTIONARY on \( d \) tables of lists, a key in the shortest of its \( d \) lists More...
class  DotProductHash
 \( h( k ) = \sum_i a_i k_i \bmod m \), the \( k_i \) being the digits of \( k \) in base \( m \) More...
class  DualArrayDeque
 a LIST by rank on two stacks S back to back, balanced More...
struct  Dynamic
 observers attached at run time, the events those of the structure (or the list L, which must be them) More...
class  DynamicCsr
 a sparse matrix by rows, with indices of type I and values of type V, whose rows are appended and removed More...
class  DynamicPGMIndex
 the ordered map from the arithmetic keys K to the values V of the dynamic PGM-index, with the error \( \epsilon = E \) in the levels, the ratio \( B \) of the sizes of two levels and the least capacity \( I \) of a level with a PGM-index More...
struct  EdgeDeleted
 an edge deleted, \( w \) the weight that it had More...
struct  EdgeInserted
 an edge \( ( u , v ) \), or \( [ u , v ] \) with \( u < v \), inserted with the weight \( w \) More...
class  Eertree
 the eertree (palindromic tree) of a string, built a byte at a time More...
class  EliasFanoGraph
 a static directed graph with its adjacency lists in Elias-Fano More...
struct  EpochClear
 the clear() of ConcurrentFlatTable in \( O( 1 ) \) by epochs: a stamp of the unsigned type \( S \) per group of 8 places, the group in use only if its stamp is the epoch that clear() raises More...
struct  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...
class  EventCount
 the sleep of threads until a condition holds, woken by notify() More...
class  EventQueue
 the queue of the events, the recompute policy P [see ReoptPolicy] and the counts that the observers share More...
class  ExactCover
 the exact cover of the primary items, with the secondary ones at most once, on dancing links More...
class  FastExactCover
 the exact cover with colors on sparse sets, the dancing cells More...
class  FastFlowExecutor
 the executor on a ParallelFor of FastFlow More...
class  FastFlowLock
 the spin lock of FastFlow, ff::lock_t, as a mutex of the standard More...
struct  FastHash
 the hash of the values of T, for the integers, the enumerations, the pointers, the floating point numbers (\( +0 \) and \( -0 \) the same) by hashWord(), and the strings by hashBytes() More...
struct  FastHash< const char * >
 the hash of a C string, that of its characters More...
struct  FastHash< std::string >
 the hash of a std::string, that of its characters More...
struct  FastHash< std::string_view >
 the hash of a string, by its bytes; any std::string_view, std::string and C string with the same characters hash the same More...
class  Fenwick
 the prefix aggregates of \( n \) values of the monoid G More...
class  FenwickObserver
 the prefix aggregates of the values of an array of values of G that tells its changes [see ObservableArray], a Fenwick< G > kept by its events More...
class  FibonacciCache
 the numbers of Fibonacci, those computed kept between the calls More...
class  FibonacciHeapPriorityQueue
 a priority queue on a Fibonacci heap, a collection of trees heap ordered whose roots are in a circular list More...
class  FingerprintPerfectHash
 a minimal perfect hash function of a static set of keys by levels of fingerprints More...
class  FingerTreap
 a DICTIONARY on a treap with the parents, the sizes and the extremes of the subtrees, searched from a finger More...
class  FlatHashTable
 a hash table with open addressing and control bytes in groups of 15 More...
class  FlatLoserTree
 the tree of losers of \( k \) sources with the keys in its nodes, the winner the smallest key by less, the lower source on equal keys More...
class  FlowNetwork
 a network of flow with integer capacities More...
class  FMIndex
 the FM-index of a text: its transform with the counts for the rank every \( b \) places and the places of the suffixes at the multiples of \( \mu \) More...
struct  forwarding_query
 the base of the tags of the queries that a wrapper forwards to what it wraps More...
class  FrontCodedDictionary
 a sorted dictionary of strings in the front coding, with anchors More...
struct  FrontierCounts
 what a run of the prototype did: the nodes added to \( S \) (the lines (1) and (3)), the extractions (2), the decreases of a priority (4) and the edges examined; the same on two frontiers that extract the nodes in the same order More...
class  GrafiteFilter
 a static range filter of the keys of type T, \( B \) bits per key, with false positive probability at most \( \ell / 2^{B-2} \) for a range of \( \ell \) keys, whatever the keys and the range More...
class  GraphBuilder
 the nodes and the edges of a graph collected one at a time, then frozen into a StaticGraph or an ArrayGraph More...
struct  GraphEvents
 the kinds of event as bits of a mask More...
class  GraphNodes
 the nodes, their labels and the counts shared by the realizations More...
class  GridGraph
 the implicit graph of a grid map, the cells of cost \( C \) and the weights of the moves of type \( W \), whose changes of the costs are told through the subject policy Policy [see Modification.h] More...
struct  GridSquare
 a square of a matrix: its side and its upper left cell More...
struct  Growth
 the order \( c^n n^p \log^q n ( \log \log n )^r \), and whether it is only an upper bound More...
class  HashedTreap
 a DICTIONARY on a treap whose priorities are the hashes of the addresses of the nodes More...
class  HashMultiset
 a multiset on a hash table, a counter of occurrences per item: the insertion of a new item sets it to 1, of an item already there adds 1, the removal subtracts 1 and removes the item at 0 (exercise 8.10) More...
class  HeapPriorityQueue
 a priority queue on a \( d \)-ary min-heap of bounded capacity, \( d \) the parameter D More...
class  HuffmanFMIndex
 the FM-index of a text on the wavelet tree of Huffman of its transform, with the places of the suffixes at the multiples of \( \mu \) More...
class  HuffmanWaveletTree
 a static sequence of symbols in about \( H_0 + 1 \) bits each, with access, rank and select in time proportional to the length of a code; RS is the rank and select of its bits, RankSelect or CompactRankSelect More...
class  HugePageAllocator
 an allocator of objects of type T, on huge pages for the large blocks More...
class  InboxChannels
 the inboxes as stacks of Treiber of batches [see MPSCInbox.h] More...
class  IncidenceGraph
 an oriented graph on its matrix of incidence, kept by columns More...
class  IndexedDaryHeap
 a \( D \)-ary heap of the ids \( [ 0 , n ) \) by their keys, the least on top, with decrease-key, its changes told through Policy More...
class  IndexedHeapPair
 the ids \( [ 0 , n ) \) by a key, the least on top, with the least of their bounds More...
class  IndexedSkipList
 a DICTIONARY on a skip list with the widths of the links, which reaches a key by its rank More...
class  IndexIterator
 a forward iterator along the cells C of a vector linked by the index in the member Next, on the items V in the member Value; -1 is the end More...
struct  IndexPlaces
 the places of 8 bytes of PointerTable: the high 32 bits of the hash and the index plus 1 of the object in the store \( S \), which gives at( i ) and index( p ) [see the file] More...
class  IndirectIterator
 the random-access iterator I on pointers read through them, *it being **base; the items are constant More...
class  InterleavedRankSelect
 a static vector of bits with its counts inside its lines, rank with one access to the memory More...
class  IntervalHeap
 an interval heap of plain items: the best and the worst by better() More...
class  IntervalTree
 a multiset of closed intervals of T with stabbing queries More...
class  JacobsonTree
 a binary tree in \( 2 n + 1 \) bits, its nodes by levels More...
class  Joinable
 the operations based on join of the tree T of keys Key and values Value, whose nodes A adapts [see JoinAdaptor], each the function of JoinAlgorithms of the same name: a base of T (which makes A its friend); A is read only in the bodies, as T is incomplete where its bases are named, and gives take( t ), the root of \( t \) taken out of it, which is left empty; put( t , r ), \( r \) the new root of the empty \( t \), which updates its size; peek( t ), its root; fresh( t ), an empty tree like \( t \); valid( t ), the invariant of \( t \); salt( t ) and make( k , v , s , i ), a node alone of the pair \( ( k , v ) \), the \( i \)-th of a batch of salt \( s \), which may be called in parallel More...
struct  JoinAlgorithms
 the algorithms on the trees whose only balancing is the join of A; each of them consumes the trees it is given and returns the trees it makes More...
class  JoinTree
 a DICTIONARY on a binary search tree balanced by the join of B alone, augmented by G, whose changes go to the observers of the subject policy Policy [see Modification.h] More...
struct  JoinTreeNodes
 the adaptor of the nodes of a JoinTree [see JoinAdaptor] More...
class  K2Tree
 the adjacency matrix of a static directed graph as a \( k^2 \)-tree More...
class  KeyIterator
 the member first of what the iterator I reads, with the category of I up to bidirectional More...
class  KokkosExecutor
 the executor on an execution space of the host of Kokkos More...
class  LaneChannels
 the inboxes as queues with a lane per sender [see MPSCQueue.h] More...
struct  LargestSecondKey
 the order of BucketQueue among the items of one \( f \): the largest \( g \) first (A*, toward the deeper nodes), the default More...
class  LAVector
 a non-decreasing sequence of integers of 64 bits as the segments of an optimal piecewise linear approximation and the corrections of the items More...
class  LceIndex
 the longest common extensions of the suffixes of a text, \( O( 1 ) \) each, on unsigned integers I of 32 or 64 bits More...
struct  LeastSecondKey
 the order of BucketQueue among the items of one \( f \): the least \( g \) first, i.e., the lexicographic order of the pairs \( ( f , g ) \) (the keys of LPA*) More...
class  LeftLeaningRedBlackTree
 a DICTIONARY on the left-leaning red-black tree of Morin, a simulated 2-4 tree More...
class  LinearCongruential
 the generator \( X_{n+1} = ( a X_n + c ) \bmod m \), \( m = 0 \) meaning \( 2^{64} \) More...
class  LinearCongruentialT
 the generator \( X_{n+1} = ( a X_n + c ) \bmod m \) of LinearCongruential with \( a , c , m \) fixed at compile time, \( m = 0 \) meaning \( 2^{64} \): a UniformRandomBitGenerator, as min() and max() are constant More...
class  LinkCutTree
 a forest of dynamic trees whose nodes have values of the type T, aggregated on the paths by the commutative monoid Op, its changes told through Policy More...
class  LinkedHashSet
 a set on a hash table whose foreach follows the order of insertion: a LIST keeps the items in that order and the table maps each item to its position, so insert(), remove() and contains() take \( O( 1 ) \) expected time and forEach() \( O( n ) \) (exercise 8.9) More...
class  LinkedHeapPriorityQueue
 a priority queue on a heap with pointers, which keeps a pointer to the last leaf if L More...
class  LinkedIterator
 a forward iterator along the cells C linked by the member Next, on the items V in the member Value; nil is the end More...
class  LinkedQueue
 a QUEUE realized as a singly linked list with a front and a back More...
class  List
 a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled More...
class  ListGraph
 a graph with lists of adjacency More...
class  ListMFSet
 the union of disjoint sets on lists, each element with the head of its list More...
class  ListPriorityQueue
 a priority queue on a list, sorted by priority if Sorted, unsorted otherwise More...
class  ListSet
 a set as an unsorted list More...
class  ListXFastTrie
 the x-fast trie of a doubly linked list and \( w + 1 \) hash tables (exercise 13.2 of Morin's book) More...
class  LockedChannels
 the inboxes as vectors under a lock, the portable baseline More...
class  LockFreePriorityQueue
 an exact PRIORITY QUEUE shared by threads, linearizable and lock-free: the skiplist of Lindén and Jonsson, its deleted prefix cut in batches More...
class  LoserTree
 the tree of losers of \( k \) players, the winner the smallest key by less More...
class  LoudsTree
 an ordered tree in \( 2 n + 1 \) bits by LOUDS, its nodes by levels More...
struct  LZ77Phrase
 a phrase of LZ77: copy length symbols from distance back, then next (none at the end of the text); distance is 0 when length is 0 More...
struct  LZ78Phrase
 a phrase of LZ78: the phrase id followed by next More...
struct  LZSSPhrase
 a phrase of LZSS: a copy of length symbols from distance back, or the literal when distance is 0 More...
class  Mailbox
 the mailbox of \( p \) workers on the channels Ch (by default the mesh, the family that DefaultChannels gives every executor), with outboxes of batches, the detection of the termination, the stop and the recovery of the messages left, and the coalescing of the messages of one key in an outbox by the policy Co More...
class  MappableAllocator
 std::allocator, which also makes a vector over the bytes of a mapped file [see restoreMapped()]; an item constructed with no argument is value-initialized if \( V \), else left uninitialized (the numbers about to be written of a matrix) More...
class  MappedFile
 a whole file mapped privately in memory, shared by its copies More...
class  MaterializedAggregate
 the combination by the commutative monoid G of the values of the pairs of a dictionary, kept by its events; for an abelian group of inexact values, recomputed from the structure bound every Period changes More...
class  MatrixGraph
 a graph with an adjacency matrix More...
struct  MaxAugmentation
 the largest of the values, whose identity is \( -\infty \) if V has it, its smallest value otherwise: a commutative and selective monoid More...
class  MaxFlowObserver
 the maximum flow from \( s \) to \( t \) in \( g \), the weights the capacities, kept up to date, the solves made by the engine E, the augmentations of ADS by default More...
struct  MaxOf
 the selective commutative monoid of the largest value of T, of identity \( -\infty \) if T has it, its least value otherwise More...
class  MeasuredSearchTree
 a DICTIONARY on a binary search tree whose nodes keep the size, the depth and the height of their subtree More...
class  MeldableHeap
 a randomized meldable heap, the smallest item by less on top More...
class  MemoryLease
 \( k \) items of the internal memory, taken on construction and given back on destruction More...
struct  MergeCounts
 what a run of kruskal() did: the merges tried and those that joined two components More...
class  MeshChannels
 the \( p^2 \) bounded queues of the pairs of workers [see SPSCQueue.h] More...
class  MFSet
 the union of disjoint sets on a forest More...
class  MinBoard
 the least of the keys of \( p \) threads, one slot of a line of cache per thread, published and read by relaxed accesses More...
class  MinDeque
 a double ended queue with its least item in \( O( 1 ) \) amortized time More...
class  MinimalPerfectHash
 a minimal perfect hash function of a static set of keys by pilots More...
class  MinMaxHeap
 a min-max heap of plain items: the best and the worst by better() More...
struct  MinOf
 the selective commutative monoid of the least value of T, of identity \( +\infty \) if T has it, its largest value otherwise More...
class  MinQueue
 a QUEUE with its least item in \( O( 1 ) \) amortized time More...
class  MinStack
 a STACK with its least item in \( O( 1 ) \) time More...
class  Montgomery64
 the arithmetic modulo an odd \( n \) of 64 bits in the form of Montgomery, \( x R \bmod n \) with \( R = 2^{64} \); the numbers in the form are below \( n \) More...
class  MoveRIndex
 the r-index of a text on move structures: count and locate with each step in \( O( 1 ) \) time More...
class  MoveStructure
 a permutation of \( [ 0 , n ) \) that shifts each of its intervals alike, with the image of a place and its interval in \( O( 1 ) \) time More...
class  MPIByteMailbox
 the mailbox of the processes of a communicator for messages of bytes, each with a tag of its own, in batches of records More...
struct  MPICodec
 the customization point of the messages that are not trivially copyable for MPIMailbox: a specialization MPICodec< Msg > has static void encode( const Msg & x , std::vector< std::byte > & out ), which appends the bytes of \( x \) to out, and static Msg decode( std::span< const std::byte > b ), which rebuilds the message from exactly the bytes that encode() appended; ADS gives those of std::string and of std::vector< T > for a trivially copyable \( T \) More...
struct  MPICodec< std::string >
 the bytes of a string More...
struct  MPICodec< std::vector< T > >
 the bytes of a vector of trivially copyable items More...
class  MPIEnvironment
 MPI started for the life of the object, and ended with it. More...
class  MPIExecutor
 the processes of a communicator, one worker each More...
class  MPIMailbox
 the mailbox of the processes of a communicator, with outboxes of batches and the detection of the termination by the four counters of Mattern: for a trivially copyable Msg, the batches are arrays of messages, copied as bytes; otherwise [see the specialization below] each message is a record of the bytes that MPICodec< Msg > gives More...
class  MPIMailbox< Msg, false >
 the mailbox of the processes of a communicator for the messages that are not trivially copyable, each the record of the bytes that MPICodec< Msg > gives, on an MPIByteMailbox (the same waves, the same stop and the same leftovers()) More...
class  MPMCQueue
 a bounded queue of many producers and many consumers More...
class  MPSCInbox
 an inbox filled by many threads and emptied by one, lock-free More...
class  MPSCQueue
 an unbounded queue from many producers to one consumer, a lane each More...
class  MultiplicativeHash
 the multiplicative hashing of section 5.1.1 of Morin's book, \( \mathrm{hash}( x ) = ( z x \bmod 2^w ) \operatorname{div} 2^{w-d} \) on a table of \( 2^d \) places, \( z \) a random odd word and \( x \) the hash code Code( k ) of the key More...
class  MultiplyShiftHash
 \( h( k ) = ( a k \bmod 2^h ) \operatorname{div} 2^{h - l} \), with \( a \) odd More...
class  MultiQueue
 a relaxed PRIORITY QUEUE shared by threads: \( n \) queues under locks, the pop from the better of two, each queue an H behind two buffers More...
class  MultiSearcher
 the search of many patterns at once, by a SIMD filter or by the automaton of Aho and Corasick More...
class  MultiStack
 \( k \) stacks sharing a vector of linked cells More...
class  NeumaierSum
 a sum of values of T that follows additions and subtractions, with the compensation of Neumaier when T is floating and it is asked: the error after \( k \) terms is then of the order of \( \varepsilon \) times the sum of their absolute values, instead of \( k \varepsilon \) times More...
struct  no_rebuild_t
 the promise of quiet( s , no_rebuild ): nobody needs to know More...
struct  NoAugmentation
 no augmentation: nothing is kept, nothing computed More...
struct  NoCoalescing
 no coalescing of the messages in the outboxes of Mailbox: no member and no code, and no send() with a merge; the default More...
struct  NodeDeleted
 a node deleted, after the deletion of its edges More...
struct  NodeInserted
 a node inserted More...
struct  NoObservers
 nobody listens: the subject is empty and every test is false at compile time, so that the structure compiles to its plain code More...
struct  NotJoinable
 the base of a binary search tree that is not balanced: no operation based on join, whose recursion would be as deep as the tree More...
class  ObjectPool
 a pool of objects of type T in blocks of at most \( n \) slots More...
class  ObservableArray
 an array of values of T whose changes are told through Policy More...
class  ObservedGraph
 the graph \( g \), whose changes are sent through the subject policy Policy [see Modification.h] More...
class  OpenHashTable
 a hash table with open addressing More...
class  OpenMPExecutor
 the executor on the threads of OpenMP More...
class  OpenMPLock
 the lock of OpenMP, omp_lock_t, as a mutex of the standard More...
struct  OptimalSearchTree
 an optimal binary search tree on the keys \( 0 , \ldots , n - 1 \): its cost, its root and the children of each key, \( -1 \) for none (and for the root of the empty tree) More...
class  OrderedMinimalPerfectHash
 the function of Czech, Havas and Majewski that maps \( \mathit{keys}[ i ] \) to \( i \) More...
class  OrderMaintenanceList
 a list of items of type T whose order between two elements is tested in \( O( 1 ) \) by labels on two levels More...
class  PackedArray
 \( n \) unsigned fields of \( B \) bits, \( 64 / B \) to a word, the values above \( 2^B - 1 \) clamped to it if Saturate More...
class  PackedBitReader
 reads the bits of a sequence of bytes in the order of a PackedBitWriter, and zeros past its end More...
class  PackedBitWriter
 a growing sequence of bits, packed in bytes, the first bit in the most significant bit of the first byte More...
class  PairingHeap
 a priority queue on a pairing heap, two-pass, or auxiliary two-pass if Aux More...
class  ParentTree
 a tree (a forest) of the nodes \( 0 , \ldots , n - 1 \) as a vector of parents More...
class  PartialRebuildingTree
 a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P More...
struct  Partition
 a partition of the nodes of a graph into \( k \) parts More...
class  PartitionedBloomFilter
 a filter of Bloom of \( r \) parts of \( m / r \) bits, a hash for each part More...
class  PartitionedEliasFano
 a static strictly increasing sequence of integers in blocks, each coded as full, as a vector of bits or by Elias-Fano, with access() and nextGEQ() More...
class  PathIterator
 a bidirectional iterator on the nodes of a binary tree of the owner O in symmetric order, by the policy P with the static functions root( o ), left( n ), right( n ) (nil for no child) and read( n ); the items are constant, and the end is the empty path More...
class  PatriciaTrie
 a sorted dictionary of strings on a Patricia trie, with the blind search More...
class  PerfectHashTable
 a static SET of integers on the two-level perfect hashing More...
class  PermutedBuckets
 a set of values below \( 2^w \), permuted by \( x \mapsto ( a x + c ) \bmod 2^w \) and split by the top bits of the images into buckets of \( L \) items on average More...
class  PersistError
 the error of a file (or a stream, or a buffer) of a structure that cannot be read: not a file of ADS, of another structure or version, truncated, corrupted, or refused by the system More...
class  PersistReader
 the archive that reads the members of a structure [see restore()] More...
class  PersistWriter
 the archive that writes the members of a structure [see store()] More...
struct  PForDeltaBlock
 a block of values coded by PForDelta More...
class  PGMIndex
 the PGM-index on a sorted array of arithmetic keys K, with the error \( \epsilon = E \) at the last level and \( \epsilon_r = R \) at the others More...
class  PhiloxT
 Philox4xW-10, the counter-based std::uniform_random_bit_generator of words of \( W \) bits (32 or 64) of Salmon, Moraes, Dror and Shaw, with the sequence of std::philox4x32 and std::philox4x64 of C++26. More...
struct  Piece
 an interval \( [ \mathit{start} , \mathit{end} ) \) of the program on a processor More...
class  PlusMinusOneRangeMinimum
 the range minima of an array whose adjacent items differ by 1 More...
class  PmrResource
 the resource \( r \) of ADS as a std::pmr::memory_resource More...
struct  Point
 a point of the plane, of integer coordinates More...
class  PointerGraph
 an oriented graph of node objects linked by pointers More...
class  PointerTable
 a hash table of pointers to objects found by their keys, on the places of ADS (the inspection above), its insertions told through Policy More...
class  PoolAllocator
 the standard allocator of objects of type T over the resource R More...
class  PoolResource
 pools of the size classes of 8 bytes up to \( M \), for one thread at a time More...
class  PositionIndex
 the positions of objects of type T, by their addresses More...
class  PPMModel
 the model of contexts of PPM, version C with exclusion, of order \( K \) on the symbols \( [ 0 , \sigma ) \) More...
class  PrefixFilter
 an incremental filter of at most \( n \) keys of type T: bins of 25 fingerprints of 8 bits over 25 quotients, the overflow in a spare More...
class  PreorderArrayTree
 an ordered tree in a vector of ( parent , value ) in preorder More...
class  PriorityFrontier
 a priority queue of the nodes [see PriorityQueue.h] as \( S \): the priority of a node its distance or, if the priority is a pair, the pair ( distance , node ), which breaks the ties by the names of the nodes, so that any priority queue extracts the same nodes in the same order. More...
class  Probing
 a sequence of inspection \( H( k , i ) \) of an OpenHashTable More...
struct  Product128
 the product \( a b \) on 128 bits, its low and its high half More...
class  QueueFrontier
 a queue as \( S \), enqueue() and dequeue(): first in, first out, so that a node leaves S at most n times unless a negative cycle is reachable More...
class  QuicksortAdversary
 the adversary of McIlroy: a comparator of \( n \) items that gives them their values while a quicksort runs More...
class  Quiet
 a mute of RAII on the structure \( s \) [see quiet()] More...
class  RadixHeap
 a monotone queue of items with integer keys of the type K, the least key first, in buckets by digits of \( B \) bits More...
class  RadixTree
 a DICTIONARY of strings on a compact trie More...
class  RandomizedSearchTree
 a DICTIONARY on a randomized binary search tree of Martínez and Roura More...
class  RandomQueue
 a bag from which pop() takes an item uniformly at random More...
class  RangeDecoder
 the decoder of a RangeEncoder on \( w \) bits More...
class  RangeEncoder
 the integer arithmetic encoder of Witten, Neal and Cleary on \( w \) bits More...
class  RangeMinimum
 the range minima of an array by Bender and Farach-Colton: the Cartesian tree, its Euler tour, and the minima of the depths along the tour More...
class  RangeTree
 a multiset of points of \( T \times T \), with the count of the points of a rectangle More...
struct  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...
class  RankIterator
 the random-access iterator on the items of a container C read by rank, c[ i ] the item \( i \), of the type T More...
struct  RankSelectOptions
 the values whose select a directory answers: a structure that needs only rank, or one of the selects, spares the inventories of the others More...
class  Rational
 a fraction in lowest terms, the denominator positive More...
struct  RatioPolicy
 the default recompute policy: from scratch when the net events exceed \( \rho \) times the size, a repair abandoned when its work exceeds \( \alpha \) times that of a computation from scratch or when an element is extracted again more than \( \beta \) times; the values that are not exact (floating point) summed again after \( \mathit{period} \) times the size of changes, by the compensated sum of Neumaier when asked More...
class  RealTimeMinDeque
 a double ended queue with its least item, every operation in \( O( 1 ) \) worst-case time More...
class  RealTimeMinQueue
 a QUEUE with its least item, every operation in \( O( 1 ) \) worst-case time More...
class  RearCodedDictionary
 a sorted dictionary of strings in the rear coding with buckets, in one string of bytes More...
class  RecordFile
 a file of records of a trivially copyable type on the disk More...
class  RecordWriter
 appends to a RecordFile through a buffer of records, the file opened only to write the buffer More...
class  RecSplit
 a minimal perfect hash function of a static set of keys by recursive splitting, with leaves of at most L keys More...
struct  RedBlackBalance
 the Red-Black trees [see RedBlackJoin] More...
struct  RedBlackJoin
 the join of the Red-Black trees, whose ranks are the black heights; A gives also red( t ), false for nil, and paint( t , red ) More...
class  Refused
 a change refused by the prepare() of an observer, before anything changed More...
class  RemUnionFind
 the union of disjoint sets of the elements \( 0 , \ldots , n - 1 \) More...
struct  Reopt
 how a query of an observer brought its solution up to date (the outcomes, \( 0 \) to \( 2 \)), and why (the causes, which refine the outcome from scratch and the repair) More...
struct  ReoptStats
 what a recompute policy reads: the work is a count of elementary operations of the observer (nodes, edges, extractions), never a time, so that a policy decides the same on every machine More...
class  Reservation
 a place reserved by the least of the iterations that want it More...
class  RibbonFilter
 a static filter of the keys of type T with results of type F, one equation of 64 coefficients per key More...
class  RIndex
 the r-index of a text: count and locate in space proportional to the runs of its transform More...
class  RingDeque
 a double ended queue on a circular vector of \( 2^k \) places that doubles More...
class  RoaringBitmap
 a set of integers of 32 bits as a Roaring bitmap More...
class  RollbackUnionFind
 the union of disjoint sets of \( [ 0 , n ) \) by rank, with no compression, whose merges can be undone More...
class  RootishArrayStack
 a LIST by rank on blocks of \( 1 , 2 , \ldots , r \) places, with \( O( \sqrt{n} ) \) places wasted More...
class  RRRBitVector
 a static vector of bits compressed to its entropy, with rank and select More...
struct  RsaKey
 a key \( ( N , e ) \) More...
class  ScapegoatTree
 a DICTIONARY on a scapegoat tree of height at most \( \log_b q \), whose nodes keep the size of their subtree if StoredSizes More...
class  SearchTree
 a binary search tree, balanced as a Red-Black tree if RB, and then with the operations based on join [see Joinable] More...
struct  SearchTreeNodes
 the adaptor of the nodes of a Red-Black tree [see JoinAdaptor] More...
struct  Segment
 a segment \( D[ f .. f + \ell - 1 ] \) of the array and its sum, with \( f \) the place first and \( \ell \) the length More...
class  SEList
 a list of blocks of \( b - 1 \) to \( b + 1 \) items, with \( O( n / b ) \) pointers More...
class  SellMatrix
 a sparse matrix of doubles in SELL- \( C \)- \( \sigma \), chunks of \( C \) rows (4 by default, the fastest on a Xeon Gold 5120 with AVX-512: the gathers of 8 lanes cost more than they save) More...
class  SenderExecutor
 the executor on a scheduler of the senders More...
class  SequenceHash
 the hash code of the arrays and of the strings of section 5.3.3 of Morin's book, a polynomial over the prime field of \( p = 2^{61} - 1 \) with an end marker, \( h( x_0 , \ldots , x_{r-1} ) = ( \sum_i x_i z^i + ( p - 1 ) z^r ) \bmod p \) More...
class  SequenceHeap
 the sequence heap of plain items, the best one by better() on top More...
class  SequenceRange
 the items of a SEQUENCE as a range of C++ More...
class  SequenceStack
 a STACK simulated with the operations of a SEQUENCE S, the top first More...
class  Sequential
 the executor of the calling thread alone, which makes the calls in their order More...
class  Shadow
 an observer that forwards every event to an incremental observer and to one that computes from scratch, and compares their answers at each query by Eq: an audit of the incremental one by recomputation, at a cost of about twice the work More...
class  ShortestPathsObserver
 the shortest paths from \( r \) in \( g \), kept up to date, by the recompute policy P More...
struct  ShortestPathTree
 the result: the distances, infinity() if not reachable, the tree of the parents, NIL for \( r \) and the unreachable nodes, the nodes in the order of extraction from \( S \), and whether a negative cycle was found More...
class  SimpleBinaryTrie
 a binary trie of the integers of \( w \) bits with no list and no jump pointers (exercise 13.1 of Morin's book) More...
class  SingleWriterFlatTable
 a DICTIONARY that one thread writes and many threads read at once, by linear probing on atomic words, with no read-modify-write per insertion, readers that read on while it grows, and no removal; cleared in \( O( 1 ) \) by the policy EpochClear More...
class  SinglyList
 a SEQUENCE realized as a singly linked list with no sentinel More...
class  SizeClassAllocator
 an allocator of small blocks by size classes, for one thread More...
class  SkipList
 a DICTIONARY on a skip list, an SSet of Morin by lowerBound() More...
class  SkipListSequence
 a sequence of items of type T on a skip list with the widths of the links, the SkiplistList of Morin More...
class  SlidingAggregate
 a QUEUE of values of the monoid G with the aggregate of its values, each operation in \( O( 1 ) \) time, amortized or in the worst case by Policy More...
class  SlotIterator
 a bidirectional iterator on the occupied places of the table O, by the policy P with the static functions size( o ), occupied( o , i ) and read( o , i ); the items are constant More...
class  SmallVector
 a vector with room for \( N \) items inside itself More...
class  SortedArrayDictionary
 a DICTIONARY realized with a vector sorted by key More...
class  SortedListSet
 a set as a list sorted in increasing order More...
class  SpaceEfficientSortedSet
 a SET of ordered items in blocks of about \( b \) items, indexed by a skip list, the SESSet of Morin More...
class  SpanningForestObserver
 the minimum spanning forest of an unoriented \( g \), kept up to date, by the recompute policy P More...
class  SparseMatrix
 a sparse matrix on orthogonal circular lists More...
class  SparseTable
 the range minima of an array by the sparse table More...
class  SpectralBloomFilter
 a filter of Bloom of \( m \) counters of the type C and \( r \) hashes, for multisets More...
struct  SpeculativeCounts
 what speculativeFor() did: its rounds and the iterations tried, the failed ones counted again More...
class  SplayTree
 a DICTIONARY on a splay tree More...
class  SplitMix64
 the generator SplitMix64, a UniformRandomBitGenerator More...
class  SPlusTree
 the static B+-tree of Slotin on a sorted array, by the order less() More...
class  SPSCQueue
 a bounded queue from one producer to one consumer, lock-free More...
struct  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...
class  StackFrontier
 a stack as \( S \), push() and pop() More...
struct  StateEqual
 the default equality of PointerTable: p->state == key More...
struct  Static
 the static observers O... (or mod::Via< O , A >), references called directly in the order of the arguments More...
class  StaticGraph
 a static graph in compressed sparse rows, the arcs of each node sorted by head, their heads and their weights in two arrays or, with ArcLayout::Interleaved, in one array of pairs More...
class  StdParExecutor
 the executor on a policy of the parallel algorithms of the standard library More...
class  StdSequence
 the sequence \( S \) of ADS, which inserts and erases by rank, with the members by iterator of a SequenceContainer, each one call of insert( i , x ) or erase( i ) of \( S \) at the rank \( i \) of the iterator More...
class  StealablePriorityQueue
 the exact PRIORITY QUEUE of one owner, of which a thief takes about half of the pairs, offered by the owner at its next operation; with a bound per pair of the type Bd (none if void), ordered by BdLess, it also knows the least bound of the pairs that its owner holds More...
class  StealingFrontier
 the frontier of a best-first search of \( p \) workers, a StealablePriorityQueue each, with the steals from random victims and the detection of the termination; with the bounds Bd of the pairs, if not void, ordered by BdLess More...
class  StringHash
 \( h( s ) = \sum_i ( s_i + 1 ) x^i \bmod ( 2^{61} - 1 ) \), at a random point \( x \) More...
class  StringSearcher
 a pattern prepared for the search of its occurrences in any text More...
class  SubscriptIterator
 the random-access constant iterator on the items T of the owner O, read by ( *o )[ i ] More...
class  SuccinctPatriciaTrie
 the compacted trie of a sorted dictionary of strings in DFUDS, the strings numbered by their lexicographic rank More...
class  SuffixArray
 the suffix array of a text with its \( \mathit{LCP} \), \( \mathit{Llcp} \) and \( \mathit{Rlcp} \) arrays and the range minima of \( \mathit{LCP} \) More...
class  SuffixAutomaton
 the suffix automaton of a string, built a byte at a time More...
class  SuffixTree
 the suffix tree of \( T \$ \), its nodes in a vector, the root at 0 More...
struct  SumAugmentation
 the sum of the values, an abelian group when V has the opposites More...
struct  SumOf
 the abelian group of the sums of T, of identity T() More...
class  TableHeap
 the ids \( [ 0 , n ) \) in a \( D \)-ary heap by the keys that the table T holds for them, read from it by update( id ): the queue of the frontier as an observer of the table of a search, in the form of the LaB-PQ of Dong et al. More...
class  TabulationHash
 the simple tabulation hashing of the keys of 64 bits More...
struct  TakeFirst
 the value of the first tree on a key in both More...
struct  TakeSecond
 the value of the second tree, or of the batch, on a key in both More...
class  TaskflowExecutor
 the executor on an executor of Taskflow More...
class  TBBExecutor
 the executor on an arena of oneTBB More...
class  TempDirectory
 a directory of its own, removed with what it holds at its destruction More...
struct  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...
class  ThreadedTree
 a binary search tree with threads in symmetric order More...
class  ThreadPool
 a pool of threads with work stealing, an executor More...
class  TieredVector
 a sequence with access in \( O( 1 ) \) and insertion and removal anywhere in \( O( \sqrt{n} ) \), in circular blocks of \( b \) items More...
struct  Tile
 a tile: the colors of its four sides More...
class  Treap
 a DICTIONARY on a treap, with the operations based on join [see Joinable] More...
struct  TreapBalance
 the treaps [see TreapJoin] More...
struct  TreapJoin
 the join of the treaps; A gives also priority( t ), of a node More...
class  TreapList
 a sequence of items of type T on an implicit treap, the TreapList of Morin More...
struct  TreapNodes
 the adaptor of the nodes of a Treap [see JoinAdaptor] More...
class  Tree
 an ordered tree, with pointers to parent, first child and next sibling More...
class  TreePriorityQueue
 a priority queue on a Red-Black tree of the pairs of a priority and of a number of insertion More...
class  Treque
 a LIST by rank fast at both ends and in the middle, on two circular deques More...
class  Trie
 a DICTIONARY of strings on a trie More...
class  TritArray
 \( n \) values in \( \{ 0 , 1 , 2 \} \), five to a byte in base 3 More...
class  TwoLevelDictionary
 a Patricia trie on the anchors of a front-coded dictionary More...
class  TwoLevelMemory
 the parameters \( B \) and \( M \) of the model, the counters of the I/Os and the occupation of the internal memory More...
class  UndoLog
 an observer that records the invertible events of L, which carry the old values, and brings a structure back to a checkpoint by replaying their inverses through its apply(), in one batch: any structure with apply() becomes undoable, at one event per change More...
class  UniqueQueue
 a QUEUE with no duplicates; the equality of T must be an equivalence, so an item unequal to itself (e.g., a NaN) cannot be enqueued: the postcondition of enqueue() refuses it More...
struct  VisitCounts
 what a visit did: the nodes taken out of its structure and the edges examined More...
class  WalkIterator
 a forward iterator on the nodes H (pointers or indices) of the owner O, from a first node, by the policy P with next( o , n , root ) and the constant none, the end, o being a pointer to the owner; *it is the node More...
class  WaveletMatrix
 a static sequence of integers of \( w \) bits with access, rank, select and the range quantiles in \( O( w ) \) time More...
struct  WeightBalance
 the weight-balanced trees More...
struct  WeightBalancedJoin
 the join of the trees balanced by weight, with \( \alpha = 0.29 \) More...
struct  WeightChanged
 the weight of an edge changed from from to to More...
struct  WeightedArc
 an arc of a weighted StaticGraph, its head with its weight More...
struct  WeightedEdge
 an edge \( [ u , v ] \) of weight \( w \) More...
struct  WeightedInterval
 an interval \( [ a , b ) \) of weight \( w \) More...
struct  WidePlaces
 the places of 16 bytes of PointerTable, the default: the whole hash and the pointer to the object More...
struct  WithPlaces
 the subject policy P [see Modification.h] of a PointerTable on the places L, WidePlaces or IndexPlaces< S > More...
class  WordRangeMinimum
 the leftmost minima of the ranges of an array, by the order less() More...
class  WorkStealingDeque
 the deque of an owner that pushes and takes, and of thieves that steal More...
struct  WorstCase
 the policy of a sliding window whose operations cost \( O( 1 ) \) time in the worst case More...
class  WyRand
 < xoshiro256** More...
class  XFastTrie
 the x-fast trie: a binary trie with a hash table of the prefixes per depth More...
class  XorList
 a doubly linked list with one word of links per cell, the exclusive or of the two neighbors More...
class  Xoshiro256T
 xoshiro256++ (or xoshiro256** if StarStar), a std::uniform_random_bit_generator of 64 bits More...
class  YFastTrie
 the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys More...
struct  ZeroingClear
 the clear() of ConcurrentFlatTable that writes 0 to every place, in time linear in its capacity; the default More...
class  ZeroPageAllocator
 an allocator of objects of type T on blocks of 0s, aligned to a huge page if they fill one at least [see the file] More...
class  ZobristTable
 a random word for each pair \( ( f , v ) \) of a feature and a value More...

Concepts

concept  AbelianGroup
 a group whose operation commutes
concept  Action
 a monoid of the maps A::Map acting on the values of the monoid G: the identity map A::id(), the composition A::compose( f , g ) (first \( g \), then \( f \)), and A::apply( f , a , n ), the map applied to the aggregate \( a \) of \( n \) values
concept  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  AddressablePriorityQueue
 the PRIORITYQUEUE of section 10.1 with handles and decreasing priority: the types Item, Priority and Handle, and empty(), min(), deleteMin(), insert( x , p ), which gives the handle of \( x \), and decrease( y , p )
concept  ArrowExportable
 what exportArrow() exports: a BitVector, a PackedArray or a sized sequence of numbers
concept  ArrowNumber
 the numbers that are the values of a column of Arrow: the integers of 8, 16, 32 and 64 bits, float and double
concept  AssignmentEngine
 the engines of the solves of an Assignment, objects that it keeps: solve( n , C , all , D , col , u , v ) gives an optimal assignment of the costs \( C \) by rows, infinity() forbidding a pair, in col (the column of each row) and its potentials in \( u \) and \( v \), every reduced cost \( c( i , j ) - u_i - v_j \) of a finite cost nonnegative and those of the pairs zero; \( D \) holds the pairs whose cost changed since the last solve, or all is true when anything may have.
concept  Augmentation
 an augmentation of a map from K to V: a monoid on G::Value, of identity G::identity() and associative operation G::combine( a , b ), and the value G::from( k , v ) of a pair; the augmented value of a subtree is the combination of the values of its pairs by increasing keys
concept  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  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  batch_updatable
 batch(), a group of changes told as one (the observers of a batch of changes)
concept  BinaryNode
 a node of a binary tree: a pointer to a struct whose children are read by left() and right() or by the fields left and right
concept  BucketTie
 a policy of the ties of BucketQueue: whether the least \( g \) comes first
concept  bulk_erasable
 erase_bulk( r ) of the range \( r \) of keys as one operation (the event BulkErased)
concept  bulk_insertable
 insert_bulk( r ) of the range \( r \) of items as one operation (the generic insertion of a range, the event BulkInserted)
concept  ChannelFamily
 the families of channels among \( p \) workers: tryPush( from , to , m ) pushes a span of messages and returns how many, drain( me , f ) calls \( f \) on the messages of the inbox of me and returns how many, size() is \( p \)
concept  CommutativeMonoid
 a monoid whose operation commutes, by the opt-in G::commutative
concept  CsrArrays
 a graph whose compressed rows are plain arrays, offsets(), heads() and, if weighted, weightData(), which a library that takes the compressed rows (METIS, KaHIP, GraphBLAS) reads without a copy: a StaticGraph of the separate layout, or an ArrayGraph
concept  declares_monotone
 whether S declares the only direction in which its values move
concept  Dictionary
 DICTIONARY (section 3.2.3): a univocal relation from keys to values; lookup() returns the value of a key, or nothing (the nil of the book, std::nullopt).
concept  DynamicGraph
 a GRAPH with the insertions and the deletions of its specification
concept  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  erasable
 erase( k ) of a key (the node tables that reuse their places within an episode)
concept  Executor
 the executors, whose bulk( n , f ) runs \( f( 0 ) , \ldots , f( n - 1 ) \) on their threads and returns when they have returned, and whose concurrency() is the number of their threads
concept  FlatClear
 a policy of clear() of ConcurrentFlatTable
concept  FlowEngine
 the engines of the solves of a MaxFlowObserver, objects that the observer keeps: scratch( net , s , t , how ) gives the value of a maximum flow of net from the zero flow, and warm( net , s , t , how , v ) that of a maximum flow from the flow that net keeps, of value \( v \) before the capacities changed (a capacity cut below its flow leaving the excess and the deficit that FlowNetwork::maxFlow() routes first); each leaves a maximum flow in net, whose minimum cut the observer reads.
concept  forwarding_query_tag
 a tag of a forwarded query
concept  FrontierQueue
 a priority queue that PriorityFrontier and Prim's algorithm take: one that lowers its priorities, natively or lazily, whose priority is a Priority, or whose items are pairs ( key , node )
concept  FullWordGenerator
 a std::uniform_random_bit_generator of 64 full bits, from 0 to \( 2^{64} - 1 \)
concept  Graph
 GRAPH (section 9.2), as far as the visits need it: the nodes, the adjacent nodes of a node, the range \( [ 0 , \mathrm{bound}() ) \) of the names.
concept  GraphObserver
 an observer of the events of weights W: the kinds that it wants, and the two ways of getting them
concept  Group
 a monoid with the inverse G::inverse( a ), i.e., combine( inverse( a ) , a ) and combine( a , inverse( a ) ) are the identity
concept  in_arcs
 forEachIn( v , f ), the arcs entering \( v \) (the observers that repair a tree from the heads of the arcs that changed)
concept  IndexedDeque
 the DEQUE of Morin: a sequence changed and read at both ends
concept  IndexedList
 the LIST of Morin: a sequence read, written, extended and shortened by rank
concept  IterableSet
 a SET that can be copied and has the foreach
concept  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  JoinAdaptor
 the nodes of a binary search tree as the algorithms based on join see them: nil(), the empty tree; left(), right(), key(), value() and size(), the reading of a node (size() of nil is 0); expose( t , l , r ), which takes off the children of \( t \) into \( l \) and \( r \), so that \( t \) is a node alone; connect( m , l , r ), which hangs \( l \) and \( r \) under the node alone \( m \) and updates what \( m \) keeps of its subtree (its size, its height, its augmented value, the parents of \( l \) and \( r \)); dispose( t ), which frees the subtree \( t \) (nothing for nil); rank( t ), the rank of a tree, and childRank( t , r , c ), that of the child \( c \) of \( t \) of rank \( r \), in \( O( 1 ) \); join( l , rl , m , r , rr ), the join of the balancing scheme, which returns the root and its rank
concept  KeyedBinaryNode
 a node of a binary tree with a key
concept  KeyedDictionary
 a dictionary that gives the address of the key equal to the one asked, on which DictionarySet is a USet; the search may change the dictionary (a splay tree), not the set of its keys
concept  MailboxCoalescing
 a policy of the coalescing of Mailbox for the messages Msg: NoCoalescing, or CoalesceBy< K , M > with K a function object made by default that gives the key of a message, and a map from the key to a place of std::size_t by try_emplace(), clear() and empty()
concept  meetable_query
 whether the query T composes two answers
concept  Mergeable
 a union of disjoint sets as kruskal() needs it: merge( u , v ) joins the components of u and v and tells whether they were apart
concept  Monoid
 a monoid on G::Value: the identity G::identity() and the associative operation G::combine( a , b )
concept  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  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  OrderedDictionary
 a KeyedDictionary that gives the address of the smallest key not smaller than the one asked, on which DictionarySet is an SSet
concept  ParentBinaryNode
 a node of a binary tree with the link to its parent
concept  Persistent
 a structure that store() writes and restore() reads: it names itself, lists its members in persist(), and is made empty by its default constructor or, if it has none, by its persistEmpty()
concept  PlaceHash
 a hash \( H \) that maps a key straight to a place of a table of \( m = 2^d \) places by h.place( k , m ), as the multiplicative hashing of section 5.1.1 of Morin's book and the tabulation hashing of its section 5.2.3 do with the \( d \) most significant bits of a product or of a XOR [see MultiplicativeHash in UniversalHashing.h and TabulationHash in RandomHashing.h]; the tables use it in place of \( h( k ) \bmod m \), whose low bits are the worst ones of a product
concept  prefetchable
 prefetch( k ), a hint that \( k \) (a key or its hash) is looked up next (a batch of lookups by group prefetching)
concept  PriorityQueue
 the PRIORITYQUEUE of section 10.1 without handles: the type of the items (Item or value_type), empty(), and queue_insert() of an item with the keys of the order of the queue (a Priority, one or two Keys, or none), queue_min() and queue_deleteMin(), the item of smallest priority read and removed
concept  PrototypeFrontier
 the structure \( S \) of the prototype as a type: add( v , d , first ) puts v into S at the distance d, first if v was never reached; extract() takes a node out of S; update( v , d ) tells S that the distance of v, already in S, fell to d
concept  Queue
 [Stack]
concept  RadixKey
 an integer or a floating point number of at most 8 bytes
concept  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  rankable
 rank( k ), the number of keys smaller than \( k \) (the order statistics); its time is the query rank_complexity_t
concept  RankStore
 the storage on which the sorts of the book work in place, which read the items by their ranks only: a SortStore, or the view of a random-access range that is not contiguous
concept  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  Reoptimizable
 a solution that follows the events of weights W
concept  ReoptPolicy
 a recompute policy: whether to compute from scratch before a repair, whether to abandon a repair while it runs (polled by the observer with its work \( w \) so far), and the record of the outcome after it
concept  reservable
 reserve( n ), room for \( n \) items (the builders)
concept  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  Selective
 a monoid whose combine( a , b ) is always \( a \) or \( b \), by the opt-in G::selective
concept  Sequence
 SEQUENCE (section 3.2.1): a dynamic linear sequence of items; as axioms, \( \mathrm{empty}( s ) = \mathrm{finished}( \mathrm{head}( s ) ) \) (empty() is redundant), \( \mathrm{read}( \mathrm{insert}( p , v ) ) = v \), \( \mathrm{remove}( \mathrm{insert}( p , v ) ) = s \), and \( \mathrm{read}( \mathrm{write}( p , v ) ) = v \) with the other items unchanged.
concept  Set
 SET (section 3.2.2): a finite collection of distinct items; union(), intersection() and difference() are functions of two sets.
concept  shiftable_keys
 shift_all( delta ), every key moved by \( \delta \) in \( O( 1 ) \) (D* Lite, Generalized Adaptive A*)
concept  SizedBinaryNode
 a node of a binary tree with a key and the size of its subtree
concept  snapshotable
 snapshot(), a view of the present state in \( O( 1 ) \) which later changes do not touch (the audits, a persistent structure)
concept  SortRange
 a range that the sorts take beside std::vector and std::span: random access, sized, its items movable in and out of it [see above]
concept  SortStore
 the storage on which the sorts work in place, by reference: a std::vector or a std::span of its items, read by their addresses
concept  SpeculativeStep
 the two steps of an iteration [see speculativeFor()]
concept  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  SSet
 the sorted set of Morin, a USet with the successor search
concept  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  Stack
 STACK (section 4.3.1): items are added and removed at the top (LIFO).
concept  StringStore
 a SortStore of strings
concept  TrieWidth
 the number of bits of the keys of a trie on U: \( w \), if it is between 1 and the bits of U
concept  undoable
 checkpoint() and rollback( t ) back to a checkpoint (a speculative change, a batch that exits by an exception)
concept  USet
 the unordered set of Morin, whose find() gives the item equal to the one asked
concept  VectorKey
 the types that vectorQuickSort() sorts: integers and floating point numbers of 32 or 64 bits
concept  WorkerExecutor
 the executors that also run long-lived workers: run( p , f ) runs \( f( 0 ) , \ldots , f( p - 1 ) \), at the same time on \( p \) distinct threads unless one returns before the others have begun, and returns when they have returned, and lock_type is a mutex of the executor with the semantics of the named requirement Lockable of the standard (lock(), unlock(), and try_lock(), which takes the lock only if it is free and never waits)

Typedefs

using Cdcl = BasicCdcl<>
 the clause learning on std::priority_queue
using Grid = std::vector< std::vector< int > >
 the squares, 0 empty
template<class S>
using 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 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 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
using Word = std::uint64_t
 a word of 64 bits
using Tuple = std::vector< int >
 a tuple, a permutation, a string
using Tiling = std::vector< std::vector< int > >
 the tile of ( i , j )
using Adjacency = std::vector< std::vector< bool > >
 an adjacency
using Clause = std::vector< int >
 some literals
using Cnf = std::vector< Clause >
 a formula
using Nodes = std::vector< int >
 a set, a path
template<class E, class C>
using MultiQueueHeap = DaryHeap< E , C , 8 >
 the inner queue of a MultiQueue by default, the 8-ary heap
template<class K>
using DefaultHash = typename detail::DefaultHashOf< K >::type
 the hash of the engineered tables and filters of ADS: FastHash< K > for the integers, the enumerations, the pointers, the floating point numbers and the strings, std::hash< K > for any other K
using GridCell = std::pair< int , int >
 a cell \( ( r , c ) \) of a grid, or a move as the difference of two cells
using FourMoves = std::remove_cv_t< decltype( FOUR_MOVES ) >
 the type of FOUR_MOVES, the default range of moves
template<class W>
using GraphModifications
 the events of a graph of weights W, in the order of their kinds
template<class W>
using GraphEvent
 an event, whose kind is its index in the variant, the variant of GraphModifications< W >
template<Graph G, class... O>
using Observable
 the graph \( g \), whose changes are sent to the static observers O... of the first form [see GraphObserver] and to those attached later, of either form
template<class G>
using PathLength = typename detail::EdgeLength< G >::type
 the type of the lengths of the paths of \( G \)
template<class T>
using IncumbentChanged = mod::Assigned< int , T >
 the best value found so far by a search changed, the handle 0
using Board = std::vector< int >
 a configuration: the tile of each square by rows, 0 the hole
template<class A, class B, class VA = std::remove_cvref_t< A >, class VB = std::remove_cvref_t< B >>
using PairRef
 the pair \( ( a , b ) \) that an iterator reads by value, in general two references into the container, whose value type is the pair of the copies \( ( V_A , V_B ) \), what std::ranges::range_value_t gives: the std::pair itself where the standard library declares the common reference of the two pairs (C++23, with \( V_A \) and \( V_B \) the types of \( a \) and \( b \)), a class derived from it that declares it otherwise
using UnionFind = DisjointSets<>
 the union by size with path halving
using Bits = std::vector< int >
 the bits, the least significant first
using CsrMatrix = BasicCsrMatrix<>
 the matrix of doubles of 32-bit columns and std::size_t offsets
template<class I = int, class V = double>
using DynamicCsc = DynamicCsr< I , V >
 the same by columns
template<class T>
using Matrix = std::vector< std::vector< T > >
 by rows
using U64 = std::uint64_t
 the unsigned integers of 64 bits
using Xoshiro256 = Xoshiro256T< false >
using Xoshiro256StarStar = Xoshiro256T< true >
 < xoshiro256++
using Philox4x32 = PhiloxT< std::uint32_t >
using Philox4x64 = PhiloxT< std::uint64_t >
 < Philox4x32-10
using MinStd = LinearCongruentialT< 16807 , 0 , 2147483647 >
 the generator of Park and Miller, \( a = 16807 \), \( c = 0 \), \( m = 2^{31} - 1 \)
using Mmix
 the generator of Knuth for MMIX, \( m = 2^{64} \)
template<class Msg, class E>
using DefaultChannels = typename ChannelsOf< E >::template type< Msg >
 the family of channels to use on the executor E
template<class Q>
using queue_item_t = typename detail::queue_item< Q >::type
 the items of the queue Q: Q::Item, else Q::value_type
template<class Q>
using queue_handle_t = typename detail::queue_handle< Q >::type
 the handles of the queue Q, which its insertions return: Q::Handle, else Q::handle_type (the mutable heaps of Boost.Heap)
template<class T, class H = std::hash< T >>
using ChainedHashSet
 the set on a hash table with lists of overflow
template<class T, class H = std::hash< T >>
using OpenHashSet = DictionarySet< OpenHashTable< T , bool , H > >
 the set on a hash table with open addressing
template<std::totally_ordered T>
using TreeSet = DictionarySet< RedBlackTree< T , bool > >
 the set on a Red-Black tree
using Comparator = std::pair< std::size_t , std::size_t >
 a comparator \( ( i , j ) \) of a network: the smaller of \( A[ i ] \) and \( A[ j ] \) goes to \( A[ i ] \)
using Table = std::vector< std::vector< int > >
 the table \( \mathit{DP}[ i ][ j ] \) of the costs
using FrontPair = std::pair< std::size_t , std::string >
 a pair \( ( \ell , \hat s ) \) of the front coding, the length of the prefix shared with the string before and the rest
using RearPair = std::pair< std::size_t , std::string >
 a pair \( ( r , \hat s ) \) of the rear coding, the characters taken off the end of the string before and the rest
using Symbols = std::vector< std::size_t >
 a text on an integer alphabet
using Words = std::vector< Word , detail::LineAllocator< Word > >
 the words of a BitVector, on lines of the cache
using EliasFano = BasicEliasFano< false >
 Elias-Fano with the inventories of \( H \) built in the constructor, the fastest access() and nextGEQ().
using LazyEliasFano = BasicEliasFano< true >
 Elias-Fano with the inventories of \( H \) built at the first query that needs them, the fastest construction.
using RankSelect = BasicRankSelect< false >
 the directory with its inventories of select built in the constructor, the fastest select
using LazyRankSelect = BasicRankSelect< true >
 the directory with its inventories of select built at the first select of each value, the fastest construction (for a directory that may never select, or that selects only some values)
template<std::totally_ordered K, class V, class G = NoAugmentation, class Policy = NoObservers, class A = std::allocator< std::pair< const K , V > >>
using JoinAVLTree = JoinTree< K , V , AVLBalance , G , Policy , A >
 the AVL tree whose balance is in join alone
template<std::totally_ordered K, class V, class G = NoAugmentation, class Policy = NoObservers, class A = std::allocator< std::pair< const K , V > >>
using JoinRedBlackTree = JoinTree< K , V , RedBlackBalance , G , Policy , A >
 the Red-Black tree whose balance is in join alone
template<std::totally_ordered K, class V, class G = NoAugmentation, class Policy = NoObservers, class A = std::allocator< std::pair< const K , V > >>
using WeightBalancedTree = JoinTree< K , V , WeightBalance , G , Policy , A >
 the tree balanced by weight, in join alone
template<std::totally_ordered K, class V, class G = NoAugmentation, class Policy = NoObservers, class A = std::allocator< std::pair< const K , V > >>
using JoinTreap = JoinTree< K , V , TreapBalance , G , Policy , A >
 the treap whose balance is in join alone
template<std::totally_ordered K, class V, class G, class Policy = NoObservers, class A = std::allocator< std::pair< const K , V > >>
using AugmentedMap = JoinTree< K , V , WeightBalance , G , Policy , A >
 the map augmented by G, balanced by weight as in PAM
template<std::totally_ordered K, class V>
using WeightRebuildTree
 the tree of exercise 8.8 of Morin, balanced by weight by rebuilds
template<std::totally_ordered K, class V>
using CountdownTree
 the CountdownTree of exercise 8.9 of Morin
template<std::totally_ordered K, class V>
using DynamiteTree = PartialRebuildingTree< K , V , RebuildPolicy::DYNAMITE >
 the DynamiteTree of exercise 8.10 of Morin
template<std::totally_ordered K, class V>
using BinarySearchTree = SearchTree< K , V , false >
 the binary search tree (ABR) of section 6.1
template<std::totally_ordered K, class V>
using RedBlackTree = SearchTree< K , V , true >
 the Red-Black tree of section 6.2

Enumerations

enum class  complexity { complexity::constant , complexity::logarithmic , complexity::linear }
 a class of time, from the cheapest More...
enum class  decrease_key_kind { decrease_key_kind::none , decrease_key_kind::lazy , 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...
enum class  Chain { Chain::FRONT , Chain::MOVE_TO_FRONT , Chain::SORTED }
 how a ChainedHashTable keeps its lists More...
enum class  BTreePolicy { BTreePolicy::STANDARD , BTreePolicy::WIDE , BTreePolicy::THREE }
 how a BlockBTree keeps its nodes within their bounds More...
enum class  ByteOrder : std::uint8_t { ByteOrder::little = 1 , ByteOrder::big = 2 , ByteOrder::native = std::endian::native == std::endian::big ? 2 : 1 }
 the byte order of the payload of a file More...
enum class  CapacityDecrease { CapacityDecrease::SLACK , CapacityDecrease::CYCLE , CapacityDecrease::PATH }
 what decreaseCapacity() did More...
enum class  GridMoves { GridMoves::FOUR , GridMoves::EIGHT }
 the moves of a GridGraph More...
enum class  Corners { Corners::CUT , Corners::NO_SQUEEZE , Corners::NO_CUT }
 when a move to a corner of a cell is allowed, the corner free More...
enum class  MoveCost { MoveCost::ENTERED , MoveCost::LEFT }
 which cell of a move of a GridGraph weighs it More...
enum class  Augment { Augment::FORD_FULKERSON , Augment::EDMONDS_KARP , Augment::DINIC , Augment::PUSH_RELABEL }
 the way of increasing the flow More...
enum class  Frontier {
  Frontier::LIST , Frontier::HEAP , Frontier::FIBONACCI , Frontier::QUEUE ,
  Frontier::STACK , Frontier::DEQUE
}
 the structure \( S \) of the prototype More...
enum class  ArcLayout { ArcLayout::Separate , ArcLayout::Interleaved }
 the layout of the arcs of a weighted StaticGraph More...
enum class  Choice { Choice::NEWEST , Choice::OLDEST }
 the node of \( Q \) that genericVisit() chooses More...
enum class  EdgeKind { EdgeKind::TREE , EdgeKind::BACK , EdgeKind::FORWARD , EdgeKind::CROSS }
 the kind of an edge with respect to a depth-first visit More...
enum class  TspBound { TspBound::BOOK , TspBound::ONE_TREE }
 the lower bound of a circuit that starts with \( S \) More...
enum class  Locality : int { Locality::None = 0 , Locality::Low = 1 , Locality::Moderate = 2 , Locality::High = 3 }
 how soon and how often a prefetched line is read again: None once (keep it out of the caches it would pollute), Low once more soon, Moderate a few times, High (the default) often, in every level More...
enum class  Union { Union::SIZE , Union::RANK }
 how the roots of two trees are joined: the smaller tree under the root of the larger, or the lower rank under the higher More...
enum class  Compression { Compression::HALVING , Compression::FULL }
 how find() shortens the path: halving it (every other node on the way made a child of its grandparent, one pass), or compressing it (all the nodes on the way made children of the root, two passes) More...
enum class  Keep { Keep::Yes , Keep::Detach }
 what an on() that returns it asks: to stay, or to be detached after the event, with no exception More...
enum class  window_kind { window_kind::subtract_on_evict , window_kind::monotone_deque , window_kind::two_stacks , window_kind::real_time }
 the algorithm of a sliding window [see SlidingAggregate] More...
enum class  Duplicate { Duplicate::IGNORE_NEW , Duplicate::FORGET_OLD }
 what enqueue() does with an item already in the queue More...
enum class  Order {
  Order::EMPTY , Order::CONSTANT , Order::INCREASING , Order::DECREASING ,
  Order::NONDECREASING , Order::NONINCREASING , Order::NONE
}
 the order of a sequence, the most specific that holds More...
enum class  Alignment { Alignment::GLOBAL , Alignment::SEMIGLOBAL , Alignment::LOCAL }
 the kind of alignment More...
enum class  RebuildPolicy { RebuildPolicy::WEIGHT , RebuildPolicy::COUNTDOWN , RebuildPolicy::DYNAMITE }
 the rules that select the subtree to rebuild More...
enum class  Color : unsigned char { Color::RED , Color::BLACK }
 the color of a node of a Red-Black tree More...

Functions

double akraBazziExponent (const std::vector< std::pair< double, double > > &ab)
 the exponent \( p \) of Akra and Bazzi of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \), the root of \( \sum_i a_i b_i^p = 1 \), the terms given as \( ( a_i , b_i ) \)
Growth akraBazzi (const std::vector< std::pair< double, double > > &ab, double beta, double k=0)
 the order of \( T( n ) = \sum_i a_i T( b_i n ) + g( n ) \) with \( g( n ) = \Theta( n^\beta \log^k n ) \)
std::size_t add (std::vector< int > &A)
 the increment of the counter \( A \) of \( k \) bits modulo \( 2^k \), returning the number of bits it has changed, i.e., its actual cost
template<class F>
void hanoi_recursive (int n, int source, int dest, int middle, F &&f)
 the moves of \( n \ge 1 \) disks from source to dest, by the recursion of the book (its hanoi-recursive())
template<class F>
void hanoi_iterative (int n, int source, int dest, int middle, F &&f)
 the moves of hanoi_recursive() with the calls on a stack (the first hanoi-iterative() of the book): the calls (1) are pushed, and each pop resumes the call left open, moving a disk and simulating the call (2)
template<class F>
void hanoi_iterative_labels (int n, int source, int dest, int middle, F &&f)
 the moves of hanoi_recursive() by the systematic rules (the second hanoi-iterative() of the book), saving on the stack the parameters and the label from which the call resumes
Growth master (double a, double b, double beta, double k=0)
 the order of \( T( n ) = a T( n / b ) + \Theta( n^\beta \log^k n ) \); \( \log_b a \) within \( 10^{-12} \) of an integer is taken as that integer (\( \log_{10} 1000 \) is 3, not 2.9999999999999996), and with \( \beta = \log_b a \) the power is \( \beta \)
Growth linear (double a, double beta)
 the order of \( T( n ) = \sum_i a_i T( n - i ) + \Theta( n^\beta ) \), \( a = \sum_i a_i \)
template<class T>
Segment< T > maxSumSegmentCubic (const std::vector< T > &D)
 a nonempty segment of largest sum, by all the pairs, \( O( n^3 ) \)
template<class T>
Segment< T > maxSumSegmentQuadratic (const std::vector< T > &D)
 a nonempty segment of largest sum, by all the pairs, \( O( n^2 ) \)
template<class T>
Segment< T > maxSumSegment (const std::vector< T > &D)
 a nonempty segment of largest sum, by one scan, \( O( n ) \)
template<class T>
Segment< T > maxSumSegmentPrefix (const std::vector< T > &D)
 a nonempty segment of largest sum, by the minimum prefix sum, \( O( n ) \)
template<class T>
Segment< T > maxSumSegmentLength (const std::vector< T > &D, std::size_t L, std::size_t U)
 a segment of largest sum among those of length in \( [ L , U ] \), \( O( n ) \)
template<class T>
Segment< T > longestSegmentAtLeast (const std::vector< T > &D, T t)
 the longest segment of sum at least \( t \), length 0 if none, \( O( n ) \)
template<class T>
Segment< T > longestSegmentAverageAtLeast (const std::vector< T > &D, T p, T q)
 the longest segment of average at least \( p / q \), length 0 if none
template<class T>
Segment< T > maxDensitySegment (const std::vector< T > &D, std::size_t L)
 a segment of largest average among those of length at least \( L \), its sum in the result, \( O( n \log n ) \)
std::vector< int > gcIndicator (const std::string &dna)
 1 for the nucleotides C and G, in either case, and 0 for the others
template<class F, class R>
bool zeroPolynomial (F &&p, std::size_t n, long d, int K, R &rng)
 whether \( p \), of \( n \) variables and total degree \( d \), is identically 0, by \( K \) random points
template<class T, class R>
bool freivalds (const std::vector< std::vector< T > > &A, const std::vector< std::vector< T > > &B, const std::vector< std::vector< T > > &C, int K, R &rng)
 whether \( A B = C \), by \( K \) runs of \( O( n^2 ) \)
template<class F, class R>
bool halfSatisfiable (F &&f, std::size_t n, int K, R &rng)
 whether the formula \( f \) of \( n \) variables is true on more than half of the assignments, from \( K \) random ones
template<class Z, class Next, class Last, class A, class O>
auto enumerateSearch (Z z, Next &&next, Last &&last, A &&a, O &&o) -> std::optional< decltype(o(z)) >
 the enumerative search from the first object \( z \): the answer \( o( z ) \) of the first \( z \) with \( a( z ) \), next( z ) after \( z \) until last( z ) holds; nothing if none
template<class Z, class Next, class Last, class A, class O, class M, class B>
auto enumerateOptimize (Z z, Next &&next, Last &&last, A &&a, O &&o, M &&m, B &&better) -> std::optional< decltype(o(z)) >
 the enumerative optimization: the answer of an admissible object of \( Z \) with no admissible one better, i.e., with no \( y \) such that better( m( y ) , m( x ) ), or nothing
template<class N, class C, class P, class L, class V>
bool backtrack (const N &node, C &&children, P &&prune, L &&leaf, V &&visit)
 the backtracking from the node \( N \): prune( N ) rejects \( N \) and its subtree, a leaf goes to visit( N ), which returns true to stop, children( N ) gives the children of a node that is not a leaf; true if stopped
template<class X, class Cand, class Best>
std::vector< X > greedy (int k, Cand &&candidates, Best &&best)
 the greedy scheme: for each of \( k \) stages, the best of the values candidates( i , x ) admissible after the partial solution \( x \) is appended to \( x \), the stage skipped if there is none
template<class X, class S, class D, class V, class C>
auto divideEtImpera (const X &x, S &&small, D &&direct, V &&divide, C &&combine) -> decltype(direct(x))
 divide et impera: direct( x ) if small( x ), else the combination of the solutions of the instances that divide( x ) gives
template<class T, class B>
std::vector< T > maximal (const std::vector< T > &X, B &&better)
 the elements of \( X \) that are maximal for the partial order better( a , b ), i.e., \( a \) strictly better than \( b \)
template<class T, class C = std::less<>>
std::vector< std::size_t > smallerToTheRight (const std::vector< T > &A, C less=C())
 the counts \( c[ i ] \) of the places \( j > i \) with \( A[ j ] < A[ i ] \), by mergesort on the places; \( O( n \log n ) \)
template<std::ranges::random_access_range R>
std::pair< std::size_t, std::size_t > longestKDistinctRun (const R &S, std::size_t k)
 the start and the length of the first longest run of consecutive items of \( S \) with at most \( k \) distinct values, by a sliding window; \( O( n \log k ) \)
template<class T>
requires ( std::is_arithmetic_v< T > && ! std::is_same_v< T , bool > )
std::optional< std::pair< T, T > > largestGap (std::vector< std::pair< T, T > > I)
 the longest stretch \( ( x , y ) \), between the first start and the last end, covered by none of the closed intervals \( I \), the first one on ties, or nothing; \( O( n \log n ) \)
template<class T, class W = T>
requires std::is_arithmetic_v< T >
W lineAssignment (std::vector< T > H, std::vector< T > L)
 the least sum of \( | H[ i ] - L[ \pi( i ) ] | \) over the permutations \( \pi \), computed in the type W, by sorting; \( O( n \log n ) \)
template<class T>
std::vector< T > lis (const std::vector< T > &A)
 a longest increasing subsequence, \( O( n^2 ) \)
template<class T>
std::size_t lisLength (const std::vector< T > &A)
 the length of a longest increasing subsequence, \( O( n \log n ) \)
template<class T>
T maxSubarraySum (const std::vector< T > &A)
 the largest sum of a subvector, the empty one included, \( O( n ) \)
template<class W, class P>
std::set< std::string > anagrams (const std::string &s, W &&word, P &&prefix)
 the anagrams of \( s \) made of words for which word( w ) is true, prefix( w ) being true if \( w \) begins some word (a word included); the words of a sentence are separated by one blank, and the empty \( s \) has the one anagram ""
template<class F>
long subsets (int n, int k, F &&f)
 the subsets of \( k \) of the items \( 0 , \ldots , n - 1 \), as vectors of \( n \) booleans, f( S ) on each and true from it to stop; the number visited
template<class T, class F>
long permutations (const std::vector< T > &A, F &&f)
 the permutations of the items of \( A \), f( S ) on each and true from it to stop; the items are told apart by their places, so that equal items give each permutation of the values more than once, \( n! \) in all
template<class T, class F>
long derangements (const std::vector< T > &A, F &&f)
 the derangements of the items of \( A \), no item in its own place, f( S ) on each and true from it to stop; the places are deranged, not the values, as in permutations()
template<class T, class F>
long subsetSum (const std::vector< T > &A, T k, F &&f)
 the subsets of the positive items of \( A \) of sum \( k \), as the places taken, f( S ) on each and true from it to stop; \( k = 0 \) gives the empty subset only, and equal items in different places give different subsets
std::optional< std::vector< std::vector< int > > > knightTour (int n, int x, int y, bool warnsdorff=true)
 a tour of the knight from \( ( x , y ) \) on an \( n \times n \) board, by backtrack, the moves in the order of the book or by the rule of Warnsdorff, as the board of the steps from 1; none for \( n < 1 \), where there is no board
template<class F>
long nQueens (int n, F &&f)
 the placements of \( n \le 32 \) queens, f( Q ) on each, \( Q[ r ] \) the column of the queen of the row \( r \), and true from f to stop; the number found
template<class F>
long nQueensIterative (int n, F &&f)
 the placements of \( n \) queens by the iterative backtracking, with the stage \( k \) and the column \( V[ k ] \) of the queen of the row \( k \), f( V ) on each and true from f to stop; the number found
bool admissible (const std::vector< int > &Q)
 whether no two queens of \( Q \) attack each other, \( Q[ r ] \) the column of the queen of the row \( r \)
std::string board (const std::vector< int > &Q)
 the board of \( Q \), a line per row, with the letter Q for a queen and a dot for an empty square
std::optional< std::vector< bool > > dpll (const Cnf &F, int n)
 a model of the formula \( F \) of \( n \) variables by DPLL, the variables left free false, or nothing if \( F \) is unsatisfiable
bool check (const Grid &S, std::size_t x, std::size_t y, int c)
 whether \( c \) can be written in the square \( ( x , y ) \) of \( S \), i.e., it is not on its row, its column or its block
bool sudoku (Grid &S, std::size_t i=0)
 fills the empty squares of \( S \) from the square number \( i \) on, in the order of the rows; true if it can
template<class S>
constexpr unsigned 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 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)
constexpr int sidewaysSum (Word x)
 the number of 1 bits of \( x \), \( \nu( x ) \)
constexpr int ruler (Word x)
 the number of trailing zeros of \( x \), \( \rho( x ) \)
constexpr int lambda (Word x)
 the place of the leading 1 of \( x \), \( \lambda( x ) = \lfloor \log_2 x \rfloor \)
constexpr Word rightmostOne (Word x)
 the rightmost 1 of \( x \) alone, 0 if \( x = 0 \)
constexpr Word smearRight (Word x)
 \( x \) with the 0 bits below its rightmost 1 set, 0 if \( x = 0 \)
constexpr Word reverseBits (Word x)
 the bits of \( x \) in reverse order
constexpr Word gray (Word x)
 the Gray code of \( x \)
constexpr Word grayInverse (Word g)
 the \( x \) whose Gray code is \( g \)
constexpr Word nextSameWeight (Word x)
 the next larger word with as many 1 bits as \( x \)
constexpr Word interleave (std::uint32_t x, std::uint32_t y)
 the Morton code of \( ( x , y ) \), the bits of \( x \) in the even places and those of \( y \) in the odd ones
constexpr std::pair< std::uint32_t, std::uint32_t > deinterleave (Word z)
 the \( ( x , y ) \) of the Morton code \( z \)
constexpr bool hasZeroByte (Word x)
 whether one of the 8 bytes of \( x \) is 0
std::uint64_t popcount (const Word *w, std::size_t n)
 the 1 bits of the \( n \) words from \( w \)
std::uint64_t popcountAnd (const Word *a, const Word *b, std::size_t n)
 the 1 bits of the \( n \) words of \( a \,\&\, b \)
Word pdep (Word x, Word mask)
 the low bits of \( x \) to the places of the 1 bits of mask, in order
Word pext (Word x, Word mask)
 the bits of \( x \) at the places of the 1 bits of mask, packed low
int select (Word x, int r)
 the place of the 1 of rank \( r \) of \( x \), from 0
Word mortonEncode (std::uint32_t x, std::uint32_t y)
 the Morton code of \( ( x , y ) \), the bits of \( x \) in the even places and those of \( y \) in the odd ones
std::pair< std::uint32_t, std::uint32_t > mortonDecode (Word z)
 the \( ( x , y ) \) of the Morton code \( z \)
template<class T, class F>
long forEachPermutation (std::vector< T > &a, F &&visit)
 the \( n! \) arrangements of \( a \) by Heap's method, visit( a ) on each
template<class T, class F>
long forEachPermutationLex (std::vector< T > &a, F &&visit)
 the distinct permutations of the multiset \( a \) in lexicographic order from \( a \) sorted, visit( a ) on each; \( a \) ends sorted
template<class F>
long forEachCombination (int n, int t, F &&visit)
 the increasing \( t \)-tuples of \( [ 0 , n ) \) in lexicographic order, visit( c ) on each, \( c \) a const std::vector< int > of size \( t \)
constexpr Word nextCombination (Word x)
 the next larger word with as many 1 bits as \( x \)
template<class F>
long forEachCombinationMask (int n, int t, F &&visit)
 the words of \( t \) 1 bits below \( 2^n \) in increasing order, visit( x ) on each
template<class F>
long mixedRadix (const std::vector< int > &m, F &&visit)
 the tuples \( ( a_0 , \ldots , a_{n-1} ) \) with \( 0 \le a_j < m_j \), in lexicographic order, \( O( 1 ) \) amortized per tuple after \( O( n ) \)
template<class F>
long grayTuples (const std::vector< int > &m, F &&visit)
 the tuples with \( 0 \le a_j < m_j \) in the reflected Gray order, loopless
template<class F>
long permutationsLex (Tuple a, F &&visit)
 the permutations of the multiset \( a \), in lexicographic order from \( a \) sorted
template<class F>
long plainChanges (int n, F &&visit)
 the permutations of \( 0 , \ldots , n - 1 \) by swaps of adjacent items, \( O( 1 ) \) amortized per permutation, the same vector visited each time
template<class F>
long heapPermutations (int n, F &&visit)
 the permutations of \( 0 , \ldots , n - 1 \) by Heap's method, one swap each
template<class F>
long combinationsLex (int n, int t, F &&visit)
 the \( t \)-combinations of \( 0 , \ldots , n - 1 \) as increasing tuples, in lexicographic order
template<class F>
long revolvingDoor (int n, int t, F &&visit)
 the \( t \)-combinations of \( 0 , \ldots , n - 1 \) in the revolving-door order
template<class F>
long integerPartitions (int n, F &&visit)
 the partitions of \( n \), their parts nonincreasing, in reverse lexicographic order, \( O( 1 ) \) amortized per partition
template<class F>
long setPartitions (int n, F &&visit)
 the restricted growth strings of the partitions of a set of \( n \) items, in lexicographic order, \( O( 1 ) \) amortized per partition
template<class F>
long nestedParentheses (int n, F &&visit)
 the strings of \( n \) pairs of balanced parentheses, in lexicographic order
bool legalTiling (const std::vector< Tile > &D, int n, const Tiling &T)
 whether \( T \) is a legal covering of the \( n \times n \) square by \( D \), with \( d = D[ 0 ] \) in \( ( 0 , 0 ) \); false if \( n < 1 \), if \( T \) is not \( n \times n \) or if a tile of \( T \) is not one of \( D \)
std::optional< Tiling > squareTiling (const std::vector< Tile > &D, int n)
 a legal covering of the \( n \times n \) square, by backtrack, or nothing (also if \( n < 1 \) or \( D \) is empty)
bool linearTiling (const std::vector< Tile > &D, long n)
 whether a strip of \( n \) tiles from \( d = D[ 0 ] \) exists, \( O( m^2 ) \); false if \( n < 1 \) or \( D \) is empty, true for any \( n \) if a cycle of tiles that fit is reachable from \( d \)
int literalNode (int l)
 the node of the literal \( \pm( v + 1 ) \) in the graph of the implications, \( 2 v \) for \( v \) and \( 2 v + 1 \) for its negation
std::optional< std::vector< bool > > twoSat (const Cnf &F, int n)
 an assignment of the \( n \) variables that satisfies \( F \), each clause of one or two literals, or nothing
std::optional< std::vector< int > > twoColoring (const Adjacency &G)
 the side, 0 or 1, of each node of \( G \), the ends of each edge apart, or nothing if \( G \) has an odd cycle; the diagonal of \( G \) is ignored, as by coloring() [see Problems.h]
std::vector< std::pair< int, int > > bipartiteMatching (int p, int q, const std::vector< std::pair< int, int > > &E)
 the pairs \( ( i , j ) \) of a largest matching of the bipartite graph with \( p \) left and \( q \) right nodes and the edges \( ( i , j ) \) of \( E \), by a maximum flow
Adjacency intervalGraph (const std::vector< std::pair< long, long > > &I)
 the graph of the intervals \( [ a , b ) \), an edge if two share a point: an empty interval \( [ a , a ) \) meets none, as in intervalClique()
int intervalClique (const std::vector< std::pair< long, long > > &I)
 the largest clique of the graph of the intervals \( [ a , b ) \): the most intervals through one point, the right ends before the left ones
bool cliqueCertificate (const Adjacency &G, const Nodes &S, int k)
 whether \( S \), of distinct nodes, has \( k \) of them or more, all adjacent (the certificatoCricca() of the book)
std::optional< Nodes > clique (const Adjacency &G, int k)
 \( k \) nodes all adjacent, or nothing (the enCricca() of the book)
std::optional< Nodes > independentSet (const Adjacency &G, int k)
 \( k \) nodes no two adjacent, or nothing
std::optional< Nodes > vertexCover (const Adjacency &G, int k)
 at most \( k \) nodes that touch every edge, or nothing
std::optional< std::vector< int > > coloring (const Adjacency &G, int k)
 a coloring of the nodes with at most \( k \) colors, adjacent nodes of different colors, by backtrack, or nothing (exercise 18.6)
std::optional< Nodes > bisection (const Adjacency &G, int k)
 a partition of the nodes in two halves cut by at most \( k \) edges, or nothing; the half of node 0
template<class T>
bool tspCertificate (const std::vector< std::vector< T > > &D, T k, const Nodes &P)
 whether the tour \( P \), a permutation, is at most \( k \) long; the empty tour of no city is 0 long (the certificatoTsp() of the book)
template<class T>
std::optional< Nodes > tsp (const std::vector< std::vector< T > > &D, T k)
 a tour of length at most \( k \) from city 0, the partial tours longer than \( k \) pruned, or nothing (the enTsp() of the book)
std::optional< Nodes > hamiltonianCircuit (const Adjacency &G)
 an unoriented circuit through every node once (\( n \ge 3 \)), or nothing
std::optional< Nodes > hamiltonianCycle (const Adjacency &G)
 an oriented cycle through every node once (\( n \ge 2 \)), or nothing
std::optional< Nodes > hamiltonianPath (const Adjacency &G, int r=-1, int t=-1)
 an oriented path through every node once, from \( r \) and to \( t \) if given
std::optional< Nodes > hamiltonianChain (const Adjacency &G)
 an unoriented chain through every node once
std::optional< Nodes > longestPath (const Adjacency &G, int r, int t, int k)
 a simple path from \( r \) to \( t \) of at least \( k \) edges, by backtrack
int longestPathDag (const Adjacency &G, int r, int t)
 the most edges of a path from \( r \) to \( t \) in an acyclic oriented graph, \( -1 \) if \( t \) is not reachable; \( O( n^2 ) \) by the topological order
std::optional< std::vector< std::pair< int, int > > > boundedSpanningTree (const Adjacency &G, int k)
 a spanning tree of the unoriented graph with at most \( k \) edges at each node, as \( n - 1 \) edges, by enumeration, or nothing
bool satCertificate (const Cnf &F, const std::vector< bool > &x)
 whether \( x \) satisfies every clause of \( F \)
std::optional< std::vector< bool > > satisfiable (const Cnf &F, int n)
 an assignment of the \( n \) variables that satisfies \( F \), by backtrack with a clause checked as soon as its variables are set, or nothing
std::optional< std::vector< int > > lp01 (const std::vector< std::vector< long > > &A, const std::vector< long > &b, int n)
 a 0-1 vector \( x \) with \( A x \le b \), by enumeration, or nothing
std::optional< Nodes > subsetSumExists (const std::vector< long > &A, long k)
 a set of the places of \( A \) of sum \( k \), by backtrack, or nothing
std::optional< Nodes > partition (const std::vector< long > &A)
 the places of a half of \( A \) of half the sum, or nothing
std::optional< Nodes > knapsackDecision (const std::vector< long > &p, const std::vector< long > &v, long C, long k)
 objects of volume at most \( C \) and profit at least \( k \) (the enZaino() of the book)
std::optional< std::vector< int > > multiprocessorScheduling (const std::vector< long > &t, int m, long d)
 the processor of each program, so that \( m \) processors run them all within time \( d \), or nothing (also if \( d < 0 \), even with no programs, since an idle processor is loaded 0)
std::optional< Nodes > exactCover3 (const std::vector< std::array< int, 3 > > &Y, int m)
 sets of three of \( \{ 0 , \ldots , m - 1 \} \) that partition it, by places, the ones that meet those chosen pruned, or nothing (the enCopertura() of the book)
std::optional< Nodes > threeDimensionalMatching (const std::vector< std::array< int, 3 > > &M, int q)
 a matching of \( q \) triples \( ( w , x , v ) \) of \( M \) with distinct \( w \), \( x \) and \( v \), the three sets being \( [ 0 , q ) \), or nothing
std::optional< std::vector< long > > bribes (std::vector< long > M, const std::vector< bool > &ps)
 the \( n \) bribes \( M \) to the \( n \) politicians, \( \mathit{ps}[ i ] \) if the \( i \)-th is of the party PS, so that the PS gets twice the party PDF; the bribe of each politician, or nothing (the mazzette() of the book)
int tileVar (int h, int i, int j, int n)
 the place \( ( h n + i ) n + j \) of the variable or node of the tile \( h \) in the square \( ( i , j ) \)
std::pair< Adjacency, int > dominoToClique (const std::vector< Tile > &D, int n)
 BOUNDED TILING to CLIQUE: the graph on the \( m n^2 \) places of tileVar(), the ones of \( ( 0 , 0 ) \) but \( u_{000} \) isolated, and \( k \).
Cnf dominoToSat (const std::vector< Tile > &D, int n)
 BOUNDED TILING to SATISFIABILITY, on the \( m n^2 \) variables of tileVar().
std::pair< std::vector< std::vector< long > >, std::vector< long > > dominoToLp01 (const std::vector< Tile > &D, int n)
 BOUNDED TILING to 0-1 INTEGER PROGRAMMING: \( A x \le b \) on the \( m n^2 \) variables of tileVar(), each equation as two inequalities.
Adjacency complement (const Adjacency &G)
 the complement graph: CLIQUE of size \( k \) to INDEPENDENT SET of size \( k \)
std::vector< std::vector< long > > hamiltonToTsp (const Adjacency &G)
 HAMILTONIAN CIRCUIT to TRAVELING SALESMAN: the distances, \( k = n \).
long halfSum (const std::vector< long > &A)
 half the sum, or \( -1 \) if the sum is odd (then no partition: the bound \( -1 \) has no YES in any of the three problems)
Adjacency cycleToPath (const Adjacency &G)
 DIRECTED HAMILTONIAN CIRCUIT to DIRECTED HAMILTONIAN PATH from \( n \) to 0: the node 0 split, a new node \( n \) with the edges out of 0; the loops of \( G \) dropped, as the problems of Problems.h ignore them.
Adjacency cycleToChain (const Adjacency &G)
 DIRECTED HAMILTONIAN CIRCUIT to HAMILTONIAN PATH: the path of cycleToPath(), each node \( v \) a chain \( v_{in} - v_{mid} - v_{out} \), each edge \( ( u , v ) \) an edge \( [ u_{out} , v_{in} ] \), and pendant nodes at the start and at the end.
std::vector< Point > sortToHull (const std::vector< long > &a)
 SORTING to CONVEX HULL: the points \( ( a , a^2 ) \).
template<class C>
std::pair< Rational, Rational > arithmeticInterval (std::span< const C > text, const std::map< C, Rational > &prob)
 the interval \( [ l , l + s ) \) of text, as the pair \( ( l , s ) \)
template<class C>
std::string arithmeticCodeExact (std::span< const C > text, const std::map< C, Rational > &prob)
 the arithmetic code of text: the first \( \lceil \log_2( 2 / s ) \rceil \) bits of \( l + s / 2 \), a string of '0' and '1'
template<class C>
std::vector< C > arithmeticDecodeExact (const std::string &bits, std::size_t n, const std::map< C, Rational > &prob)
 the text of \( n \) symbols of the code bits
template<class C>
std::vector< std::uint8_t > arithmeticEncode (std::span< const C > text, const std::map< C, std::uint64_t > &counts, int w=32)
 the arithmetic code of text with the static model of the counts
template<class C>
std::vector< C > arithmeticDecode (std::span< const std::uint8_t > code, std::size_t n, const std::map< C, std::uint64_t > &counts, int w=32)
 the \( n \) symbols of the code with the static model of the counts
std::vector< std::uint8_t > adaptiveArithmeticEncode (std::span< const std::uint32_t > x, std::uint32_t sigma)
 the adaptive arithmetic code of the symbols of \( x \) in \( [ 0 , \sigma ) \)
std::vector< std::uint32_t > adaptiveArithmeticDecode (std::span< const std::uint8_t > code, std::size_t n, std::uint32_t sigma)
 the \( n \) symbols of the adaptive arithmetic code in \( [ 0 , \sigma ) \)
std::vector< std::uint8_t > adaptiveArithmeticEncode (std::string_view s)
 the adaptive arithmetic code of the bytes of \( s \), those of adaptiveArithmeticEncode() above with \( \sigma = 256 \)
std::string adaptiveArithmeticDecode (std::span< const std::uint8_t > code, std::size_t n)
 the \( n \) bytes of the adaptive arithmetic code, by adaptiveArithmeticDecode() above with \( \sigma = 256 \)
std::vector< std::uint8_t > binaryPack (std::span< const std::uint32_t > x, bool sorted=false)
 the binary packing of \( x \) in blocks of 128 integers, of their differences at a distance of 4 if sorted
std::vector< std::uint32_t > binaryUnpack (std::span< const std::uint8_t > in, std::size_t n, bool sorted=false)
 the \( n \) integers of the code in, packed with the same sorted
std::vector< std::uint8_t > patchedPack (std::span< const std::uint32_t > x, bool sorted=false)
 the patched binary packing (PFor) of \( x \) in blocks of 128 integers, of their differences at a distance of 4 if sorted
std::vector< std::uint32_t > patchedUnpack (std::span< const std::uint8_t > in, std::size_t n, bool sorted=false)
 the \( n \) integers of the patched code in, packed with the same sorted
BWT bwt (std::string_view s, std::size_t wideFrom=bwtWideFrom)
std::vector< std::size_t > lfMapping (const BWT &b)
 the LF-mapping of the \( n + 1 \) rows of the transform \( b \)
std::string inverseBwt (const BWT &b)
 the text of the transform \( b \)
std::vector< std::uint8_t > moveToFront (std::string_view s, std::string_view alphabet)
 the places of the symbols of \( s \) in the list alphabet, each moved to the front after its use
std::vector< std::uint8_t > moveToFront (std::string_view s)
 the move-to-front of moveToFront() above, with the 256 bytes in their order
std::string inverseMoveToFront (const std::vector< std::uint8_t > &x, std::string_view alphabet)
 the symbols of the places \( x \) in the list alphabet
std::string inverseMoveToFront (const std::vector< std::uint8_t > &x)
 the inverse of inverseMoveToFront() above, with the 256 bytes in their order
std::vector< std::pair< std::size_t, char > > runLengthEncode (std::string_view s)
 the maximal runs of \( s \) as pairs \( ( \ell , c ) \) of a length and a symbol
std::string runLengthDecode (const std::vector< std::pair< std::size_t, char > > &R)
 the text of the runs \( R \)
std::vector< std::uint32_t > zeroRunEncode (const std::vector< std::uint8_t > &x)
 the RLE0 of bzip: the integers of \( x \) but 0 grown by 1, each run of \( m \) zeros in the code of Wheeler, the digits of \( m + 1 \) after the leading 1
std::vector< std::uint8_t > zeroRunDecode (const std::vector< std::uint32_t > &y)
 the integers of an RLE0
std::vector< std::uint8_t > bzipCompress (std::string_view s, std::size_t block=900000)
 the bzip of \( s \): blocks of at most block symbols, each transformed, moved to front, coded by RLE0 and by its canonical code of Huffman
std::string bzipDecompress (std::span< const std::uint8_t > code)
 the text of a bzip
template<class C, class F>
std::map< C, int > huffmanLengths (const std::map< C, F > &freq)
 the lengths of the codes of Huffman [see Huffman.h] of the symbols with the frequencies freq
template<class C, class F>
std::map< C, int > limitedLengths (const std::map< C, F > &freq, int L)
 the lengths of a code of Huffman of no length above \( L \), by halving the frequencies (rounding up) until the code of Huffman of the halved ones has no length above \( L \)
template<class C, class F>
double entropy (const std::map< C, F > &freq)
 the entropy of order 0, in bits per symbol, of the distribution proportional to the frequencies \( f \) of freq
double entropy (std::string_view s)
 the empirical entropy of order 0 of \( s \), in bits per symbol; 0 if \( s \) is empty
double entropy (std::string_view s, std::size_t k)
 the empirical entropy of order \( k \) of \( s \), in bits per symbol; 0 if \( s \) is empty
std::vector< std::uint8_t > huffmanCompress (std::span< const std::uint8_t > in)
 the code of Huffman of the bytes of in, with the lengths and the size
std::vector< std::uint8_t > huffmanDecompress (std::span< const std::uint8_t > in)
 the bytes that huffmanCompress() coded in in
std::array< std::uint8_t, 256 > limitedHuffmanLengths (const std::array< std::uint64_t, 256 > &f, int L)
 the optimal lengths of at most \( L \) bits of the codes of the 256 bytes of frequencies \( f \), 0 for a byte of frequency 0, by package-merge
constexpr int binaryLength (std::uint64_t x)
 \( | B( x ) | \), the bits of the binary code of \( x \), \( 1 + \lfloor \log_2 x \rfloor \)
constexpr std::uint64_t signedToNatural (std::int64_t x)
 \( x \) as a natural number: \( 2 x \) if \( x \ge 0 \), \( -2 x + 1 \) if \( x < 0 \)
constexpr std::int64_t naturalToSigned (std::uint64_t y)
 the inverse of signedToNatural(): \( y / 2 \) if \( y \) is even, \( -( y - 1 ) / 2 \) if odd
std::vector< std::uint64_t > dGaps (const std::vector< std::uint64_t > &x)
 the d-gaps of a non-decreasing sequence: the first item, then the differences between consecutive items
std::vector< std::uint64_t > prefixSums (const std::vector< std::uint64_t > &g)
 the sequence of the d-gaps \( g \), i.e., their prefix sums
void encodeUnary (BitWriter &w, std::uint64_t x)
 \( U( x ) \), \( x - 1 \) zeros and a 1
std::uint64_t decodeUnary (BitReader &r)
 the integer \( x \ge 1 \) whose \( U( x ) \) is next in \( r \): one plus the zeros before the next 1
constexpr std::uint64_t unaryLength (std::uint64_t x)
 the bits of \( U( x ) \), i.e., \( x \)
void encodeGamma (BitWriter &w, std::uint64_t x)
 \( \gamma( x ) \), \( | B( x ) | - 1 \) zeros and \( B( x ) \)
std::uint64_t decodeGamma (BitReader &r)
 the integer whose \( \gamma \) is next in \( r \)
constexpr int gammaLength (std::uint64_t x)
 the bits of \( \gamma( x ) \), \( 2 \lfloor \log_2 x \rfloor + 1 \)
void encodeDelta (BitWriter &w, std::uint64_t x)
 \( \delta( x ) \), \( \gamma( | B( x ) | ) \) and \( B( x ) \)
std::uint64_t decodeDelta (BitReader &r)
 the integer whose \( \delta \) is next in \( r \)
constexpr int deltaLength (std::uint64_t x)
 the bits of \( \delta( x ) \), \( 1 + 2 \lfloor \log_2 | B( x ) | \rfloor + | B( x ) | \)
void encodeRice (BitWriter &w, std::uint64_t x, int k)
 \( R_k( x ) \), \( U( q + 1 ) \) and the remainder \( r \) in \( k \) bits, \( x - 1 = q 2^k + r \)
std::uint64_t decodeRice (BitReader &r, int k)
 the integer whose \( R_k \) is next in \( r \): \( q 2^k + r + 1 \), \( q + 1 \) read in unary and \( r \) in \( k \) bits
constexpr std::uint64_t riceLength (std::uint64_t x, int k)
 the bits of \( R_k( x ) \), \( \lfloor ( x - 1 ) / 2^k \rfloor + 1 + k \)
void encodeGolomb (BitWriter &w, std::uint64_t x, std::uint64_t b)
 Golomb's code of modulus \( b \), \( U( q + 1 ) \) and the remainder \( r \) in the truncated binary code, \( x - 1 = q b + r \).
std::uint64_t decodeGolomb (BitReader &r, std::uint64_t b)
 the integer whose Golomb's code of modulus \( b \) is next in \( r \)
constexpr std::uint64_t golombLength (std::uint64_t x, std::uint64_t b)
 the bits of Golomb's code of \( x \) of modulus \( b \)
int pforDeltaWidth (const std::vector< std::uint64_t > &x, std::uint64_t base, double f=0.9)
 the smallest \( b \) whose range \( [ \mathit{base} , \mathit{base} + 2^b - 2 ] \) holds at least the fraction \( f \) of the values (all of them if \( f = 1 \)), at most 63
PForDeltaBlock encodePForDelta (const std::vector< std::uint64_t > &x, int b, std::uint64_t base=0)
 the values \( x \) in slots of \( b \) bits after subtracting base
std::vector< std::uint64_t > decodePForDelta (const PForDeltaBlock &p)
 the values of the block \( p \): each slot plus the base, or the next exception for an escape
void encodeVByte (std::vector< std::uint8_t > &out, std::uint64_t x)
 the variable-byte code of \( x \) appended to out
std::uint64_t decodeVByte (const std::vector< std::uint8_t > &in, std::size_t &p)
 the integer coded from \( \mathit{in}[ p ] \), \( p \) moved past it: the groups of 7 bits gathered up to the byte below \( 2^7 \)
constexpr int vbyteLength (std::uint64_t x)
 the bytes of the variable-byte code of \( x \), \( \lceil | B( x ) | / 7 \rceil \), and 1 for \( x = 0 \)
void encodeDense (std::vector< std::uint32_t > &out, std::uint64_t x, std::uint32_t s, std::uint32_t c)
 the \( ( s , c ) \)-dense code of \( x \) appended to out, a word per item: the continuers \( s , \ldots , s + c - 1 \) and then a stopper \( 0 , \ldots , s - 1 \)
std::uint64_t decodeDense (const std::vector< std::uint32_t > &in, std::size_t &p, std::uint32_t s, std::uint32_t c)
 the integer coded from \( \mathit{in}[ p ] \), \( p \) moved past it
constexpr int denseLength (std::uint64_t x, std::uint32_t s, std::uint32_t c)
 the words of the \( ( s , c ) \)-dense code of \( x \)
std::uint32_t denseOptimalS (const std::vector< std::uint64_t > &f, int bits=8)
 the number \( s \) of stoppers, \( c = 2^{\mathit{bits}} - s \), that minimizes the words of the integers \( 0 , 1 , \ldots \) of frequencies \( f \), by trying each \( s \)
void encodeBounded (BitWriter &w, std::uint64_t x, std::uint64_t a, std::uint64_t b)
 \( x - a \) in \( \lceil \log_2( b - a + 1 ) \rceil \) bits, the BinaryCode of chapter 11, Integer Coding, of Ferragina's book
std::uint64_t decodeBounded (BitReader &r, std::uint64_t a, std::uint64_t b)
 the integer in \( [ a , b ] \) coded next in \( r \) by encodeBounded()
void encodeInterpolative (BitWriter &w, const std::vector< std::uint64_t > &x, std::uint64_t low, std::uint64_t hi)
 the interpolative code of \( x \), which \( \mathit{low} \) and \( \mathit{hi} \) bound
std::vector< std::uint64_t > decodeInterpolative (BitReader &r, std::size_t n, std::uint64_t low, std::uint64_t hi)
 the \( n \) integers coded in \( [ \mathit{low} , \mathit{hi} ] \), by the recursion of encodeInterpolative() with decodeBounded() in place of encodeBounded()
std::vector< LZ77Phrase > lz77Parse (std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max())
 the parse of LZ77 of \( s \) with a window of \( w \) symbols, the closest among the longest copies
std::string lz77Decode (const std::vector< LZ77Phrase > &P)
 the text of the phrases \( P \) of LZ77
std::vector< LZSSPhrase > lzssParse (std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max(), std::size_t minLength=1)
 the parse of LZSS of \( s \) with a window of \( w \) symbols, a copy for the closest among the longest prefixes of length at least minLength, a literal otherwise, by searching the whole window
std::vector< LZSSPhrase > lzssParseHashed (std::string_view s, std::size_t w, std::size_t minLength=3, std::size_t maxChain=std::numeric_limits< std::size_t >::max())
 the parse of LZSS of \( s \) by the chains of the hashes of 3 symbols, as in gzip, following at most maxChain candidates
std::string lzssDecode (const std::vector< LZSSPhrase > &P)
 the text of the phrases \( P \) of LZSS
std::vector< LZ78Phrase > lz78Parse (std::string_view s, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max())
 the parse of LZ78 of \( s \), the dictionary restarting when it has maxPhrases phrases besides the empty one
std::string lz78Decode (const std::vector< LZ78Phrase > &P, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max())
 the text of the phrases \( P \) of LZ78
std::vector< std::uint32_t > lzwEncode (std::string_view s)
 the identifiers of the code of LZW of \( s \)
std::string lzwDecode (const std::vector< std::uint32_t > &I)
 the text of the code \( I \) of LZW
std::vector< LZ77Phrase > lz77ParseLinear (std::string_view s)
 the phrases of LZ77 of \( s \) with no window, in \( O( |s| ) \) time
std::vector< std::uint8_t > ppmEncode (std::string_view s, int K)
 the code of the bytes of \( s \) by PPM of order \( K \)
std::string ppmDecode (std::span< const std::uint8_t > code, std::size_t n, int K)
 the \( n \) bytes of the code by PPM of order \( K \)
std::vector< std::uint8_t > ransCompress (std::span< const std::uint8_t > in)
 the rANS code of order 0 of the bytes of in, with the frequencies and the size
std::vector< std::uint8_t > ransDecompress (std::span< const std::uint8_t > in)
 the bytes that ransCompress() coded in in
std::array< std::uint32_t, 256 > scaleFrequencies (const std::array< std::uint64_t, 256 > &f, int b)
 the frequencies \( f \) scaled to sum to \( 2^b \), each positive one kept positive
std::vector< std::uint8_t > streamVByteEncode (std::span< const std::uint32_t > x)
 the Stream VByte code of \( x \): the control bytes, then the data
std::vector< std::uint32_t > streamVByteDecode (std::span< const std::uint8_t > code, std::size_t n)
 the \( n \) integers of the Stream VByte code
std::vector< std::uint8_t > tansCompress (std::span< const std::uint8_t > in)
 the tANS code of order 0 of the bytes of in, with the frequencies and the size
std::vector< std::uint8_t > tansDecompress (std::span< const std::uint8_t > in)
 the bytes that tansCompress() coded in in
constexpr Product128 product128 (std::uint64_t a, std::uint64_t b)
 the product \( a b \) on 128 bits
constexpr std::uint64_t foldedProduct (std::uint64_t a, std::uint64_t b)
 the folded product: the low half of \( a b \) on 128 bits XOR its high half, \( ( a b \bmod 2^{64} ) \oplus \lfloor a b / 2^{64} \rfloor \)
constexpr std::uint64_t hashWord (std::uint64_t x, std::uint64_t seed=0)
 the hash of the word \( x \) under the seed, the folded product of \( x \) and of the seed XOR a constant
std::uint64_t hashBytes (const void *p, std::size_t n, std::uint64_t seed=0)
 the hash of the \( n \) bytes from \( p \) under the seed
unsigned bin_bit (std::string_view k, std::size_t j)
 the bit of place \( j \) of \( \mathrm{bin}( k ) \), counted from the left; 0 past the end
std::uint64_t int_bin (std::string_view k)
 \( \mathrm{int}( \mathrm{bin}( k ) ) \) of a key of at most 8 characters
std::uint64_t hash_extraction (std::string_view k, int p, std::size_t s)
 the extraction: the \( p \) bits of \( \mathrm{bin}( k ) \) from the place \( s \) on, counted from the left, as an integer in \( [ 0 , 2^p ) \)
std::uint64_t hash_xor (std::string_view k, int p)
 the XOR of the blocks of \( p \) bits of \( \mathrm{bin}( k ) \), the last one padded with zeros on the right
std::uint64_t hash_division (std::string_view k, std::uint64_t m, std::uint64_t base=256, std::uint64_t seed=0)
 the division \( \mathrm{int}( \mathrm{bin}( k ) ) \bmod m \) by the rule of Horner in the given base, each character being a digit, from the leading digit seed (the \( h = 5 \), \( h = 3 h + c \) is base 3 and seed 5); a character is any byte, up to 255 also in a base below 256
std::uint64_t hash_multiplication (std::uint64_t i, std::uint64_t m, long double C=(std::sqrt(5.0L) - 1)/2)
 the multiplication in floating point, the formula of the book, \( \lfloor m ( C i - \lfloor C i \rfloor ) \rfloor \): exact only while \( C i \) keeps enough digits after the point, i.e., for \( i \) well below the \( 2^{64} \) of the mantissa of a long double
std::uint64_t hash_fibonacci (std::uint64_t i, int p)
 the multiplication with integers for \( m = 2^p \), \( w = 64 \): the \( p \) most significant bits of the 64 least significant ones of \( i s \), with \( s = \lfloor C 2^{64} \rfloor \); it is \( \lfloor m \, \mathrm{frac}( i s / 2^{64} ) \rfloor \), which differs from the exact \( \lfloor m \, \mathrm{frac}( C i ) \rfloor \) by about \( m i / 2^{64} \)
std::uint64_t hash_midsquare (std::uint64_t i, int p)
 the middle square: the \( p \) bits in the middle of the 64 least significant ones of \( i^2 \)
constexpr std::uint64_t splitmix64 (std::uint64_t x)
 the mix of SplitMix64: a bijection of the words of 64 bits
constexpr std::uint64_t fibonacciPlace (std::uint64_t h, int b)
 the place of the hash \( h \) in a table of \( 2^b \) places, its top \( b \) bits after the product by \( \lfloor 2^{64} / \phi \rfloor \)
std::uint64_t canonicalWord (double x)
 the canonical word of \( x \): 0 for \( +0 \) and \( -0 \), one quiet NaN for every NaN, the bits of \( x \) otherwise
std::uint64_t rowFingerprint (std::span< const double > x, std::uint64_t seed=0)
 the fingerprint of the dense row \( x \) under the seed
template<class I>
std::uint64_t rowFingerprint (std::size_t n, const I *ind, const double *val, std::uint64_t seed=0)
 the fingerprint of the sparse row of the \( n \) entries \( ( \mathit{ind}[ k ] , \mathit{val}[ k ] ) \) under the seed: the values hashed as for a dense row, from the hash of the bytes of the indices
bool sameRow (std::span< const double > a, std::span< const double > b)
 true if the dense rows \( a \) and \( b \) have the same length and equal values, \( +0 \) equal to \( -0 \) and every NaN equal to every NaN
template<class I>
bool sameRow (std::size_t na, const I *ia, const double *va, std::size_t nb, const I *ib, const double *vb)
 true if the sparse rows of \( n_a \) and \( n_b \) entries have the same indices in the same order and equal values, in the sense above
bool is_prime (std::size_t n)
 true if \( n \) is prime, by trial division up to \( \sqrt{n} \)
std::size_t next_prime (std::size_t n)
 the smallest prime not smaller than \( n \), by trial divisions
bool is_pow2 (std::size_t n)
 true if \( n \) is a power of two, i.e., \( n \ne 0 \) and n & ( n - 1 ) is 0
std::size_t resized (std::size_t m, bool grow, std::size_t m0)
 the size after a doubling, or after a halving down to \( m_0 \)
std::uint64_t mergeSortIOs (std::size_t n, std::size_t M, std::size_t B, std::size_t k)
 the I/Os of a mergesort of fan-in at most \( k \), \( 2 \lceil n / B \rceil ( 1 + \lceil \log_k \lceil n / R \rceil \rceil ) \) with \( R = \lfloor M / B \rfloor B \): a pass that forms the runs and one per level of the merges, each reading and writing every block
std::uint64_t sortingLowerBound (std::size_t n, std::size_t M, std::size_t B)
 the least I/Os of a sort of \( n \) items by comparisons, \( \lceil n / B \rceil \) writes plus the reads that the tree of the I/Os needs, never fewer than \( \lceil n / B \rceil \)
std::uint64_t permutingLowerBound (std::size_t n, std::size_t M, std::size_t B)
 the least I/Os of a permutation of \( n \) items, the larger of \( 2 \lceil n / B \rceil \) and the smallest \( t \) with \( t ( \log_2 ( n + 1 ) + \log_2 \binom{M}{B} ) \ge \log_2 n! - \lceil n / B \rceil \log_2 B! \)
template<class T, class C = std::less<>>
void binaryMergeSort (const DiskFile< T > &in, DiskFile< T > &out, C less=C())
 the items of in, sorted, into out, by the binary mergesort
template<class T, class C = std::less<>, class Sel = LoserTree< T , C >>
void multiwayMergeSort (const DiskFile< T > &in, DiskFile< T > &out, C less=C(), bool snowPlow=false)
 the items of in, sorted, into out, by the mergesort of fan-in \( M / B - 1 \); the runs by replacement selection if snowPlow; the least of the heads of the runs chosen by a Sel, a tree of losers by default [see LoserTree.h for its interface]
template<class T, class R, class C = std::less<>>
void distributionSort (const DiskFile< T > &in, DiskFile< T > &out, R &g, C less=C())
 the items of in, sorted, into out, by the distribution with pivots from a random sample drawn by g
template<class T>
void permuteBySorting (const DiskFile< T > &in, const DiskFile< std::size_t > &pi, DiskFile< T > &out)
 \( \mathit{out}[ i ] = \mathit{in}[ \pi[ i ] ] \), by two sorts and three scans
template<class T>
void permuteDirect (const DiskFile< T > &in, const DiskFile< std::size_t > &pi, DiskFile< T > &out)
 \( \mathit{out}[ i ] = \mathit{in}[ \pi[ i ] ] \), one read per item at most
bool isList (const std::vector< std::size_t > &succ)
 whether \( \mathit{succ} \) is a list: one tail \( t \) with \( \mathit{succ}[ t ] = t \), and every item reached from the only item that is no successor
std::vector< std::size_t > listRank (const std::vector< std::size_t > &succ)
 the distances from the tail, by the predecessors and a walk back
std::vector< std::size_t > listRankPointerJumping (const std::vector< std::size_t > &succ, std::size_t *rounds=nullptr)
 the distances from the tail, by pointer jumping; the rounds go to *rounds, if given
template<class R>
std::vector< bool > randomIndependentSet (const std::vector< std::size_t > &succ, R &g)
 the heads whose successor shows tails, a coin per item drawn by g
std::vector< int > deterministicCoinTossing (const std::vector< std::size_t > &succ, std::size_t *rounds=nullptr)
 three colors in \( \{ 0 , 1 , 2 \} \), by deterministic coin tossing; the rounds down to six colors go to *rounds, if given
std::vector< bool > independentSetOfColors (const std::vector< std::size_t > &succ, const std::vector< int > &color)
 the items whose color is smaller than those of their neighbors, the tail excluded and not counted as a neighbor, so that a list of two items or more gives at least one
template<class R>
std::vector< std::size_t > listRankIndependentSet (const std::vector< std::size_t > &succ, R &g, bool deterministic=false, std::size_t *levels=nullptr)
 the distances from the tail, by removing independent sets, random ones drawn by g or, if deterministic, the local minima of the three colors; the levels of the recursion go to *levels, if given
template<class T, class Op>
void parallelStep (const DiskFile< T > &A, const DiskFile< std::pair< std::size_t, std::size_t > > &ops, Op op, DiskFile< T > &out)
 \( \mathit{out}[ i ] = \mathrm{op}( A[ i ] , A[ b ] ) \) for each pair \( ( i , b ) \) of ops, \( \mathit{out}[ i ] = A[ i ] \) for the \( i \) of no pair, the values of \( A \) read before any change; two sorts and three scans
void externalPointerJumping (const DiskFile< std::size_t > &succ, DiskFile< std::size_t > &rank, std::size_t *rounds=nullptr)
 the ranks of the list succ into rank, by pointer jumping, each round a parallelStep(); the rounds go to *rounds, if given
template<class R>
void externalListRank (const DiskFile< std::size_t > &succ, DiskFile< std::size_t > &rank, R &g, std::size_t *levels=nullptr)
 the ranks of the list succ into rank, by removing random independent sets drawn by g; the levels of the recursion go to *levels, if given
template<Persistent T>
void store (const T &x, std::ostream &s, ByteOrder o=ByteOrder::native)
 the structure \( x \) written to the stream \( s \), its payload in the order \( o \)
template<Persistent T>
void store (const T &x, const std::filesystem::path &p, ByteOrder o=ByteOrder::native)
 the structure \( x \) written to the file \( p \), made or replaced, its payload in the order \( o \)
template<Persistent T>
std::vector< std::byte > store (const T &x, ByteOrder o=ByteOrder::native)
 the bytes of the structure \( x \), as in a file, its payload in the order \( o \)
template<Persistent T>
T restore (std::istream &s)
 the structure read from the stream \( s \), its checksum checked
template<Persistent T>
T restore (std::span< const std::byte > b)
 the structure read from the bytes \( b \), its checksum checked
template<Persistent T>
T restore (const std::filesystem::path &p)
 the structure read from the file \( p \), its checksum checked
template<Persistent T>
T restoreMapped (const std::filesystem::path &p, bool verify=false)
 the structure of the file \( p \) mapped in memory, its arrays views over the mapping (copies if the file is of the other byte order, or the array is not on the allocator of the views), its checksum checked if \( \mathit{verify} \); the mapping lives as long as a view of it
std::int64_t squaredDistance (const Point &p, const Point &q)
 the square \( ( x_p - x_q )^2 + ( y_p - y_q )^2 \) of the distance of \( p \) and \( q \)
std::pair< std::pair< std::size_t, std::size_t >, std::int64_t > closestPair (const std::vector< Point > &P)
 the places \( i < j \) of the two closest points of \( P \) and the square of their distance, by divide et impera; \( O( n \log n ) \)
std::pair< std::pair< std::size_t, std::size_t >, std::int64_t > closestPairSweep (const std::vector< Point > &P)
 the pair of closestPair() by the sweep on the points sorted by \( x \), and by the randomized grid when the sweep takes too long; a pair of the least distance, not always the one of closestPair()
std::pair< std::pair< std::size_t, std::size_t >, std::int64_t > closestPairBrute (const std::vector< Point > &P)
 a closest pair, the first of the least distance in the order of the loops (not always the one of closestPair()), by all the pairs; \( \Theta( n^2 ) \)
long long cross (const Point &a, const Point &b, const Point &c)
 the cross product \( ( b - a ) \times ( c - a ) \): positive if \( c \) is to the left of the line from \( a \) to \( b \), 0 if on it; in long long, as long may have 32 bits
bool sameSide (const Point &p1, const Point &p2, const Point &p, const Point &q)
 true if \( p \) and \( q \) are on the same side of the line through \( p_1 \) and \( p_2 \), or on it (the stessaparte() of the book)
double pseudoAngle (long dx, long dy)
 an increasing function of the angle of the vector \( ( \mathit{dx} , \mathit{dy} ) \), in \( [ 0 , 4 ) \) and with no arctangent (exercise 16.1)
std::vector< Point > convexHullBrute (std::vector< Point > P)
 the hull by checking every segment, \( O( n^3 ) \); the vertices in counterclockwise order from the lowest one
std::vector< Point > graham (std::vector< Point > P)
 the vertices of the hull in counterclockwise order from the lowest point, the rightmost of the lowest ones, by the scan of Graham
std::vector< Point > convexHull (const std::vector< Point > &P)
 the hull by the octagon of Akl and Toussaint, the radix sort and the monotone chain of Andrew; the vertices as graham() gives them
template<Graph G>
AllPairs< typename G::Weight > floydWarshall (const G &g)
 the shortest paths between all the pairs of nodes
template<class D>
void addEdge (AllPairs< D > &R, int a, int b, const D &w)
 the insertion of the edge \( ( a , b ) \) of cost \( w \), \( O( n^2 ) \)
template<Graph G>
std::vector< int > maxCardinalityMatching (const G &g)
 the mate of each node in a matching of largest size of the unoriented graph \( g \), NIL for a node left unmatched and for a name that is not a node
template<class W>
requires std::is_arithmetic_v< W > && std::is_signed_v< W >
std::pair< W, std::vector< std::size_t > > maxWeightMatching (int n, const std::vector< std::tuple< int, int, W > > &E, bool maxCardinality=false)
 the largest total weight of a matching of the graph of \( n \) nodes and of the edges \( E = ( u , v , w ) \), or, if maxCardinality, the largest weight of a matching of largest size, and the places in \( E \) of its edges, in increasing order
template<Graph G>
std::optional< std::vector< int > > eulerianCycle (const G &g)
 the nodes of an Eulerian cycle of the graph, the first node repeated at the end, or nothing if there is none; empty with no edge
template<Graph G>
std::optional< std::vector< int > > eulerianTrail (const G &g)
 the nodes of an Eulerian trail of the graph, closed (the first node repeated at the end) if there is an Eulerian cycle and open otherwise, or nothing if there is none; empty with no edge
template<Graph G>
std::optional< std::vector< int > > eulerianTrail (const G &g, int s)
 the Eulerian trail of eulerianTrail() above from the node \( s \), or nothing if no Eulerian trail starts from it; empty with no edge
template<Graph G>
bool isEulerianCycle (const G &g, const std::vector< int > &c)
 whether the nodes \( c \), the first repeated at the end, are a closed path that uses each edge of \( g \) exactly once; empty if g has no edge
template<Graph G>
bool isEulerianTrail (const G &g, const std::vector< int > &c)
 whether the nodes \( c \) are a path, open or closed, that uses each edge of \( g \) exactly once, an unoriented edge in either direction; empty if g has no edge
template<Graph G>
std::vector< std::vector< int > > edgeDisjointPaths (const G &g, int s, int t, long long k=std::numeric_limits< long long >::max())
 at most \( k \) paths from \( s \) to \( t \) with no edge in common, as many as there can be, each as its nodes from \( s \) to \( t \)
template<class T>
CapacityDecrease decreaseCapacity (std::vector< std::vector< T > > &c, std::vector< std::vector< T > > &f, int s, int t, int u, int v)
 \( c( u , v ) \) decreases by 1, and the maximum flow \( f \) from \( s \) to \( t \) within \( c \) becomes a maximum flow within the new \( c \)
template<Graph G>
std::vector< std::vector< int > > incidence (const G &g)
 the matrix of incidence nodes-edges, the edges in the order of V() and of adj(), an unoriented one when met from its smaller end
std::vector< int > adjFromIncidence (const std::vector< std::vector< int > > &B, int u, bool directed)
 the adjacent nodes of \( u \) from the matrix of incidence \( B \) of a graph, oriented or not, in the order of the columns
bool insideGrid (int rows, int cols, GridCell x)
 whether \( ( r , c ) \) is a cell of a \( \mathit{rows} \times \mathit{cols} \) grid
template<class Free, class Moves = FourMoves>
std::vector< std::vector< int > > gridDistances (int rows, int cols, const std::vector< GridCell > &sources, Free &&free, const Moves &moves=FOUR_MOVES)
 the distance in moves of each cell of the \( \mathit{rows} \times \mathit{cols} \) grid from the nearest source, INF if none reaches it, entering only the cells \( x \) with \( \mathrm{free}( x ) \); \( D[ r ][ c ] \) for the cell \( ( r , c ) \)
template<class Free, class Moves = FourMoves>
int gridDistance (int rows, int cols, GridCell s, GridCell t, Free &&free, const Moves &moves=FOUR_MOVES)
 the distance in moves from the cell \( s \) to the cell \( t \) of the \( \mathit{rows} \times \mathit{cols} \) grid through the cells \( x \) with \( \mathrm{free}( x ) \), INF if \( t \) cannot be reached; the visit stops when \( t \) leaves the queue
template<class T, class Moves = FourMoves>
std::size_t floodFill (std::vector< std::vector< T > > &M, int r, int c, const std::type_identity_t< T > &color, const Moves &moves=FOUR_MOVES)
 the cell \( ( r , c ) \) of \( M \) and all the cells joined to it by moves through cells of its color get the color \( \mathit{color} \); the number of cells painted, 0 if \( \mathit{color} \) is already the color of \( ( r , c ) \)
int knightDistance (int n, GridCell s, GridCell t)
 the fewest moves of a knight from \( s \) to \( t \) on an \( n \times n \) board, INF if it cannot get there
template<class W, class C, class P>
std::vector< int > gridDistances (const GridGraph< W, C, P > &g, const std::vector< int > &S)
 the distance in moves of each cell of the grid \( g \) from the nearest of the nodes \( S \), INF if none reaches it or if the cell is blocked; \( D[ u ] \) for the cell \( u \)
template<class W = int>
W manhattan (GridCell a, GridCell b, W straight=W(1))
 the distance of Manhattan between the cells \( a \) and \( b \), \( \mathit{straight} \cdot ( | \Delta r | + | \Delta c | ) \), the least cost of a path of moves to the sides of cost \( \mathit{straight} \)
template<class W>
W octile (GridCell a, GridCell b, W straight, W diagonal)
 the octile distance between the cells \( a \) and \( b \), \( \mathit{straight} \cdot ( M - m ) + \mathit{diagonal} \cdot m \) with \( M \) and \( m \) the larger and the smaller of \( | \Delta r | \) and \( | \Delta c | \), the least cost of a path of moves to the sides and to the corners
template<class W = int>
W chebyshev (GridCell a, GridCell b, W straight=W(1))
 the distance of Chebyshev between the cells \( a \) and \( b \), \( \mathit{straight} \cdot \max\{ | \Delta r | , | \Delta c | \} \), the octile distance when a move to a corner costs as one to a side (the king)
template<class W, class C, class P>
W gridHeuristic (const GridGraph< W, C, P > &g, int u, int t)
 a lower bound on the cost of a path from \( u \) to \( t \) in \( g \), consistent, for the A* of Hart, Nilsson and Raphael: the least cost \( \gamma_{\mathrm{min}} \) of a cell times manhattan() for four moves and times octile() for eight, the latter with \( \min\{ \mathit{diagonal} , 2 \, \mathit{straight} \} \) as the cost of a corner; the same bound under both values of MoveCost, since a move weighs at least \( \gamma_{\mathrm{min}} \) times its unit cost whichever of its two cells pays (see Graphs on grid maps)
template<class W = double, class C = unsigned char>
GridGraph< W, C > readGridMap (std::istream &in, GridMoves moves=GridMoves::EIGHT, Corners corners=Corners::NO_CUT)
 the grid of a map in the format of the benchmarks of Sturtevant: the lines type octile, height \( h \), width \( w \) and map, then \( h \) lines of \( w \) characters, of which the dot, G and S are free cells of cost 1 and the others (O, T, W and the at sign) are blocked
std::vector< std::pair< int, int > > bipartiteBMatching (const std::vector< std::vector< int > > &A, int nr, const std::vector< long long > &capL, const std::vector< long long > &capR)
 the pairs \( ( u , v ) \) of a \( b \)-matching of largest size, \( A[ u ] \) the nodes on the right adjacent to the node \( u \) on the left, \( u \) in at most \( \mathit{capL}[ u ] \) pairs and \( v \) in at most \( \mathit{capR}[ v ] \)
template<class W>
std::pair< W, std::vector< std::size_t > > branchAndBoundMatching (int n, const std::vector< std::tuple< int, int, W > > &E)
 the largest total weight of a matching of the graph of \( n \) nodes and of the edges \( E = ( u , v , w ) \) by a branch and bound, and the places in \( E \) of its edges, in increasing order
bool feasibleCirculation (int n, const std::vector< BoundedEdge > &E, std::vector< long long > *flows=nullptr)
 whether the edges admit a circulation, a flow conserved at every node with \( \mathit{low} \le f( e ) \le \mathit{high} \); then the flows in *flows, if given
template<Graph G>
std::vector< WeightedEdge< typename G::Weight > > edges (const G &g)
 the edges of an unoriented graph, each once, from its smaller end
template<class W>
std::vector< WeightedEdge< W > > kruskal (int n, std::vector< WeightedEdge< W > > A, long k=0)
 the edges of a minimum spanning forest of the nodes \( [ 0 , n ) \); with \( k > 0 \) the weights are integers in \( [ 0 , k ) \), sorted by counting
template<class W, Mergeable M>
std::vector< WeightedEdge< W > > kruskal (int n, std::vector< WeightedEdge< W > > A, M &sets, long k=0, MergeCounts *c=nullptr)
 the minimum spanning forest of kruskal() above, with the MFSET sets given, whose merge( u , v ) joins the components of u and v and tells whether they were apart [see MFSet.h]; its work in *c, if given
template<Graph G>
auto kruskal (const G &g, long k=0)
 the minimum spanning forest of kruskal() above, on the edges of an unoriented graph
template<Graph G>
std::vector< int > prim (const G &g, int r, Frontier how=Frontier::HEAP)
 the parents of the tree from \( r \), NIL for \( r \) and the nodes out of its component; how is LIST, HEAP or FIBONACCI
template<Graph G, FrontierQueue Q>
std::vector< int > prim (const G &g, int r, Q &q, FrontierCounts *c=nullptr)
 the tree of prim() above, on the priority queue \( q \) given [see PriorityQueue.h], whose priority is the weight or the pair ( weight , node ), which breaks the ties by the names of the nodes; its work in *c, if given.
template<class W>
bool isMinimumSpanningForest (int n, const std::vector< WeightedEdge< W > > &A, const std::vector< WeightedEdge< W > > &T)
 whether \( T \) is a minimum spanning forest of the edges \( A \) on the nodes \( [ 0 , n ) \): its edges are in A, it has no cycle, as many edges as n minus the components of A, and no edge of A weighs less than the heaviest edge of the path of T between its ends, \( O( m n ) \)
template<class W>
constexpr EdgeDeleted< W > inverse (const EdgeInserted< W > &e)
 the inverse of an insertion of an edge, its deletion
template<class W>
constexpr EdgeInserted< W > inverse (const EdgeDeleted< W > &e)
 the inverse of a deletion of an edge, its insertion with the weight it had
template<class W>
constexpr WeightChanged< W > inverse (const WeightChanged< W > &e)
 the inverse of a change of a weight, the change back
template<class W>
constexpr unsigned kindOf (const GraphEvent< W > &e)
 the bit of the kind of \( e \)
template<class W>
std::pair< int, int > endsOf (const GraphEvent< W > &e)
 the ends of the edge of \( e \), \( ( -1 , -1 ) \) for an event on a node
template<class W>
std::vector< GraphEvent< W > > coalesce (std::span< const GraphEvent< W > > E)
 the net effect of the events \( E \), i.e., the nodes inserted, the edges in the order of their first event and the nodes deleted, by (8) of Changes of the graph and reoptimization, in \( O( |E| ) \) expected time
template<Graph G>
std::vector< std::uint64_t > countShortestPaths (const G &g, int s)
 the number of shortest paths, in edges, from \( s \) to each node, modulo \( 2^{64} \): 1 for \( s \), 0 for the nodes not reachable
template<Graph G>
std::pair< std::vector< int >, std::vector< int > > multiSourceDistance (const G &g, const std::vector< int > &S)
 the distance from the nearest node of \( S \), INF if none reaches it, and the parents in the forest of the shortest paths, NIL for the nodes of \( S \) and those not reached
template<Graph G>
int setDistance (const G &g, const std::vector< bool > &A, const std::vector< bool > &B)
 the fewest edges of a path from a node of \( A \) to one of \( B \), 0 if they meet, INF if there is none
template<Graph G>
std::vector< int > longestPathLayering (const G &g)
 the edges of a longest path ending at each node of the acyclic graph, 0 on the sources (and on the names that are not nodes)
template<Graph G, class Keep>
std::vector< PathLength< G > > dagLongestPaths (const G &g, Keep &&keep)
 the largest total length of a path leaving each node along the edges \( ( u , v ) \) with \( \mathrm{keep}( u , v ) \), the empty path included, 0 on the names that are not nodes
template<Graph G>
std::vector< PathLength< G > > dagLongestPaths (const G &g)
 the longest paths of dagLongestPaths() above, along all the edges
template<Graph G, class F>
void simpleCycles (const G &g, int s, F &&f)
 calls \( f( C ) \) on each simple cycle through \( s \), \( C \) its nodes from \( s \) back to \( s \)
template<class T>
std::optional< std::vector< std::size_t > > refuelingStops (const std::vector< T > &D, T L, T R)
 the places in \( D \) of the fewest stops of a trip from 0 to \( L \), a full tank lasting \( R \) and the stations at \( D \), nothing if the trip cannot be made
template<Graph G>
bool isTree (const G &g)
 whether the unoriented graph is a free tree, connected and with \( n - 1 \) edges
template<Graph G>
int diameter (const G &g)
 the largest distance in edges between two nodes
template<Graph G>
int treeDiameter (const G &g)
 the edges of a longest path of the free tree
template<class T>
std::pair< int, int > treeDiameter (const BinaryTree< T > *t)
 the diameter of a binary tree: its height and the edges of its longest path, \( ( -1 , 0 ) \) for the empty tree
template<Graph G>
std::vector< int > treeVertexCover (const G &g)
 the nodes of a minimum vertex cover of the forest, in increasing order
template<Graph G>
std::int64_t countTriangles (const G &g)
 the triangles of the unoriented graph
template<Graph G>
std::optional< std::vector< int > > twoColoring (const G &g)
 a color 0 or 1 for each node, the ends of each edge apart, -1 on the names that are not nodes; nothing if there is an odd cycle
template<class T>
int universalSink (const std::vector< std::vector< T > > &A)
 the node with an edge from every other one and no edge out, NIL if there is none, from the matrix of adjacency \( A \), whose entries convert to bool (the diagonal is not read)
template<Graph G>
requires requires( const G g , int u , int v ) { { g.hasEdge( u , v ) } -> std::convertible_to< bool >; }
int universalSink (const G &g)
 the universal sink of the graph \( G \), NIL if there is none, by the elimination of universalSink( A ) above on hasEdge(), at most \( 3 ( n - 1 ) \) calls of it, \( O( n ) \) time on the adjacency matrix of MatrixGraph (exercise 12.10 of Morin's book), where the in-degrees would take \( \Theta( n^2 ) \)
template<Graph G>
std::optional< std::vector< int > > uniqueTopologicalOrder (const G &g)
 the topological order of the oriented graph if it is the only one, nothing if it has a cycle or more orders
template<class D>
constexpr D infinity (void)
 the infinite distance of the type D
template<Graph G>
ShortestPathTree< typename G::Weight > shortestPaths (const G &g, int r, Frontier how)
 the shortest paths from \( r \) with the structure how
template<Graph G, class S>
requires PrototypeFrontier< S , typename G::Weight >
ShortestPathTree< typename G::Weight > shortestPaths (const G &g, int r, S &frontier, FrontierCounts *c=nullptr)
 the shortest paths of shortestPaths() above, with the structure \( S \) given, its work in *c if given
template<Graph G>
auto dijkstra (const G &g, int r)
 Dijkstra: a priority queue on an unsorted list, \( O( n^2 ) \).
template<Graph G>
auto johnson (const G &g, int r)
 Johnson: a priority queue on a binary heap, \( O( m \log n ) \).
template<Graph G>
auto fredmanTarjan (const G &g, int r)
 Fredman-Tarjan: a priority queue on a Fibonacci heap, \( O( m + n \log n ) \).
template<Graph G>
auto bellmanFordMoore (const G &g, int r)
 Bellman-Ford-Moore: a queue, \( O( n m ) \), negative cycles detected.
template<Graph G>
auto papeDEsopo (const G &g, int r)
 Pape-D'Esopo: a deque.
template<Graph G>
ShortestPathTree< typename G::Weight > dagShortestPaths (const G &g, int r)
 the shortest paths of an acyclic graph, scanning its nodes in topological order, \( O( n + m ) \)
template<Graph G>
bool isShortestPathTree (const G &g, int r, const ShortestPathTree< typename G::Weight > &R)
 whether \( R \) is a tree of shortest paths from \( r \): d[ r ] = 0, the unreachable nodes at infinity() with no parent, d[ v ] = d[ T[ v ] ]
template<Graph G>
bool reachesNegativeCycle (const G &g, int r)
 whether a negative cycle is reachable from \( r \), by Bellman-Ford, \( O( n m ) \)
template<class W, ArcLayout L>
std::vector< int > bfsOrder (const StaticGraph< W, L > &g, int r=0)
 the order of a visit in breadth from \( r \), then from the least node not reached, and so on: the name p[ u ] of each node u in the relabelled graph, a permutation of the nodes
template<Graph G>
std::vector< int > sccTarjan (const G &g)
 the strongly connected components of scc() by one visit in depth, with no transposed graph, numbered as there
template<Graph G>
std::vector< int > sccPearce (const G &g)
 the strongly connected components of sccTarjan() with one integer and one bit per node in place of three integers, numbered as scc() does
template<Graph G>
std::pair< std::vector< int >, std::vector< std::pair< int, int > > > genericVisit (const G &g, int r, Choice c)
 the general visit from \( r \): the nodes in the order in which they join \( R \), and the edges of the tree \( B \) in the order in which they join it
template<Graph G, class FN, class FE>
void bfs (const G &g, int r, FN &&node, FE &&edge)
 the visit in breadth from \( r \), calling node( u ) when \( u \) is examined and edge( u , v ) when \( ( u , v ) \) is examined
template<Graph G>
std::pair< std::vector< int >, std::vector< int > > distance (const G &g, int r)
 the distances from \( r \), INF if not reachable, and the parents in the tree of the shortest paths, NIL for \( r \) and the unreachable nodes
template<Graph G, class Q>
requires requires( Q q , int v ) { q.enqueue( v ); { q.dequeue() } -> std::convertible_to< int >; }
std::pair< std::vector< int >, std::vector< int > > distance (const G &g, int r, Q &S, VisitCounts *c=nullptr)
 the distances of distance() above, with the queue \( S \) given, empty, whose enqueue() and dequeue() keep the order of arrival [see ArrayQueue.h]; its work in *c, if given
std::vector< int > path (int r, int s, const std::vector< int > &p)
 the path from \( r \) to \( s \) in the tree of the parents \( p \), empty if there is none (the procedure printPath of the book)
template<Graph G, class Pre, class Edge, class Post>
void dfs (const G &g, int u, std::vector< bool > &visited, Pre &&pre, Edge &&edge, Post &&post)
 the visit in depth from \( u \), calling pre( u ) in the previsit, edge( u , v ) on each edge and post( u ) in the postvisit
template<Graph G>
std::vector< int > cc (const G &g, std::vector< int > S)
 the component of each node, numbered from 1, the visits starting from the nodes as they leave the stack \( S \) (its last item first)
template<Graph G>
std::vector< int > cc (const G &g)
 the components of cc() above, the visits starting from the nodes in increasing order
template<Graph G>
bool hasCycle (const G &g)
 true if the oriented graph has a cycle, i.e., if a visit finds a back edge; on an unoriented graph each edge, met again from its other end, is a back edge, so it is true if and only if there is an edge
template<Graph G>
bool isTopologicalOrder (const G &g, const std::vector< int > &S)
 whether \( S \) has each node once and each edge \( ( u , v ) \) has \( u \) before \( v \)
template<Graph G>
std::vector< int > topsort (const G &g)
 the nodes by decreasing finish time, which for an acyclic graph is a topological order; the first is the top of the stack of the book
template<Graph G>
std::vector< int > topsortKahn (const G &g)
 the topological order by removing the nodes with no entering edge, in the order of V() and then of discovery; fewer than \( n \) nodes if there is a cycle
template<Graph G>
ListGraph transpose (const G &g)
 the transposed graph, with the edges reversed
template<Graph G>
std::vector< int > scc (const G &g)
 the strongly connected component of each node, numbered from 1
template<Graph G>
bool unilaterallyConnected (const G &g)
 true if every two nodes have a path between them in one direction
template<ArrowNumber T>
constexpr const char * arrowFormat (void)
 the format of Arrow of the numbers of type \( T \)
template<class X>
requires ArrowExportable< std::remove_const_t< X > >
void exportArrow (std::shared_ptr< X > x, ArrowArray *a, ArrowSchema *s, std::string_view name="")
 the structure \( *x \) as a column of Arrow of no nulls, named \( \mathit{name} \), in \( *a \) and \( *s \), which its consumer releases; the values are those of \( *x \), which the array keeps alive (copied where the layouts differ, see above)
template<class X>
requires ArrowExportable< X >
void exportArrow (X x, ArrowArray *a, ArrowSchema *s, std::string_view name="")
 the structure \( x \) as a column of Arrow of no nulls, named \( \mathit{name} \), in \( *a \) and \( *s \): \( x \) is moved into the array, which keeps it alive until its consumer releases it
BitVector toBitVector (const ArrowArray &a, const ArrowSchema &s)
 the column of booleans \( a \) of type \( s \) copied into a BitVector; \( a \) and \( s \) are only read
template<unsigned B, bool S = false>
PackedArray< B, S > toPackedArray (const ArrowArray &a, const ArrowSchema &s)
 the column \( a \) of type \( s \) copied into a PackedArray< B , S >: a column of booleans if \( B = 1 \), or of integers of any width, each value clamped to \( 2^B - 1 \) if \( S \); \( a \) and \( s \) are only read
template<ArrowNumber T>
std::vector< T > toVector (const ArrowArray &a, const ArrowSchema &s)
 the column \( a \) of numbers of type \( T \), of type \( s \), copied into a std::vector; \( a \) and \( s \) are only read
template<class Ar, Persistent T>
void save (Ar &a, const T &x)
 the structure \( x \) written to the archive \( a \) of cereal
template<class Ar, Persistent T>
void load (Ar &a, T &x)
 the structure \( x \) read from the archive \( a \) of cereal
template<class Ar>
void save (Ar &a, const BitVector &b)
 the bits \( b \) written to the archive \( a \) of cereal, as sdsl-lite writes a bit_vector
template<class Ar>
void load (Ar &a, BitVector &b)
 the bits \( b \) read from the archive \( a \) of cereal, as sdsl-lite writes a bit_vector
roaring_bitmap_t * toCRoaring (const RoaringBitmap &s)
 the set \( s \) as a new bitmap of CRoaring, which the caller frees by roaring_bitmap_free()
RoaringBitmap fromCRoaring (const roaring_bitmap_t *r)
 the bitmap \( r \) of CRoaring as a RoaringBitmap
roaring::Roaring toRoaring (const RoaringBitmap &s)
 the set \( s \) as a roaring::Roaring of the C++ interface of CRoaring
RoaringBitmap fromCRoaring (const roaring::Roaring &r)
 the roaring::Roaring \( r \) of the C++ interface of CRoaring as a RoaringBitmap
sdsl::bit_vector toSdsl (const BitVector &b)
 the bits of \( b \) as a bit_vector of sdsl-lite, by a copy of the words
BitVector toBitVector (const sdsl::bit_vector &v)
 the bits of the bit_vector \( v \) of sdsl-lite as a BitVector, by a copy of the words
template<unsigned B, bool S>
sdsl::int_vector< B > toSdsl (const PackedArray< B, S > &a)
 the fields of \( a \) as an int_vector< B > of sdsl-lite, by a copy of the words
template<unsigned B, bool S = false, std::uint8_t W>
PackedArray< B, S > toPackedArray (const sdsl::int_vector< W > &v)
 the fields of the int_vector \( v \) of sdsl-lite as a PackedArray< B , S >: by a copy of the words if its width is \( B \), and else field by field, each clamped to \( 2^B - 1 \) if \( S \)
std::vector< int > firstFit (const std::vector< long > &A, long k, bool decreasing=false)
 the box of each object, the first one with room for it (ff), the objects in the order given or, if decreasing, in decreasing order of volume (ffd); the boxes are \( 0 , 1 , \ldots \)
template<class T>
T tourCost (const std::vector< std::vector< T > > &D, const Nodes &S)
 the cost \( \sum_i D[ S[ i ] ][ S[ ( i + 1 ) \bmod n ] ] \) of the circuit \( S \) of the distances \( D \)
template<class T>
Nodes deltaTsp (const std::vector< std::vector< T > > &D)
 the circuit of the nodes of a minimum spanning tree of the complete graph of the symmetric distances \( D \) in preorder from 0, the children by increasing name: at most twice the optimum if \( D \) is triangular
std::vector< std::vector< long > > tspGap (const Adjacency &G, long s)
 the distances of Theorem 19.2: 1 on the edges of \( G \), \( s n \) elsewhere; their optimum is \( n \) if \( G \) has a Hamiltonian circuit and more than \( s n \) otherwise
std::pair< long, Nodes > apSubsetSum (const std::vector< long > &A, long k, int h)
 the sum, at most \( k \), and the places of \( A \) of the best set found from the sets of at most \( h \) elements, \( \epsilon = 1 / ( h + 1 ) \); the sets of (1) in the order of the text, by size and then lexicographically on \( A \) in decreasing order
std::pair< long, Nodes > knapsackApprox (const std::vector< long > &p, const std::vector< long > &v, long C, double eps)
 the best profit and the objects of an \( \epsilon \)-approximation of KNAPSACK, profits \( p \) and volumes \( v \) within \( C \), by the rounded profits
Nodes vertexCoverApprox (const Adjacency &G)
 both ends of each edge \( [ u , v ] \), \( u < v \), whose ends are both out of \( S \), at most twice a minimum vertex cover; \( O( n^2 ) \) on the adjacency matrix
template<class T>
T spanningTreeWeight (const std::vector< std::vector< T > > &D, const Nodes &V)
 the weight of a minimum spanning tree of the nodes in \( V \), by the symmetric distances \( D \)
template<class T>
T oneTree (const std::vector< std::vector< T > > &D, int r)
 the weight of a minimum 1-tree of \( r \): a minimum spanning tree of the other nodes and the two least edges of \( r \); each circuit is a 1-tree, so that the weight bounds the optimum from below
template<class T>
T tspLowerBound (const std::vector< std::vector< T > > &D, const Nodes &S, TspBound how=TspBound::BOOK)
 a lower bound \( \mathit{lb}( S ) \) of the circuits that start with the path \( S \), the cost of the circuit if \( S \) has all the cities or if \( n = 2 \), where the circuit through both cities is the only one
template<class T>
std::pair< T, Nodes > bbTsp (const std::vector< std::vector< T > > &D, const Nodes &start={}, TspBound how=TspBound::BOOK, long *generated=nullptr)
 the cost and a minimum circuit from 0, starting from the circuit start if not empty; the number of nodes of the tree of the choices generated, the root included, goes to *generated, if given
template<class T, class O>
std::pair< T, Nodes > bbTsp (const std::vector< std::vector< T > > &D, const Nodes &start, TspBound how, long *generated, O &o)
 bbTsp( D , start , how , generated ), each improvement of the best cost told to \( o \) as IncumbentChanged< T >
template<class T>
std::pair< T, Nodes > littleTsp (const std::vector< std::vector< T > > &D, long *generated=nullptr)
 the cost and a minimum circuit from 0, by the reduction of the matrix; the number of nodes of the tree generated goes to *generated, if given
std::pair< long, Nodes > maxWeightClique (const Adjacency &G, const std::vector< long > &w, long *generated=nullptr)
 the weight and the nodes of a clique of \( G \) of largest weight (MAXIMUM WEIGHT CLIQUE), the weights \( w \) not negative; a set is extended by the candidates adjacent to all of it, and pruned when its weight and that of all the candidates is not above the best; the nodes generated go to *generated, if given
template<class O>
std::pair< long, Nodes > maxWeightClique (const Adjacency &G, const std::vector< long > &w, long *generated, O &o)
 maxWeightClique( G , w , generated ), each improvement of the best weight told to \( o \) as IncumbentChanged< long >
std::pair< long, Nodes > knapsackBB (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated=nullptr)
 the best profit and the objects of KNAPSACK by branch-&-bound, by places; the objects by decreasing profit per volume, each in and then out, pruned when the fractional knapsack of the rest does not beat the best; the nodes generated go to *generated, if given
template<class O>
std::pair< long, Nodes > knapsackBB (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated, O &o)
 knapsackBB( p , v , C , generated ), each improvement of the best profit told to \( o \) as IncumbentChanged< long >
std::pair< long, Nodes > knapsackBacktrack (const std::vector< long > &p, const std::vector< long > &v, long C, long *generated=nullptr)
 KNAPSACK by backtracking with the simple bound: the objects in their order, each in and then out, an object that does not fit skipped, and a node pruned when its profit plus the profits of all the objects still to decide does not beat the best; the nodes generated go to *generated.
std::pair< long, Nodes > knapsackGreedy (const std::vector< long > &p, const std::vector< long > &v, long C)
 the greedy heuristic of KNAPSACK: the objects by decreasing profit per volume, each taken if it still fits; not optimal in general
Board puzzleGoal (int n)
 the goal on \( n \times n \) squares, the tiles \( 1 , \ldots , n^2 - 1 \) by rows and the hole last
int manhattan (const Board &B, int n)
 the lower bound of the text: the sum over the tiles of the rows and columns between the tile and its place, \( \sum_{B[ p ] \ne 0} | \lfloor p / n \rfloor - \lfloor q / n \rfloor | + | p \bmod n - q \bmod n | \) with \( q = B[ p ] - 1 \)
std::vector< Board > puzzleMoves (const Board &B, int n)
 the configurations one move away, the hole swapped with the tile above, below, on the left and on the right of it, in this order
Board puzzleSpiralGoal (int n)
 the spiral goal on \( n \times n \) squares: the tiles clockwise from the top left corner, the hole where the spiral ends
std::optional< std::vector< Board > > puzzleBFS (const Board &B, const Board &goal, int n, long *visited=nullptr)
 the configurations from \( B \) to goal of a shortest solution by the visit in breadth, or nothing if goal cannot be reached; the configurations examined go to *visited, if given
std::optional< std::vector< Board > > puzzleDFS (const Board &B, const Board &goal, int n, int nmax)
 the configurations from \( B \) to goal of a solution of at most \( \mathit{nmax} \) moves by the backtracking in depth, or nothing if there is none
bool solvable (const Board &B, int n)
 whether the goal can be reached from \( B \)
template<class Map = std::map< Board , int >>
std::optional< std::vector< Board > > solvePuzzle (const Board &B, int n, long *visited=nullptr)
 the configurations from \( B \) to the goal of a shortest solution, or nothing; the number of nodes extracted goes to *visited, if given; the least level of each configuration is kept in a Map, std::map by default, or another map of std or Boost, or a hash table of ADS [see FlatHashTable.h], with the same nodes visited
template<class T>
std::pair< std::vector< std::pair< int, int > >, Nodes > greedyTsp (const std::vector< std::vector< T > > &D)
 the edges chosen, in the order of insertion, the last one closing the chain, and the circuit from 0, for the symmetric distances \( D \) of \( n \ge 3 \) cities
Nodes twoOptMove (Nodes pi, int i, int j)
 the circuit of \( I_2( \pi ) \) without the edges \( ( \pi[ i ] , \pi[ i + 1 ] ) \) and \( ( \pi[ j ] , \pi[ j + 1 ] ) \), \( 0 \le i < j < n \), not consecutive: the stretch \( \pi[ i + 1 .. j ] \) reversed
template<class T>
Nodes twoOpt (const std::vector< std::vector< T > > &D, Nodes pi, std::vector< T > *trace=nullptr)
 the local search on \( I_2 \) from \( \pi \), for the symmetric distances \( D \), taking the best circuit of the neighborhood while it improves; the costs of the circuits visited go to *trace, if given
long kOptNeighbors (int n, int k)
 the size of \( I_k( \pi ) \) on \( n \ge 3 \) nodes: the circuits that share exactly \( n - k \) edges with \( \pi \), by enumeration of all the circuits, \( O( n! ) \)
long kOptNeighbours (int n, int k)
 the former name of kOptNeighbors(), kept for the code that uses it
std::vector< int > partitionLocalSearch (const std::vector< long > &A, std::vector< int > side)
 the side, 0 or 1, of each element of \( A \), by the local search from side that moves an element or swaps two while the difference of the sums decreases, the best move first; \( O( n^2 ) \) each step
std::vector< int > minMaxGreedy (const Adjacency &G, int a, int b)
 the side of each node of \( G \), \( n \) even, from \( a \) in \( V_0 \) and \( b \) in \( V_1 \) (the min-max-greedy of the book)
int cutSize (const Adjacency &G, const std::vector< int > &side)
 the number of the edges across the two sides
int overlap (const std::string &a, const std::string &b)
 the length of the longest suffix of \( a \) that is a prefix of \( b \), at most \( \min\{ |a| , |b| \} \): the whole of \( b \) if \( a \) ends with it, 0 if either is empty
std::string greedySuperstring (const std::vector< std::string > &P)
 a common superstring of \( P \), by the greedy on the overlaps: the oriented edges \( ( i , j ) \) by decreasing overlap, each added if \( \mathit{out}[ i ] \) and \( \mathit{in}[ j ] \) are 0 and \( i , j \) are apart, and the path joined; the strings contained in another are dropped first
std::pair< int, std::vector< std::pair< std::string, std::string > > > starAlignment (const std::vector< std::string > &P)
 the star alignment: the center \( h \), the string with the largest sum of the global scores against the others, and its global alignment with each string, the center against itself included; \( O( k^2 n^2 ) \)
std::vector< int > dsatur (const Adjacency &G)
 the coloring by saturation degree: the color, from 0, of each node of \( G \), colored one at a time with the least color not on its neighbors, the next node the one with most distinct colors among its neighbors, then with most neighbors colored, then the first; \( O( n^3 ) \)
template<class Bits = std::vector< bool >>
bool subsetSumDP (const std::vector< long > &A, long k, std::vector< std::vector< bool > > *rows=nullptr)
 whether some elements of \( A \) sum to \( k \) (false if \( k < 0 \)), by the vector \( M \) with \( M[ j ] \) true if some of \( A[ 0 .. i ] \) sum to \( j \); the vector \( M \) after each element goes to *rows, if given, the first one before any; \( O( n k ) \) time; \( M \) is a vector of Bits, std::vector< bool > by default, or boost::dynamic_bitset, or BitVector of ADS [see BitVector.h], with the same cells written
std::optional< Nodes > subsetSumSet (const std::vector< long > &A, long k)
 the places of a subset of \( A \) of sum \( k \), by the table of all the rows, \( O( n k ) \) time and space, or nothing
std::optional< Nodes > partitionDP (const std::vector< long > &A)
 PARTITION by dynamic programming: the places of a half of \( A \) of half the sum, or nothing (exercise 19.1).
std::optional< std::vector< int > > schedulingDP (const std::vector< long > &t, int m, long d)
 MULTIPROCESSOR SCHEDULING by dynamic programming on the vectors of the loads of the \( m \) processors, each at most \( d \): the processor of each program, or nothing (also if \( d < 0 \), even with no programs, since an idle processor is loaded 0); \( O( n ( d + 1 )^m ) \) time (exercise 19.2).
std::pair< double, std::vector< std::vector< Piece > > > mcNaughton (const std::vector< double > &t, int m)
 the rule of McNaughton: the length \( d \) of the schedule and the pieces of each processor; the programs fill a processor up to \( d \) and go on at time 0 of the next one, and the two pieces of a program do not overlap because \( t[ i ] \le d \); \( O( n + m ) \) time (exercise 19.3)
std::optional< std::vector< std::vector< Piece > > > realTimeScheduling (const std::vector< double > &C, const std::vector< double > &T, int m)
 REAL-TIME SCHEDULING without priority rule: the tasks of time \( C[ i ] \) every \( T[ i ] \) run on \( m \) processors if and only if \( C[ i ] \le T[ i ] \) and \( \sum_i C_i / T_i \le m \); the schedule of a period of length 1, task \( i \) for the fraction \( C[ i ] / T[ i ] \) of it, or nothing (exercise 19.4).
std::optional< std::vector< int > > bottino (const std::vector< long > &P)
 the thief of each jewel of price \( P[ i ] \), so that the three thieves take \( m / 3 \) each, or nothing; \( S[ i ][ j ][ h ] \) tells whether the first \( i \) jewels give \( j \) to the first and \( h \) to the second thief, and the prices are not negative, so that \( j \) and \( h \) range in \( [ 0 , m / 3 ] \); \( O( n m^2 ) \) time (exercise 19.5)
template<Graph G>
MFSet components (const G &g)
 the MFSET of the connected components of an unoriented graph, built by merging the ends of each edge (the cc() of section 10.2.5); its elements are the names \( [ 0 , \mathrm{bound}() ) \) of \( g \), so that a name that is not a node of \( g \), a deleted one, is a component of its own, counted by count()
std::vector< int > offlineConnectivity (int n, const std::vector< ConnectivityOp > &ops)
 the answers to the questions of ops on \( n \) nodes, in their order: 1 or 0 for CONNECTED, the number of components for COMPONENTS
template<class S>
Batch< S > batch (S &s)
 a batch on the structure \( s \), open while it lives: its events are collected, and the outermost batch sends their net effect at its end
template<class S>
Quiet< S > quiet (S &s)
 a mute on the structure \( s \): no event while it lives, Rebuilt to every observer at its end (inside a batch, the events collected before are dropped, and the batch sends Rebuilt and the events after the mute)
template<class S>
Quiet< S > quiet (S &s, no_rebuild_t)
 a mute on the structure \( s \) that nobody needs to know: no event, and at the level of the audits the observers audited at its end
Bits toBits (std::uint64_t x, std::size_t n=0)
 the bits of \( x \), at least \( n \) of them
std::uint64_t fromBits (const Bits &b)
 the value \( \sum_i b_i 2^i \) of the bits, which must be at most 64
Bits carry (const std::vector< long > &c)
 the coefficients \( c_i \), possibly larger than 1 or negative, made bits of the same value \( \sum_i c_i 2^i \) by the carries
Bits binaryAdd (const Bits &X, const Bits &Y)
 the sum \( X + Y \), \( \Theta( n ) \)
std::vector< long > widen (const Bits &X)
 the bits of \( X \) as the coefficients of a polynomial in \( x = 2 \)
Bits multiplyBinarySchool (const Bits &X, const Bits &Y, long *mults=nullptr)
 the product \( X Y \) by the method of the school, \( \Theta( n^2 ) \); the products of two bits added to *mults, if given
Bits multiplyBinaryFour (const Bits &X, const Bits &Y, long *mults=nullptr)
 the product \( X Y \) by four products of half size, \( \Theta( n^2 ) \); the products of two bits added to *mults, if given
Bits multiplyBinaryKaratsuba (const Bits &X, const Bits &Y, long *mults=nullptr)
 the product \( X Y \) by the three products of Karatsuba, \( O( n^{1.59} ) \); the products of two bits added to *mults, if given
std::uint64_t ahmes (std::uint64_t a, std::uint64_t b, long *steps=nullptr)
 the product \( a b \) by the multiplication of Ahmes; the halvings added to *steps, if given
template<class T = std::uint64_t>
T catalan (int n)
 the number \( C_n \) of Catalan, the binary trees of \( n \) nodes
std::uint64_t binomial (int n, int k, long *calls=nullptr)
 the binomial coefficient \( \binom{n}{k} \) by the recursion; the calls added to *calls, if given
std::vector< std::vector< std::uint64_t > > tartaglia (int n)
 the triangle of Tartaglia, the table of the \( \binom{m}{k} \), \( 0 \le k \le m \le n \)
std::uint64_t fibonacciTable (int n)
 the number \( F_n \) of Fibonacci, \( F_0 = F_1 = 1 \), with a vector
std::uint64_t fibonacci (int n)
 the number \( F_n \) of Fibonacci, \( F_0 = F_1 = 1 \), in \( O( 1 ) \) space
std::uint64_t factorial (int n)
 the factorial \( n! \) by a loop
std::uint64_t factorialRec (int n)
 the factorial \( n! \) by the recursion \( n! = n ( n - 1 )! \), \( 0! = 1 \)
std::uint64_t binomialByFactorials (int n, int k)
 the binomial coefficient \( \binom{n}{k} \) as \( n! / ( k! ( n - k )! ) \)
template<class T>
void gemm (std::size_t m, std::size_t n, std::size_t k, T alpha, const T *A, std::size_t lda, const T *B, std::size_t ldb, T beta, T *C, std::size_t ldc)
 the product \( C \gets \alpha A B + \beta C \), \( A \) \( m \times k \), \( B \) \( k \times n \) and \( C \) \( m \times n \) by rows, with the leading dimensions lda, ldb, ldc (the distance of two rows); \( C \) is not read when \( \beta = 0 \)
template<class T>
DenseMatrix< T > multiply (const DenseMatrix< T > &A, const DenseMatrix< T > &B)
 the product \( A B \), a new matrix, by gemm() with \( \alpha = 1 \) and \( \beta = 0 \)
template<class T>
DenseMatrix< T > transpose (const DenseMatrix< T > &A)
 the transpose \( A^T \), by blocks of \( 32 \times 32 \)
template<class T>
DenseMatrix< T > multiplyStrassen (const DenseMatrix< T > &A, const DenseMatrix< T > &B, std::size_t cutoff=3072)
 the product \( A B \) by the variant of Winograd of the algorithm of Strassen, 7 products of halves and 15 sums a level, down to blocks of fewer than \( \mathit{cutoff} \) rows, columns or inner terms, multiplied by gemm()
template<class T>
Matrix< T > multiplyNaive (const Matrix< T > &A, const Matrix< T > &B, long *mults=nullptr)
 the product \( A B \) of two \( n \times n \) matrices by the definition, \( \Theta( n^3 ) \) (the moltiplicaMatrici() of the book); the products of two entries added to *mults, if given
template<class T>
Matrix< T > multiply (const Matrix< T > &A, const Matrix< T > &B)
 the product of \( A \), \( p \times q \), and \( B \), \( q \times r \), \( \Theta( p q r ) \); with \( q = 0 \) the vector \( B \) has no row to give \( r \), and the product is \( p \times 0 \)
template<class T>
Matrix< T > transpose (const Matrix< T > &A)
 the transpose \( A^T \), \( b_{ji} = a_{ij} \)
template<class T>
Matrix< T > scale (Matrix< T > A, const T &s)
 the product \( s A \) of the matrix by a scalar
template<class T>
Matrix< T > strassen (const Matrix< T > &A, const Matrix< T > &B, std::size_t cutoff=1, long *mults=nullptr)
 the product \( A B \) by the algorithm of Strassen, \( O( n^{2.81} ) \), the blocks of at most \( \mathit{cutoff} \) rows by the naive method; the products of two entries added to *mults, if given
std::pair< long, std::vector< std::vector< std::size_t > > > matrixChain (const std::vector< long > &c)
 the least cost \( \mathit{DP}[ 0 ][ n - 1 ] \) and the table \( S \) of the splits, for the \( n \) matrices of sizes \( c[ 0 .. n ] \) (the parentesizzazione() of the book)
std::string parenthesization (const std::vector< std::vector< std::size_t > > &S, std::size_t i, std::size_t j)
 the parenthesization of \( A_i \cdots A_j \) by the splits \( S \), e.g., ((A0·A1)·A2) (the stampaPar() of the book)
U64 gcd (U64 s, U64 m)
 the greatest common divisor \( \gcd( s , m ) \) by the algorithm of Euclid, \( O( \log m ) \) steps
constexpr U64 binaryGcd (U64 a, U64 b)
 the greatest common divisor of \( a \) and \( b \) by the binary algorithm, with no division; \( \gcd( a , 0 ) = a \)
std::tuple< long long, long long, long long > extendedEuclid (long long s, long long m)
 the triple \( ( d , p , q ) \) with \( s p + m q = d = \gcd( s , m ) \) (the euclideEsteso() of the book)
long long modInverse (long long s, long long m)
 the inverse \( p \in [ 0 , m ) \) of \( s \), with \( p s \bmod m = 1 \); a violation of the precondition if \( \gcd( s , m ) \ne 1 \)
constexpr U64 mulMod61 (U64 a, U64 b)
 the product \( a b \bmod p \), \( p = 2^{61} - 1 \), by four products of 32 bits and the folding \( 2^{61} \equiv 1 \pmod{p} \)
constexpr U64 mulMod (U64 a, U64 b, U64 m)
 the product \( a b \bmod m \), exact for any \( a \), \( b \) and \( m \): by the product of 64 bits for \( m \le 2^{32} \), by mulMod61() for \( m = 2^{61} - 1 \), and otherwise by the product of 128 bits and one division of two words by one
U64 powMod (U64 x, U64 v, U64 m)
 the power \( x^v \bmod m \) by repeated squaring, the products of Montgomery when \( m \) is odd
bool isPrimeTrial (U64 n)
 the primality of \( n \) by the divisions by \( 2 , \ldots , \lfloor \sqrt{n} \rfloor \) (the primo() of the book)
bool witness (U64 n, U64 b)
 true if \( b \) is a witness that the odd \( n > 2 \) is composite
template<class R>
bool millerRabin (U64 n, int K, R &rng)
 the primality of \( n \) by the test of Miller and Rabin on \( K \) random bases, wrong with probability at most \( ( 1 / 4 )^K \), and only on a composite \( n \) (the primo() of the book)
bool isPrime (U64 n)
 the primality of \( n \), exact for every \( n \) of 64 bits
std::vector< U64 > sieve (U64 n)
 the primes up to \( n \), increasing, by the sieve of Eratosthenes
std::vector< U64 > factorize (U64 n)
 the prime factors of \( n \), with their multiplicity, increasing, by the divisions by the primes below 4096, the elliptic curves of Lenstra and the rho of Pollard and Brent
template<class T>
std::vector< T > multiplyNaive (const std::vector< T > &p, const std::vector< T > &q, long *mults=nullptr)
 the product \( p q \) by all the products of two coefficients, \( \Theta( n^2 ) \) (the moltiplicaPolinomi() of the book); their number added to *mults, if given
template<class T>
std::vector< T > multiplyFour (const std::vector< T > &p, const std::vector< T > &q, long *mults=nullptr)
 the product \( p q \) by four recursive products of half size, \( \Theta( n^2 ) \) (the Prodotto4() of the book on polynomials); the products of two coefficients added to *mults, if given
template<class T>
std::vector< T > multiplyKaratsuba (const std::vector< T > &p, const std::vector< T > &q, long *mults=nullptr)
 the product \( p q \) by the three recursive products of Karatsuba, \( O( n^{1.59} ) \) (the moltiplicaPolinomiD&I() of the book); the products of two coefficients added to *mults, if given
template<FullWordGenerator G>
std::uint64_t uniformBelow (G &&g, std::uint64_t s)
 an integer uniform in \( [ 0 , s ) \), by the method of Lemire
template<FullWordGenerator G>
double uniformReal (G &&g)
 a double uniform in \( [ 0 , 1 ) \), the top 53 bits of a word times \( 2^{-53} \)
template<FullWordGenerator G>
double normalZiggurat (G &&g)
 a normal deviate of mean 0 and variance 1, by the ziggurat of Marsaglia and Tsang with 256 layers
template<FullWordGenerator G>
double exponentialZiggurat (G &&g)
 an exponential deviate of mean 1, by the ziggurat of Marsaglia and Tsang with 256 layers
template<std::random_access_iterator I, FullWordGenerator G>
void shuffleFast (I first, I last, G &&g)
 the items of \( [ \mathit{first} , \mathit{last} ) \) shuffled by \( g \), every permutation equally likely, the indices drawn in batches
double chiSquare (const std::vector< long > &Y, const std::vector< double > &p)
 the chi-square statistic \( V \) of the counts \( Y \) against the probabilities \( p \) over \( n = \sum_s Y_s \) samples
std::pair< double, double > kolmogorovSmirnov (std::vector< double > U)
 the statistics \( ( K^+_n , K^-_n ) \) of Kolmogorov and Smirnov of the numbers \( U \) in \( [ 0 , 1 ) \) against the uniform distribution, scaled by \( \sqrt{n} \)
double serialTest (const std::vector< double > &U, int d)
 the chi-square statistic of the pairs \( ( U_{2j} , U_{2j+1} ) \) of numbers in \( [ 0 , 1 ) \) in \( d \times d \) cells, \( d^2 - 1 \) degrees of freedom
double spectralTest2 (std::uint64_t a, std::uint64_t m)
 the \( \nu_2 \) of the spectral test of the generator of multiplier \( a \) and modulus \( m \)
template<class T, class R>
void shuffle (std::vector< T > &A, R &g)
 the vector \( A \) shuffled by \( g \), every permutation equally likely if \( g \) is uniform on its range
template<class R>
std::vector< std::size_t > selectionSampling (std::size_t n, std::size_t N, R &g)
 \( n \) of the \( N \) items \( 0 , \ldots , N - 1 \), in order, by one pass
template<class T, class R>
std::vector< T > reservoirSampling (const std::vector< T > &S, std::size_t n, R &g)
 \( n \) items from the sequence \( S \), as if it were a stream of unknown length; all of \( S \), in its order, when \( S \) has at most \( n \) items (a stream shorter than the sample)
template<class R>
std::vector< std::size_t > sampleBySwaps (std::size_t n, std::size_t N, R &g)
 \( n \) of the positions \( 0 , \ldots , N - 1 \), sorted, by \( n \) swaps in an array of the \( N \) positions
template<class R>
std::vector< std::size_t > sampleByDictionary (std::size_t n, std::size_t N, R &g)
 \( n \) of the positions \( 0 , \ldots , N - 1 \), sorted, by a hash table of those drawn
template<class R>
std::vector< std::size_t > sampleBySorting (std::size_t n, std::size_t N, R &g, std::size_t *rounds=nullptr)
 \( n \) of the positions \( 0 , \ldots , N - 1 \), sorted, by a bucket sort of random positions; the rounds of draws go to *rounds, if given
template<class R>
std::vector< std::size_t > sampleBySkips (std::size_t n, std::size_t N, R &g, std::size_t *randoms=nullptr)
 \( n \) of the positions \( 0 , \ldots , N - 1 \), sorted, by the gaps of Vitter's Algorithm D (A when \( 13 n \ge N \)); the random numbers drawn go to *randoms, if given
template<class T, class R>
std::vector< T > heapSampling (const std::vector< T > &S, std::size_t n, R &g)
 \( n \) items of the stream \( S \), in the order of \( S \), by the \( n \) largest of random keys, as if the length of \( S \) were unknown
template<std::input_iterator I, std::sentinel_for< I > S, class R>
std::vector< std::iter_value_t< I > > reservoirSampleL (I first, S last, std::size_t n, R &g)
 \( n \) items of \( [ \mathit{first} , \mathit{last} ) \), a stream of unknown length, by the skips of Algorithm L, in no particular order; all of them, in their order, when the stream has at most \( n \) items
template<class R>
U64 randomPrime (int bits, R &rng)
 a random odd prime of exactly \( \mathit{bits} \) bits, by the test of Miller and Rabin on 40 bases
template<class R>
std::pair< RsaKey, RsaKey > rsaKeys (R &rng)
 a pair (public, private) of keys, with \( N \) of about 62 bits
U64 rsa (U64 M, const RsaKey &k)
 the message \( M < N \) under the key, \( M^e \bmod N \): encrypting with a public key, or decrypting and signing with a private one
template<class I, class V, class J>
std::size_t compressTriplets (std::size_t nmajor, std::size_t nminor, std::size_t z, const J *major, const J *minor, const V *value, I *beg, I *ind, V *val, AssemblyWorkspace< I, V > &work)
 the compressed form, by major index, of the \( z \) triplets \( ( \mathit{major}_k , \mathit{minor}_k , \mathit{value}_k ) \) of a matrix of \( \mathit{nmajor} \times \mathit{nminor} \), the values of equal places summed; the number of the entries
template<class I, class V, class J>
std::size_t compressTriplets (std::size_t nmajor, std::size_t nminor, std::size_t z, const J *major, const J *minor, const V *value, I *beg, I *ind, V *val)
 the form of compressTriplets() above, with a workspace of its own
template<class I, class V, class J>
std::size_t assembleCsc (std::size_t m, std::size_t n, std::size_t z, const J *row, const J *col, const V *value, I *beg, I *ind, V *val, AssemblyWorkspace< I, V > &work)
 the compressed sparse columns of the \( m \times n \) matrix of the \( z \) triplets \( ( \mathit{row}[ k ] , \mathit{col}[ k ] , \mathit{value}[ k ] ) \): beg has \( n + 1 \) places, ind holds the rows; the number of the entries
template<class I, class V, class J>
std::size_t assembleCsr (std::size_t m, std::size_t n, std::size_t z, const J *row, const J *col, const V *value, I *beg, I *ind, V *val, AssemblyWorkspace< I, V > &work)
 the compressed sparse rows of the same: beg has \( m + 1 \) places, ind holds the columns; the number of the entries
std::optional< std::vector< long > > greedyChange (std::vector< long > coins, long c)
 the coins taken by the greedy choice, the coins given in any order; nothing if it cannot pay
std::optional< long > optimalChange (const std::vector< long > &coins, long c)
 the fewest coins that pay \( c \), nothing if none
template<class T>
T coinsInALine (const std::vector< T > &V)
 the most the first player can be sure of in the game of the coins in a line \( V \), both players taking in turn the first or the last coin
std::vector< double > fractionalKnapsack (const std::vector< double > &p, const std::vector< double > &v, double C)
 the fractions \( x \) of the objects, by decreasing \( p_i / v_i \) (the zaino() of the book)
template<class T>
GridSquare largestSquare (const std::vector< std::vector< T > > &A)
 the largest square of nonzero cells of \( A \), the first in the order of the rows of its lower right cell
template<class C = std::uint64_t, class T>
C countLatticePaths (const std::vector< std::vector< T > > &B)
 the number of the paths from the upper left to the lower right cell of \( B \), each step right or down, through nonzero cells only; 0 for \( B \) empty
template<class T>
T maxNonAdjacentSum (const std::vector< T > &A)
 the largest sum of items of \( A \) no two of them adjacent, 0 for none
template<class T>
std::pair< T, std::vector< std::size_t > > nonAdjacentSelection (const std::vector< T > &A)
 the sum of maxNonAdjacentSum() and the places of its items, increasing; an item is taken only if it makes the sum larger
template<class T>
std::pair< T, std::vector< std::size_t > > paintHouses (const std::vector< std::vector< T > > &cost)
 the least cost of a painting of the houses, adjacent houses of different colors, \( \mathit{cost}[ h ][ c ] \) for the house \( h \) of the color \( c \), and the colors
template<class T>
std::optional< std::vector< std::size_t > > minimumIntervalCover (const std::vector< std::pair< T, T > > &I, T lo, T hi)
 the places of the fewest closed intervals \( I \) whose union contains \( [ \mathit{lo} , \mathit{hi} ] \), by increasing left end; nothing if there is none
std::vector< std::size_t > independentSet (const std::vector< std::pair< long, long > > &I)
 the places of a largest set of disjoint intervals \( [ a , b ) \), in increasing order
std::vector< int > intervalColoring (const std::vector< std::pair< long, long > > &I)
 the colors, from 0, of the intervals \( [ a , b ) \), the fewest possible
std::vector< double > towers (std::vector< double > k, double d)
 the fewest towers such that each house is within \( d \) of one (the torri() of the book)
std::pair< long, std::vector< std::size_t > > knapsack (const std::vector< long > &p, const std::vector< long > &v, long C)
 the best profit and a set of objects, by places, of the 0-1 knapsack
long knapsackMemo (const std::vector< long > &p, const std::vector< long > &v, long C, long *solved=nullptr)
 the best profit by memoization in a hash table (the zaino() of the book); the number of subproblems solved goes to *solved, if given
long zaino (const std::vector< long > &p, const std::vector< long > &v, long C, long *solved=nullptr)
 knapsackMemo() under the name of the book
template<class T>
std::pair< T, std::vector< std::size_t > > rodCutting (const std::vector< T > &price, std::size_t L)
 the largest gain of a rod of length \( L \) cut in pieces of lengths \( 1 , \ldots , m \), \( m = |\mathit{price}| \), \( \mathit{price}[ t - 1 ] \) the price of a piece of length \( t \), and the lengths of the pieces
template<class T, class V>
std::pair< T, std::vector< std::size_t > > unboundedKnapsack (const std::vector< T > &p, const std::vector< V > &v, V C)
 the largest profit of the objects of profits \( p \) and volumes \( v \), each in unlimited supply, in a knapsack of capacity \( C \), and the copies of each
template<class T, class V>
std::optional< T > minValueExactWeight (const std::vector< V > &w, const std::vector< T > &v, V W)
 the least value of coins of weights \( w \) and values \( v \), in unlimited supply, weighing exactly \( W \); nothing if there is none
template<class C = std::uint64_t, class V>
C coinChangeWays (const std::vector< V > &coins, V T)
 the number of multisets of the coins of sum \( T \), each coin in unlimited supply; equal values in coins count as distinct kinds
template<class C = std::uint64_t, class V>
C subsetSumCount (const std::vector< V > &A, V k)
 the number of subsets of the places of \( A \) whose items sum to \( k \)
int minimumSquares (std::int64_t n)
 the fewest squares of positive integers summing to \( n \)
template<class T>
std::pair< T, std::vector< std::size_t > > linearPartition (const std::vector< T > &A, std::size_t k)
 the least largest sum of a part over the splits of \( A \) in \( k \) nonempty contiguous parts, and the starts of the parts after the first one
template<std::integral T>
T painterPartition (const std::vector< T > &A, std::size_t k)
 the least largest sum of a part over the splits of \( A \) in at most \( k \) contiguous parts; 0 for \( A \) empty
template<class T>
OptimalSearchTree< T > optimalSearchTree (const std::vector< T > &p, const std::vector< T > &q)
 the optimal binary search tree of the keys of weights \( p \) and of the gaps of weights \( q \)
template<class T>
OptimalSearchTree< T > optimalSearchTree (const std::vector< T > &p)
 the tree of optimalSearchTree() above, with the gaps of weight 0
template<class T>
T trappingRainWater (const std::vector< T > &h)
 the water held by the columns of heights \( h \), no walls outside
template<std::integral T>
std::vector< T > largestDivisibleSubset (std::vector< T > A)
 a largest subset of \( A \) in which of any two items one divides the other, sorted
template<class T>
T maxSumIncreasingSubsequence (const std::vector< T > &A)
 the largest sum of a strictly increasing subsequence of \( A \), 0 for the empty one
template<class T, class Less>
std::vector< std::size_t > longestChainSubsequence (const std::vector< T > &S, Less less)
 the places of a longest subsequence of \( S \) each item of which precedes the next by less, a strict partial order
template<class T, class Hash = std::hash< T >>
std::pair< std::size_t, std::size_t > longestDistinctSegment (const std::vector< T > &A)
 the start and the length of the first longest segment of \( A \) with no value repeated
template<class T>
std::vector< std::size_t > shortestJobFirst (const std::vector< T > &t)
 the order of the programs, by increasing duration
template<class T>
T totalCompletion (const std::vector< T > &t, const std::vector< std::size_t > &A)
 the sum of the times of completion of the programs in the order \( A \), \( \sum_k ( t_{A[ 0 ]} + \cdots + t_{A[ k ]} ) \)
template<class T, class W>
std::vector< std::size_t > smithOrder (const std::vector< T > &t, const std::vector< W > &w)
 the order of the programs of times \( t \) and weights \( w \) of least weighted sum of the times of completion, by increasing \( t / w \) (Smith's rule)
template<class T, class W>
auto weightedCompletion (const std::vector< T > &t, const std::vector< W > &w, const std::vector< std::size_t > &A)
 the sum of \( w_i C_i \) in the order \( A \), \( C_i \) the time of completion of \( i \)
template<class T>
T maxProfit (const std::vector< T > &prices, std::size_t k)
 the largest gain of at most \( k \) transactions on the prices
template<class T>
std::optional< T > maxProfitExactly (const std::vector< T > &prices, std::size_t k)
 the largest gain of exactly \( k \) transactions on the prices, nothing if there are fewer than \( 2 k \) days
template<class W>
std::pair< std::vector< std::size_t >, W > maxinterval (const std::vector< WeightedInterval< W > > &I)
 the places of the intervals of a largest independent set, in increasing order, and its weight
const std::vector< int > & affinityCpus (void)
 the processors on which the process may run, in increasing order, as the first call found them: those of its binding, or those that the topology allows where the system does not tell the binding (macOS); empty where hwloc does not give them
unsigned availableCpus (void)
 the number of processors on which the process may run, that of affinityCpus() where it is not empty and std::thread::hardware_concurrency() otherwise (0 if not known)
bool pinThread (unsigned i)
 binds the calling thread to the processor \( i \bmod c \) of affinityCpus(), \( c \) their number; true if the thread is bound, false where the placement does not exist or the system refuses it
int currentCpu (void)
 the processor on which the calling thread runs now, \( -1 \) where it is not known
bool isRunCaller (void)
 true if the running thread is the thread that called a run() of an executor (or a feedbackFarm() [see Farm.h]) which has not returned yet: asked in the call \( f( i ) \) of a worker, it tells whether that worker runs on the caller, e.g., \( f( 0 ) \) on ThreadPool, OpenMPExecutor and Sequential, any index or none on TBBExecutor, none on FastFlowExecutor with \( p > 1 \) (see Long-lived workers and their locks), so that a worker that pins itself to a processor can leave the caller as it found it
template<Executor E, class F, class G>
void parallelInvoke (E &ex, F &&f, G &&g)
 the calls f() and g() in parallel, returning when both have returned
std::pair< std::size_t, std::size_t > blocksOf (std::size_t first, std::size_t last, std::size_t grain=kGrain, std::size_t blocks=kBlocks)
 the blocks of \( [ \mathit{first} , \mathit{last} ) \), with at least \( g \) indices each and at most \( \bar{B} \) of them: their number \( b \), and the size \( s \) of all but the last
template<Executor E, class F>
void parallelForBlocks (E &ex, std::size_t first, std::size_t last, F &&f, std::size_t grain=kGrain, std::size_t blocks=kBlocks)
 the calls f( lo , hi ) on the blocks \( [ \mathit{lo} , \mathit{hi} ) \) of \( [ \mathit{first} , \mathit{last} ) \), in parallel
template<Executor E, class F>
void parallelFor (E &ex, std::size_t first, std::size_t last, F &&f, std::size_t grain=kGrain, std::size_t blocks=kBlocks)
 the calls f( i ) for each \( i \in [ \mathit{first} , \mathit{last} ) \), in parallel
template<Executor E, class T, class F, class Op>
T parallelReduce (E &ex, std::size_t first, std::size_t last, T id, F &&f, Op op, std::size_t grain=kGrain, std::size_t blocks=kBlocks)
 the reduction of \( [ \mathit{first} , \mathit{last} ) \): the results of f( lo , hi ) on the blocks, combined by \( \oplus \) (op) in the order of the blocks, starting from id
template<Executor E, std::random_access_iterator I, std::random_access_iterator O, class T, class Op = std::plus<>>
T parallelInclusiveScan (E &ex, I in, std::size_t n, O out, T init, Op op=Op())
 the inclusive prefixes \( y[ i ] = \mathit{init} \oplus x[ 0 ] \oplus \cdots \oplus x[ i ] \) of the \( n \) items \( x \) from in, written from out, which may be in; the last prefix (init if \( n = 0 \))
template<Executor E, std::random_access_iterator I, std::random_access_iterator O, class T, class Op = std::plus<>>
T parallelExclusiveScan (E &ex, I in, std::size_t n, O out, T init, Op op=Op())
 the exclusive prefixes \( y[ i ] = \mathit{init} \oplus x[ 0 ] \oplus \cdots \oplus x[ i - 1 ] \) of the \( n \) items \( x \) from in, written from out, which may be in; the sum of all of them with init
template<class T, class R, WorkerExecutor E, class S, class O, class W>
void feedbackFarm (E &ex, std::size_t w, S &&start, O &&onResult, W &&work)
 the farm of a master and \( w \) workers with feedback: start( emit ) (or start( emit , w )), then onResult( r , emit ) on each result of work( t ) (or work( t , i ) on the worker \( i \)), until it returns false or no task is left
template<class T, class R, class S, class O, class W>
void feedbackFarm (FastFlowExecutor &ex, std::size_t w, S &&start, O &&onResult, W &&work)
 the farm with feedback of feedbackFarm() above on a farm of FastFlow, with an emitter of its own and \( w \) workers
template<class K, class H = std::hash< K >>
std::size_t ownerOf (const K &k, std::size_t p, const H &h=H())
 the owner of the key \( k \) among \( p \) workers or processes, \( h( k ) \bmod p \) for the hash function \( h \)
template<Executor E, class W, ArcLayout AL>
std::vector< int > bfsDistances (E &ex, const StaticGraph< W, AL > &g, int s, const StaticGraph< W, AL > *gt=nullptr)
 the distances from \( s \) by a visit in breadth that optimizes its direction, \( -1 \) for the nodes not reached; gt the transpose of \( g \) if \( g \) is oriented (nullptr: the visit goes from the top down only)
template<Executor E, class W, ArcLayout AL>
std::vector< int > connectedComponents (E &ex, const StaticGraph< W, AL > &g)
 the least node of the component of each node, an oriented graph taken as unoriented
std::vector< int > randomOrder (int n, unsigned long long seed)
 a random permutation of \( [ 0 , n ) \) from the seed, the same on every machine (the shuffle of Fisher and Yates on a SplitMix64 generator)
template<Executor E, class W>
std::vector< int > parallelKruskal (E &ex, int n, const std::vector< WeightedEdge< W > > &A)
 the places in \( A \) of the edges of the minimum spanning forest that Kruskal gives on the order \( ( w , \mathit{place} ) \), in that order
template<Executor E, class W>
std::vector< int > filterKruskal (E &ex, int n, const std::vector< WeightedEdge< W > > &A)
 the forest of parallelKruskal() above, by filter-Kruskal
template<Executor E>
std::vector< int > spanningForest (E &ex, int n, const std::vector< std::pair< int, int > > &A)
 the places in \( A \) of the edges of the spanning forest of the greedy algorithm in the order of \( A \), increasing
template<Executor E, class W, ArcLayout AL>
std::vector< int > maximalIndependentSet (E &ex, const StaticGraph< W, AL > &g, const std::vector< int > &pi)
 the nodes of the greedy maximal independent set of \( g \) in the order \( \pi \) (the node \( \pi[ 0 ] \) first), increasing
template<Executor E>
std::vector< int > maximalMatching (E &ex, int n, const std::vector< std::pair< int, int > > &A, const std::vector< int > &pi)
 the places in \( A \) of the edges of the greedy maximal matching in the order \( \pi \) of the edges (the edge \( A[ \pi[ 0 ] ] \) first), increasing
template<std::random_access_iterator I, class C = std::less<>>
std::vector< std::size_t > multisequenceSplit (const std::vector< std::pair< I, I > > &R, std::size_t r, C less=C())
 the split of the sorted ranges \( R_1 , \ldots , R_k \) at the rank \( r \) of the stable merge, i.e., the number of items that each range gives to the \( r \) least
template<Executor E, std::random_access_iterator I, std::random_access_iterator O, class C = std::less<>>
O multiwayMerge (E &ex, const std::vector< std::pair< I, I > > &R, O out, C less=C())
 the items of the sorted ranges \( R_1 , \ldots , R_k \) merged into out on the threads of ex, the range of lower index first on equal items; the end of the output
template<Executor E, class T, std::integral I, std::integral P>
void multiply (E &ex, const BasicCsrMatrix< T, I, P > &A, const T *x, T *y)
 the product \( y = A x \) of the sparse matrix \( A \) by rows on the threads of ex
template<Executor E, class T, std::integral I, std::integral P>
std::vector< T > multiply (E &ex, const BasicCsrMatrix< T, I, P > &A, const std::vector< T > &x)
 the product \( A x \) of the sparse matrix \( A \) by rows on the threads of ex, as a new vector
template<Executor E, std::size_t C>
void multiply (E &ex, const SellMatrix< C > &A, const double *x, double *y)
 the product \( y = A x \) of the sparse matrix \( A \) by chunks of \( C \) rows on the threads of ex
template<Executor E, std::size_t C>
std::vector< double > multiply (E &ex, const SellMatrix< C > &A, const std::vector< double > &x)
 the product \( A x \) of the sparse matrix \( A \) by chunks on the threads of ex, as a new vector
template<Executor E, class T>
void gemm (E &ex, std::size_t m, std::size_t n, std::size_t k, T alpha, const T *A, std::size_t lda, const T *B, std::size_t ldb, T beta, T *C, std::size_t ldc)
 \( C \gets \alpha A B + \beta C \) on the threads of ex, for \( A \) of \( m \times k \), \( B \) of \( k \times n \) and \( C \) of \( m \times n \) by rows, as gemm()
template<Executor E, class T>
DenseMatrix< T > multiply (E &ex, const DenseMatrix< T > &A, const DenseMatrix< T > &B)
 the product \( A B \) of two dense matrices on the threads of ex
template<Executor E, Graph G>
std::vector< typename G::Weight > deltaStepping (E &ex, const G &g, int s, typename G::Weight delta)
 the distances from \( s \) by the \( \Delta \)-stepping of Meyer and Sanders, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places
template<Executor E, Graph G>
std::vector< typename G::Weight > rhoStepping (E &ex, const G &g, int s, std::size_t rho=std::size_t(1)<< 20)
 the distances from \( s \) by the \( \rho \)-stepping of Dong, Gu, Sun and Zhang, infinity() for the nodes not reached and for the unused names, in a vector of g.bound() places
template<Executor E, SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void sort (E &ex, Store &&A, C less=C())
 the vector \( A \) sorted by less on the threads of ex, not necessarily stable
template<Executor E, class T, class C = std::less<>>
void sort (E &ex, std::vector< T > &A, C less=C())
 sort() above on a vector
template<Executor E, SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void stableSort (E &ex, Store &&A, C less=C())
 the vector \( A \) sorted by less on the threads of ex, the equal items in their order
template<Executor E, class T, class C = std::less<>>
void stableSort (E &ex, std::vector< T > &A, C less=C())
 stableSort() above on a vector
template<Executor E, SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void learnedSort (E &ex, Store &&A)
 the vector \( A \) of numbers sorted in their natural order on the threads of ex, distributed by the model of the CDF of a sample [see LearnedSort.h] when it fits, as sort( ex , A ) otherwise and for the buckets; not necessarily stable
template<Executor E, VectorKey T>
void learnedSort (E &ex, std::vector< T > &A)
 learnedSort() above on a vector
template<Executor E, SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void learnedStableSort (E &ex, Store &&A)
 the vector \( A \) of numbers sorted as learnedSort( ex , A ) sorts it, the equal items in their order (\( -0 \) and \( +0 \) among them), as stableSort( ex , A )
template<Executor E, VectorKey T>
void learnedStableSort (E &ex, std::vector< T > &A)
 learnedStableSort() above on a vector
template<Executor E, SortRange R, class... P>
requires requires( E & ex , std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { sort( ex , v , std::forward< P >
( p )... ); }
decltype(auto) sort (E &ex, R &&A, P &&... p)
 sort( ex , A ) on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<Executor E, SortRange R, class... P>
requires requires( E & ex , std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { stableSort( ex , v , std::forward
< P >( p )... ); }
decltype(auto) stableSort (E &ex, R &&A, P &&... p)
 stableSort( ex , A ) on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<Executor E, SortRange R, class... P>
requires requires( E & ex , std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { learnedSort( ex , v , std::forward
< P >( p )... ); }
decltype(auto) learnedSort (E &ex, R &&A, P &&... p)
 learnedSort( ex , A ) on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<Executor E, SortRange R, class... P>
requires requires( E & ex , std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { learnedStableSort( ex , v ,
std::forward< P >( p )... ); }
decltype(auto) learnedStableSort (E &ex, R &&A, P &&... p)
 learnedStableSort( ex , A ) on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<Executor E, class S>
std::vector< std::size_t > lcpArray (E &ex, const S &T, const std::vector< std::size_t > &SA)
 the LCP array of \( T \) and of its suffix array \( \mathit{SA} \) on the threads of ex, \( n - 1 \) entries (none if \( n < 2 \))
template<Executor E, class I>
std::vector< I > lcpArrayPhi (E &ex, std::string_view T, const std::vector< I > &SA)
 the LCP array of the text \( T \) of bytes and of its suffix array \( \mathit{SA} \) of indices of the type I, on the threads of ex, the result of lcpArrayPhi( T , SA ) [see SuffixSorting.h]
template<Executor E, SpeculativeStep S>
void speculativeFor (E &ex, S &step, std::size_t s, std::size_t e, std::size_t g=50, SpeculativeCounts *c=nullptr)
 the iterations \( [ s , e ) \) of step by deterministic reservations, with the result of the sequential loop; the rounds of at most \( r_{\mathrm{max}} = \lfloor ( e - s ) / g \rfloor + 1 \) iterations; its work in *c, if given
constexpr std::uint64_t packFG (std::uint32_t f, std::uint32_t g) noexcept
 the key of 64 bits of the pair \( ( f , g ) \), \( f \) in the high half and the complement of \( g \) in the low one, so that the keys under std::less come by least \( f \) and then largest \( g \), the order of a BucketQueue
constexpr std::uint32_t keyF (std::uint64_t k) noexcept
 the \( f \) of a key of packFG()
constexpr std::uint32_t keyG (std::uint64_t k) noexcept
 the \( g \) of a key of packFG()
template<class T, class C = std::less<>>
std::vector< T > kWayMerge (const std::vector< std::vector< T > > &R, C less=C())
 the items of the sorted vectors of \( R \), merged through a tree of losers
template<class I, class O, class C = std::less<>>
O multiwayMerge (const std::vector< std::pair< I, I > > &R, O out, C less=C())
 the items of the sorted ranges \( R[ i ] = [ \mathit{first} , \mathit{last} ) \) merged into out, the range of lower index first on equal items; the end of the output
template<Queue Q>
void extractPositive (Q &q, Q &out)
 moves the positive items of \( q \), in their order, to the back of out, leaving \( q \) empty
template<Queue Q>
void copyPositive (Q &q, Q &out)
 copies the positive items of \( q \), in their order, to the back of out, leaving \( q \) as it was
template<class T, class F>
long binarySearch (const std::vector< T > &A, const T &v, F &&trace)
 the place of \( v \) in the sorted \( A \), or -1; trace( i , j , m ) on each call that examines \( A[ m ] \)
template<class T>
long binarySearch (const std::vector< T > &A, const T &v)
 the search of binarySearch() above, with no trace
template<class T>
BinaryTree< T > * decisionTree (const std::vector< T > &A)
 the decision tree of binarySearch() on \( A \), nil if \( A \) is empty; the caller owns it
template<class T, class C = std::less<>>
std::size_t lowerBound (const std::vector< T > &A, const T &v, std::size_t lo, std::size_t hi, C less=C())
 the first place in \( [ \mathit{lo} , \mathit{hi} ) \) of an item not smaller than \( v \), \( \mathit{hi} \) if none
template<class T, class C = std::less<>>
std::size_t lowerBound (const std::vector< T > &A, const T &v, C less=C())
 the place of lowerBound() above in the whole of \( A \), i.e., lowerBound( A , v , 0 , n )
template<class T, class C = std::less<>>
std::size_t upperBound (const std::vector< T > &A, const T &v, C less=C())
 the first place of an item larger than \( v \), \( n \) if none
template<class T, class C = std::less<>>
std::size_t gallopSearch (const std::vector< T > &A, const T &v, C less=C())
 the first place \( h \) of an item not smaller than \( v \), found by looking at the places \( 0 , 1 , 3 , 7 , \ldots \) and then by a binary search that leaves out the last place looked at, at most \( 2 \lceil \log_2 ( h + 1 ) \rceil \) comparisons for \( h \ge 1 \) and 1 for \( h = 0 \)
template<class T, class F>
long interpolationSearch (const std::vector< T > &A, const T &v, F &&trace)
 the place of \( v \) in the sorted \( A \), or -1; trace( i , j , m ) on each probe (the ricercaInterpolata() of the book)
template<class T>
long interpolationSearch (const std::vector< T > &A, const T &v)
 the search of interpolationSearch() above, with no trace
template<class T>
long fibonacciSearch (const std::vector< T > &A, const T &v, long *cmp=nullptr)
 the Fibonacci search of \( v \) in the sorted \( A \): its place, or -1; the comparisons go to *cmp, if given, the test of the line 9 among them
template<class T>
long uniformBinarySearch (const std::vector< T > &A, const T &v, long *cmp=nullptr)
 the uniform binary search of \( v \) in the sorted \( A \): its place, or -1; the comparisons go to *cmp, if given
template<class T, class C = std::less<>>
std::size_t findPeak (const std::vector< T > &A, C less=C())
 the place \( r \) of an item of \( A \) not smaller than its neighbors, by a binary search; \( \lceil \log_2 n \rceil \) comparisons
template<class T, class C = std::less<>>
std::size_t localMinimum (const std::vector< T > &A, C less=C())
 the place \( r \) of an item of \( A \) not larger than its neighbors, by a binary search; \( \lceil \log_2 n \rceil \) comparisons
template<class T, class C = std::less<>>
BinaryTree< T > * localMinimum (BinaryTree< T > *t, C less=C())
 a node of the tree \( t \) not larger than its children and, if it is not \( t \), smaller than its parent: from \( t \) down to the first child smaller than the current node, the left one first; \( O( h ) \) comparisons
template<class T, class C = std::less<>>
std::size_t argmin (const std::vector< T > &A, std::size_t start, std::size_t end, C less=C())
 the place of the first minimum of the range \( A[ \mathit{start} .. \mathit{end} ] \)
template<std::ranges::random_access_range R, class C = std::less<>>
requires ( ! std::is_same_v< std::remove_cvref_t< R > , std::vector< std::ranges::range_value_t< R > > > )
std::size_t argmin (const R &A, std::size_t start, std::size_t end, C less=C())
 argmin() above on any random-access range \( A \) other than a vector (a span, the view of a deque), the ranks of the selection sort on it
template<class T, class C = std::less<>>
const T & min (const std::vector< T > &A, C less=C())
 the minimum of a vector that is not empty, \( n - 1 \) comparisons
template<class T, class C = std::less<>>
std::pair< T, T > minMax (const std::vector< T > &A, C less=C())
 the minimum and the maximum together, by pairs: the two items of a pair are compared, the smaller with the minimum and the larger with the maximum, \( \lceil 3 n / 2 \rceil - 2 \) comparisons instead of the \( 2 ( n - 1 ) \) of two searches
template<class T, class C = std::less<>>
std::pair< T, T > minMaxDivide (const std::vector< T > &A, C less=C())
 the pair of minMax() by divide et impera: the halves solved recursively and their minima and maxima compared, \( T( 2 ) = 1 \), \( T( n ) = 2 T( n / 2 ) + 2 \), i.e., \( 3 n / 2 - 2 \) comparisons for \( n \) a power of 2
template<std::integral I, class P>
I exponentialSearch (P &&p, I lo=I(0))
 the least \( i \ge \mathit{lo} \) with \( p( i ) \), \( p \) false and then true from \( \mathit{lo} \); \( O( \log( i - \mathit{lo} + 1 ) ) \) evaluations of \( p \)
template<class G, class P>
std::size_t unboundedSearch (G &&get, P &&pred)
 the first place \( i \) where get( i ), which gives an optional item, empty past the end of the sequence, gives no item or an item \( x \) with pred( x ); \( O( \log i ) \) calls of get()
template<std::unsigned_integral U>
U integerSqrt (U n)
 the largest \( r \) with \( r^2 \le n \), by a binary search with no overflow; \( w / 2 \) steps for \( w \) bits, none for a bool, which is its own root
template<std::unsigned_integral U>
bool isPerfectSquare (U n)
 true if \( n = k^2 \) for an integer \( k \), i.e., if the square of integerSqrt( n ) is \( n \)
template<std::random_access_iterator It, class C = std::less<>>
void nthElement (It first, It nth, It last, C less=C())
 the item of its rank put in nth, in \( [ \mathit{first} , \mathit{last} ) \) by less(), the items before it not larger and those after it not smaller
template<class T, class C = std::less<>>
T nthElement (std::vector< T > &A, std::size_t k, C less=C())
 the item of rank \( k \) (from 0) of \( A \), which is rearranged by nthElement() above
template<class T, class Compare = std::less< T >>
std::vector< std::size_t > cartesianTree (const std::vector< T > &A, Compare less={})
 the parent of each item of \( A \) in its Cartesian tree, the root (the leftmost minimum) having \( n \); equal items go to the right
template<class T, class R = std::mt19937>
T selection (std::vector< T > &A, std::size_t k, R *rng=nullptr)
 the item of rank \( k \), \( 1 \le k \le n \), of \( A \) (the selezione() of the book); with a generator the pivots are random, otherwise the first item of the part
template<class T>
T medianOfMedians (std::vector< T > &A, std::size_t k)
 the item of rank \( k \), \( 1 \le k \le n \), in linear time in the worst case
template<class T, class C = std::less<>>
std::size_t rotatedMinimum (const std::vector< T > &A, C less=C())
 the place of the minimum of \( A \), a strictly increasing vector rotated right by that number of places; \( O( \log n ) \)
template<class T>
requires ( std::is_arithmetic_v< T > && ! std::is_same_v< T , bool > )
std::size_t closestValue (const std::vector< T > &A, const T &x)
 the first place of an item of the sorted \( A \) at the least distance from \( x \), the smaller item on ties; \( O( \log n ) \)
template<class T, class S>
std::optional< std::pair< std::size_t, std::size_t > > pairWithSum (const std::vector< T > &A, const S &x)
 two places \( i < j \) of the sorted \( A \) with \( A[ i ] + A[ j ] = x \), the sum computed in the type S, or nothing; \( O( n ) \)
template<class T, class C = std::less<>>
T kthOfTwoSorted (const std::vector< T > &X, const std::vector< T > &Y, std::size_t k, C less=C())
 the item of rank \( k \), from 0, of the sorted \( X \) and \( Y \) together; \( O( \log \min( m , n ) ) \)
template<class T, class C = std::less<>>
std::size_t branchlessLowerBound (const std::vector< T > &A, const T &v, C less=C())
 the first place of an item not smaller than \( v \) in the sorted \( A \), \( n \) if none, by the binary search with no branch
template<class T>
void rotateArray (std::span< T > a, std::size_t r)
 the item \( a[ i ] \) moved to \( a[ ( i + r ) \bmod n ] \), for every \( i \), by three reversals: \( n \) swaps at most and \( O( 1 ) \) space
template<IndexedList L>
void rotate (L &l, std::size_t r)
 the item of rank \( i \) of \( l \) moved to the rank \( ( i + r ) \bmod n \): the rotate() of the list if it has one, the cycles of the permutation otherwise, \( n + \gcd( n , r ) \) moves
template<class T, bool P, class C = std::less<>>
void listSort (List< T, P > &L, C less=C())
 the list \( L \) sorted by relinking its cells, stable
template<class T, class F>
std::pair< std::size_t, std::size_t > dutchNationalFlag (std::vector< T > &A, F &&color, std::size_t *swaps=nullptr)
 the items of \( A \) by color( x ), 0 then 1 then 2, with \( n \) reads of the colors and at most \( n \) swaps, counted in *swaps if it is given; \( ( i , j ) \) with \( A[ 0 .. i ) \) of color 0, \( A[ i .. j ) \) of color 1 and \( A[ j .. n ) \) of color 2
template<class T, class C = std::less<>>
void wiggleSort (std::vector< T > &A, C less=C())
 \( A[ 0 ] \le A[ 1 ] \ge A[ 2 ] \le \cdots \), by swaps of neighbors; \( n - 1 \) comparisons
template<class T, class C = std::less<>>
void sortKSorted (std::vector< T > &A, std::size_t k, C less=C())
 \( A \) sorted, each item at most \( k \) places away from its place in the sorted order, by a heap of \( k + 1 \) items; \( O( n \log k ) \)
template<class T, class W = T>
requires std::is_arithmetic_v< T >
std::pair< std::size_t, W > minimumSwapSort (const std::vector< T > &A)
 the fewest swaps that sort \( A \), and the least total cost of the swaps that sort it, a swap costing the sum of its two items, computed in the type W (the least when no item is negative; with two items of negative sum no least cost exists); \( O( n \log n ) \)
template<Sequence S>
long search (const S &s, const typename S::Item &v)
 the place of \( v \) counted from 0, or \( -( n + 1 ) \)
template<Sequence S>
long searchOrdered (const S &s, const typename S::Item &v)
 the place of \( v \) in the sorted \( s \), or \( -c \), \( c \) the comparisons made, -1 on the empty \( s \), so that a miss is always negative
template<Sequence S>
std::pair< typename S::Pos, bool > lowerBound (const S &s, const typename S::Item &v)
 the position of the first item not smaller than \( v \) in the sorted \( s \), or \( \mathit{pos}_n \), and whether it is \( v \): insert() of \( v \) there keeps \( s \) sorted
template<Sequence S>
S sublist (const S &s, typename S::Pos p, typename S::Pos q)
 the sequence of the items of \( s \) from the position \( p \) to the position \( q \), both included, empty if \( p \) is \( \mathit{pos}_n \)
template<Sequence S>
Order order (const S &s)
 the order of \( s \), the most specific that holds
template<Sequence S>
void bubbleSort (S &s)
 the bubble sort: at most \( n \) passes of swaps of adjacent items out of order, stopped at the first pass without swaps
template<Sequence S>
S mergeSorted (const S &a, const S &b)
 the merge of the sorted \( a \) and \( b \), the repeated items kept, those of \( a \) first among equals
template<Sequence S>
void naturalMergeSort (S &s, long *passes=nullptr)
 the natural merge sort; the number of passes goes to *passes, if given
template<Sequence S>
void removeDuplicates (S &s)
 keeps the first copy of each item, in \( O( n^2 ) \) comparisons
template<Sequence S>
SequenceRange< S > range (const S &s)
 the range of the items of \( s \)
template<std::unsigned_integral U>
constexpr void xorSwap (U &a, U &b)
 \( a \) and \( b \) swapped by three exclusive ors and no third variable (exercise 3.19 of Morin's book)
double bloomFalsePositive (double m, double n, int r)
 the probability \( ( 1 - ( 1 - 1 / m )^{r n} )^r \) of a false positive of a filter of \( m \) bits and \( r \) hashes after \( n \) insertions, 0 for \( n = 0 \)
int bloomBestHashes (double m, double n)
 the number of hashes, the floor or the ceiling of \( ( m / n ) \ln 2 \), of the least false positives; past the largest int (\( m / n \) above about \( 3 \cdot 10^9 \)) the floor is cut to the largest int less one
double bloomLowerBound (double n, double epsilon)
 \( n \log_2( 1 / \epsilon ) \), the bits that any filter of \( n \) keys with false positives \( \epsilon \) needs
double bloomBits (double n, double epsilon)
 \( n \log_2( 1 / \epsilon ) / \ln 2 \), the bits of a filter of Bloom with the best number of hashes and false positives \( \epsilon \)
std::pair< double, double > compressedBloom (double bitsPerKey, int r)
 the false positives and the bits per key after an arithmetic coding, \( m / n \) times the entropy of a bit, of a filter of \( m / n = \mathit{bitsPerKey} \) bits per key and \( r \) hashes
template<class T, class H = std::hash< T >>
std::pair< std::vector< T >, std::vector< T > > bloomIntersection (const std::vector< T > &A, const std::vector< T > &B, std::size_t mA)
 the intersection of \( A \) and \( B \) by a filter of \( A \) of \( m_A \) bits: the keys \( Q \) of \( B \) that the filter accepts, and the keys of \( A \) in \( Q \), in the order of \( B \)
BoolSet setUnion (const BoolSet &A, const BoolSet &B)
 the union, a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)
BoolSet setIntersection (const BoolSet &A, const BoolSet &B)
 the intersection, a set of dimension \( \min( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)
BoolSet setDifference (const BoolSet &A, const BoolSet &B)
 the difference, a set of dimension A.dim()
BoolSet setSymmetricDifference (const BoolSet &A, const BoolSet &B)
 the symmetric difference, the items in exactly one of \( A \) and \( B \), a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)
template<class T>
ListSet< T > setUnion (const ListSet< T > &A, const ListSet< T > &B)
 the union: \( C \) starts as \( B \) and gets the items of \( A \) not in \( B \), inserted without looking for them in \( C \), \( O( n m ) \) time (exercise 8.2)
template<class T>
ListSet< T > setIntersection (const ListSet< T > &A, const ListSet< T > &B)
 the intersection, \( O( n m ) \) time (exercise 8.1)
template<class T>
ListSet< T > setDifference (const ListSet< T > &A, const ListSet< T > &B)
 the difference, \( O( n m ) \) time (the procedure of section 8.2)
template<class T>
ListSet< T > setSymmetricDifference (const ListSet< T > &A, const ListSet< T > &B)
 the symmetric difference, \( O( n m ) \) time (exercise 8.5)
RoaringBitmap setUnion (const RoaringBitmap &A, const RoaringBitmap &B)
 the union, by the merge of the containers
RoaringBitmap setIntersection (const RoaringBitmap &A, const RoaringBitmap &B)
 the intersection, by the merge of the containers
RoaringBitmap setDifference (const RoaringBitmap &A, const RoaringBitmap &B)
 the difference, by the merge of the containers
RoaringBitmap setSymmetricDifference (const RoaringBitmap &A, const RoaringBitmap &B)
 the symmetric difference, by the merge of the containers
template<IterableSet S>
S setUnion (const S &A, const S &B)
 the union: a copy of \( A \), plus the items of \( B \)
template<IterableSet S>
S setIntersection (const S &A, const S &B)
 the intersection: a copy of the smaller set \( X \), less its items not in the other one, \( Y \)
template<IterableSet S>
S setDifference (const S &A, const S &B)
 the difference: a copy of \( A \), less its items in \( B \)
template<IterableSet S>
S setSymmetricDifference (const S &A, const S &B)
 the symmetric difference: \( A \setminus B \), plus the items of \( B \) not in \( A \)
template<class T, class C = std::less<>>
std::vector< T > intersectMerge (const std::vector< T > &A, const std::vector< T > &B, C less=C())
 the items common to \( A \) and \( B \), by merging
template<class T, class C = std::less<>>
std::vector< T > intersectBinarySearch (const std::vector< T > &A, const std::vector< T > &B, C less=C())
 the items common to \( A \) and \( B \), by a binary search in the longer list of each item of the shorter one
template<class T, class C = std::less<>>
std::vector< T > intersectMutualPartition (const std::vector< T > &A, const std::vector< T > &B, C less=C())
 the items common to \( A \) and \( B \), by mutual partitions
template<class T, class C = std::less<>>
std::vector< T > intersectDoubling (const std::vector< T > &A, const std::vector< T > &B, C less=C())
 the items common to \( A \) and \( B \), by doubling searches
template<class T, class C = std::less<>>
std::vector< T > intersectTwoLevel (const std::vector< T > &A, const std::vector< T > &B, std::size_t L, C less=C())
 the items common to \( A \) and \( B \), by the first items of the blocks of \( L \) items of \( A \)
template<class T>
void twoLevelHeaders (const DiskFile< T > &A, std::size_t L, DiskFile< T > &H)
 the first item of each block of \( L \) items of \( A \), into \( H \), by one scan
template<class T, class C = std::less<>>
void intersectMergeExternal (const DiskFile< T > &A, const DiskFile< T > &B, DiskFile< T > &out, C less=C())
 the items common to the sorted files \( A \) and \( B \) into out, by merging, \( \lceil n / B \rceil + \lceil m / B \rceil \) reads
template<class T, class C = std::less<>>
void intersectTwoLevelExternal (const DiskFile< T > &A, const DiskFile< T > &H, std::size_t L, const DiskFile< T > &B, DiskFile< T > &out, C less=C())
 the items common to the sorted files \( A \) and \( B \) into out, by the headers \( H \) of the blocks of \( L \) items of \( A \) [see twoLevelHeaders()]
template<class T>
SortedListSet< T > merge (const SortedListSet< T > &A, const SortedListSet< T > &B, bool a, bool b, bool both)
 the merge of the sorted lists of \( A \) and \( B \): an item of \( A \) only, of \( B \) only or of both goes into the result if a, b or both say so; \( O( n + m ) \) time
template<class T>
SortedListSet< T > setUnion (const SortedListSet< T > &A, const SortedListSet< T > &B)
 the union, \( O( n + m ) \) time (exercise 8.3)
template<class T>
SortedListSet< T > setIntersection (const SortedListSet< T > &A, const SortedListSet< T > &B)
 the intersection, \( O( n + m ) \) time (the procedure of section 8.3)
template<class T>
SortedListSet< T > setDifference (const SortedListSet< T > &A, const SortedListSet< T > &B)
 the difference, \( O( n + m ) \) time (exercise 8.4)
template<class T>
SortedListSet< T > setSymmetricDifference (const SortedListSet< T > &A, const SortedListSet< T > &B)
 the symmetric difference, \( O( n + m ) \) time (exercise 8.5)
template<class T>
std::size_t intersect (const T *a, std::size_t n, const T *b, std::size_t m, T *out)
 the items common to \( a[ 0 .. n ) \) and \( b[ 0 .. m ) \), written to out, and their number
template<class T>
std::vector< T > intersect (const std::vector< T > &A, const std::vector< T > &B)
 the items common to \( A \) and \( B \), by intersect() above on their data
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void countingSort (Store &&A, std::size_t k)
 \( A \), of integers in \( [ 0 , k ) \), in increasing order, by counting the occurrences of each key
template<class T>
void countingSort (std::vector< T > &A, std::size_t k)
 countingSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { countingSort( v , std::forward< P >( p )... ); }
decltype(auto) countingSort (R &&A, P &&... p)
 countingSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void dualPivotQuickSort (Store &&A, C less=C())
 the dual-pivot quicksort
template<class T, class C = std::less<>>
void dualPivotQuickSort (std::vector< T > &A, C less=C())
 dualPivotQuickSort() above on a vector
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void threeWayQuickSort (Store &&A, C less=C())
 the quicksort with the three-way partition of Ferragina's book
template<class T, class C = std::less<>>
void threeWayQuickSort (std::vector< T > &A, C less=C())
 threeWayQuickSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { dualPivotQuickSort( v , std::forward< P >
( p )... ); }
decltype(auto) dualPivotQuickSort (R &&A, P &&... p)
 dualPivotQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { threeWayQuickSort( v , std::forward< P >( p )... ); }
decltype(auto) threeWayQuickSort (R &&A, P &&... p)
 threeWayQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void bubbleSort (Store &&A, C less=C())
 the bubble sort, each pass ending at the last swap of the previous one
template<class T, class C = std::less<>>
void bubbleSort (std::vector< T > &A, C less=C())
 bubbleSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void cocktailShakerSort (Store &&A, C less=C())
 the bubble sort with passes in both directions
template<class T, class C = std::less<>>
void cocktailShakerSort (std::vector< T > &A, C less=C())
 cocktailShakerSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void oddEvenSort (Store &&A, C less=C(), std::size_t *rounds=nullptr)
 the odd-even transposition sort; the rounds go to *rounds, if given
template<class T, class C = std::less<>>
void oddEvenSort (std::vector< T > &A, C less=C(), std::size_t *rounds=nullptr)
 oddEvenSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void combSort (Store &&A, C less=C())
 the comb sort, the gap shrinking by 1.3
template<class T, class C = std::less<>>
void combSort (std::vector< T > &A, C less=C())
 combSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void gnomeSort (Store &&A, C less=C())
 the gnome sort
template<class T, class C = std::less<>>
void gnomeSort (std::vector< T > &A, C less=C())
 gnomeSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { bubbleSort( v , std::forward< P >( p )... ); }
decltype(auto) bubbleSort (R &&A, P &&... p)
 bubbleSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { cocktailShakerSort( v , std::forward< P >
( p )... ); }
decltype(auto) cocktailShakerSort (R &&A, P &&... p)
 cocktailShakerSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { oddEvenSort( v , std::forward< P >( p )... ); }
decltype(auto) oddEvenSort (R &&A, P &&... p)
 oddEvenSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { combSort( v , std::forward< P >( p )... ); }
decltype(auto) combSort (R &&A, P &&... p)
 combSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { gnomeSort( v , std::forward< P >( p )... ); }
decltype(auto) gnomeSort (R &&A, P &&... p)
 gnomeSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<class T, class C = std::less<>>
std::vector< std::vector< T > > replacementSelection (const std::vector< T > &input, std::size_t M, C less=C())
 the runs of the input made by replacement selection with \( M \) items in memory
template<class T, class C = std::less<>>
std::vector< T > polyphaseMerge (std::vector< std::vector< T > > runs, std::size_t tapes, C less=C(), std::size_t *phases=nullptr)
 the polyphase merge of the runs on \( T \) tapes; the phases go to *phases, if given
template<class T, class C = std::less<>>
std::vector< T > externalSort (const std::vector< T > &input, std::size_t M, std::size_t tapes, C less=C())
 the sort of input by replacementSelection() and then polyphaseMerge()
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void maxHeapRestore (Store &&A, std::size_t i, std::size_t dim, C less=C())
 \( A[ i ] \) moved down in the heap \( A[ 0 .. \mathit{dim} - 1 ] \), with the order less, \( O( 1 ) \) extra space
template<class T, class C = std::less<>>
void maxHeapRestore (std::vector< T > &A, std::size_t i, std::size_t dim, C less=C())
 maxHeapRestore() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void heapBuild (Store &&A, C less=C())
 \( A \) made a max-heap, \( O( n ) \) time
template<class T, class C = std::less<>>
void heapBuild (std::vector< T > &A, C less=C())
 heapBuild() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void heapsort (Store &&A, C less=C())
 \( A \) in increasing order, \( O( n \log n ) \) time
template<class T, class C = std::less<>>
void heapsort (std::vector< T > &A, C less=C())
 heapsort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
bool isMaxHeap (Store &&A, std::size_t dim, C less=C())
 true if \( A[ 0 .. \mathit{dim} - 1 ] \) is a max-heap, i.e., if no item is larger than its parent
template<class T, class C = std::less<>>
bool isMaxHeap (const std::vector< T > &A, std::size_t dim, C less=C())
 isMaxHeap() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { heapsort( v , std::forward< P >( p )... ); }
decltype(auto) heapsort (R &&A, P &&... p)
 heapsort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void insertionSort (Store &&A, std::size_t lo, std::size_t hi, C less=C())
 the insertion sort of \( A[ \mathit{lo} .. \mathit{hi} - 1 ] \)
template<class T, class C = std::less<>>
void insertionSort (std::vector< T > &A, std::size_t lo, std::size_t hi, C less=C())
 insertionSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void insertionSortSentinel (Store &&A, C less=C())
 the insertion sort with a sentinel: the minimum first goes to \( A[ 0 ] \), with \( n - 1 \) comparisons and one swap, so that the inner loop of each insertion needs no test on the index, since it stops at \( A[ 0 ] \) at the latest
template<class T, class C = std::less<>>
void insertionSortSentinel (std::vector< T > &A, C less=C())
 insertionSortSentinel() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void insertionSort (Store &&A, C less=C())
 \( A \) in increasing order by less, the insertion sort of the whole vector
template<class T, class C = std::less<>>
void insertionSort (std::vector< T > &A, C less=C())
 insertionSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { insertionSort( v , std::forward< P >( p )... ); }
decltype(auto) insertionSort (R &&A, P &&... p)
 insertionSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { insertionSortSentinel( v , std::forward< P >
( p )... ); }
decltype(auto) insertionSortSentinel (R &&A, P &&... p)
 insertionSortSentinel() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \(A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void binaryInsertionSort (Store &&A, C less=C())
 the binary insertion sort
template<class T, class C = std::less<>>
void binaryInsertionSort (std::vector< T > &A, C less=C())
 binaryInsertionSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void listInsertionSort (Store &&A, C less=C(), std::size_t *moves=nullptr)
 the list insertion sort; the moves of the items go to *moves, if given
template<class T, class C = std::less<>>
void listInsertionSort (std::vector< T > &A, C less=C(), std::size_t *moves=nullptr)
 listInsertionSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void addressCalculationSort (Store &&A, std::size_t M=0)
 the address calculation sort of numbers into \( M \) lists, \( M = \lfloor n / 4 \rfloor + 1 \) if \( M \) is 0; with an infinite range (an infinity, or a span beyond a double) all the items go to one list, an insertion sort
template<class T>
void addressCalculationSort (std::vector< T > &A, std::size_t M=0)
 addressCalculationSort() above on a vector
template<RankStore Store, RadixKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void radixExchangeSort (Store &&A)
 the radix exchange sort
template<RadixKey T>
void radixExchangeSort (std::vector< T > &A)
 radixExchangeSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void tournamentSort (Store &&A, C less=C())
 the tournament sort
template<class T, class C = std::less<>>
void tournamentSort (std::vector< T > &A, C less=C())
 tournamentSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void mergeInsertionSort (Store &&A, C less=C())
 the merge insertion sort of Ford and Johnson
template<class T, class C = std::less<>>
void mergeInsertionSort (std::vector< T > &A, C less=C())
 mergeInsertionSort() above on a vector
long fordJohnsonBound (std::size_t n)
 the worst case of the comparisons of mergeInsertionSort() on \( n \) items, \( \sum_{k=1}^{n} \lceil \log_2 ( 3 k / 4 ) \rceil \)
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { binaryInsertionSort( v , std::forward< P >
( p )... ); }
decltype(auto) binaryInsertionSort (R &&A, P &&... p)
 binaryInsertionSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { listInsertionSort( v , std::forward< P >( p )... ); }
decltype(auto) listInsertionSort (R &&A, P &&... p)
 listInsertionSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { addressCalculationSort( v , std::forward< P >
( p )... ); }
decltype(auto) addressCalculationSort (R &&A, P &&... p)
 addressCalculationSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \(A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { radixExchangeSort( v , std::forward< P >( p )... ); }
decltype(auto) radixExchangeSort (R &&A, P &&... p)
 radixExchangeSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { tournamentSort( v , std::forward< P >( p )... ); }
decltype(auto) tournamentSort (R &&A, P &&... p)
 tournamentSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { mergeInsertionSort( v , std::forward< P >
( p )... ); }
decltype(auto) mergeInsertionSort (R &&A, P &&... p)
 mergeInsertionSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void learnedSort (Store &&A)
 the learned sort of \( A \) in the natural order (the total order of IEEE 754 for the floating point numbers): the buckets of a model of the CDF of a sample, each sorted by vectorQuickSort(), and sampleSort() when the sample shows a distribution that the model does not fit; not stable
template<VectorKey T>
void learnedSort (std::vector< T > &A)
 learnedSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { learnedSort( v , std::forward< P >( p )... ); }
decltype(auto) learnedSort (R &&A, P &&... p)
 learnedSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void mergeParts (Store &&A, std::vector< T > &B, std::size_t start, std::size_t mid, std::size_t end, C less=C(), long long *inv=nullptr)
 \( A[ \mathit{start} .. \mathit{mid} ] \) and \( A[ \mathit{mid} + 1 .. \mathit{end} ] \), sorted, merged through \( B \) (the Merge() of the book); the inversions met are added to *inv, if given
template<class T, class C = std::less<>>
void mergeParts (std::vector< T > &A, std::vector< T > &B, std::size_t start, std::size_t mid, std::size_t end, C less=C(), long long *inv=nullptr)
 mergeParts() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void mergeSortRec (Store &&A, std::vector< T > &B, std::size_t start, std::size_t end, std::size_t cutoff, C less=C(), long long *inv=nullptr)
 the sort of \( A[ \mathit{start} .. \mathit{end} ] \) (the MergeSort() of the book), insertionSort() on at most \( \mathit{cutoff} \) items; with \( \mathit{cutoff} > 1 \) also no merge of two parts already in order, i.e., with \( A[ \mathit{mid} ] \le A[ \mathit{mid} + 1 ] \), which makes the sort of a sorted vector take \( n - 1 \) comparisons
template<class T, class C = std::less<>>
void mergeSortRec (std::vector< T > &A, std::vector< T > &B, std::size_t start, std::size_t end, std::size_t cutoff, C less=C(), long long *inv=nullptr)
 mergeSortRec() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void mergeSort (Store &&A, std::size_t cutoff=1, C less=C())
 \( A \) in increasing order, stable; the parts of at most \( \mathit{cutoff} \) items by insertionSort() (1 is the book)
template<class T, class C = std::less<>>
void mergeSort (std::vector< T > &A, std::size_t cutoff=1, C less=C())
 mergeSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void mergeSortBottomUp (Store &&A, C less=C())
 the iterative Merge Sort: the runs of length \( w \) are merged in pairs, for \( w = 1 , 2 , 4 , \ldots \)
template<class T, class C = std::less<>>
void mergeSortBottomUp (std::vector< T > &A, C less=C())
 mergeSortBottomUp() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
long long countInversions (Store &&A, C less=C())
 the number of inversions of \( A \), the pairs \( i < j \) with \( A[ j ] < A[ i ] \), by Merge Sort, \( O( n \log n ) \); \( A \) ends sorted
template<class T, class C = std::less<>>
long long countInversions (std::vector< T > &A, C less=C())
 countInversions() above on a vector
template<class T, class C = std::less<>>
void mergeSort (List< T > &L, C less=C())
 Merge Sort of a list with pointers, through the operations of the SEQUENCE alone: the items are copied from a list to another, once per level, since the abstract data type moves no cells.
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { mergeSort( v , std::forward< P >( p )... ); }
decltype(auto) mergeSort (R &&A, P &&... p)
 mergeSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { mergeSortBottomUp( v , std::forward< P >( p )... ); }
decltype(auto) mergeSortBottomUp (R &&A, P &&... p)
 mergeSortBottomUp() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { countInversions( v , std::forward< P >( p )... ); }
decltype(auto) countInversions (R &&A, P &&... p)
 countInversions() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<StringStore Store>
void multikeyQuickSort (Store &&A)
 the multikey quicksort of strings
void multikeyQuickSort (std::vector< std::string > &A)
 multikeyQuickSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { multikeyQuickSort( v , std::forward< P >( p )... ); }
decltype(auto) multikeyQuickSort (R &&A, P &&... p)
 multikeyQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void pdqSort (Store &&A, C less=C())
 the pattern-defeating quicksort
template<class T, class C = std::less<>>
void pdqSort (std::vector< T > &A, C less=C())
 pdqSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { pdqSort( v , std::forward< P >( p )... ); }
decltype(auto) pdqSort (R &&A, P &&... p)
 pdqSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<class V>
std::vector< std::pair< int, V > > pigeonholeSort (const std::vector< std::pair< int, V > > &A, int k)
 the pairs sorted by key, the values of a key in their first order
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
std::size_t partition (Store &&A, std::size_t start, std::size_t end, C less=C())
 the pivot \( A[ \mathit{start} ] \) moved to its place \( j \), the smaller items before it, the others after it (the perno() of the book); \( \mathit{end} - \mathit{start} \) comparisons
template<class T, class C = std::less<>>
std::size_t partition (std::vector< T > &A, std::size_t start, std::size_t end, C less=C())
 partition() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
std::size_t partitionByValue (Store &&A, std::size_t start, std::size_t end, const T &x, C less=C())
 the partition of \( A[ \mathit{start} .. \mathit{end} ] \) around a value \( x \) that need not be in it, in one pass from both ends: the items not larger than \( x \) first, the larger ones after; the number \( r \) of the items not larger than \( x \)
template<class T, class C = std::less<>>
std::size_t partitionByValue (std::vector< T > &A, std::size_t start, std::size_t end, const T &x, C less=C())
 partitionByValue() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void quickSort (Store &&A, std::size_t start, std::size_t end, C less=C())
 the sort of \( A[ \mathit{start} .. \mathit{end} ] \), the QuickSort() of the book
template<class T, class C = std::less<>>
void quickSort (std::vector< T > &A, std::size_t start, std::size_t end, C less=C())
 quickSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void quickSort (Store &&A, C less=C())
 \( A \) in increasing order by less, the Quicksort of the whole vector
template<class T, class C = std::less<>>
void quickSort (std::vector< T > &A, C less=C())
 quickSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void quickSortTuned (Store &&A, std::size_t cutoff=16, C less=C(), std::size_t *depth=nullptr)
 Quicksort with the improvements of section 12.2; the largest number of parts on the stack goes to *depth, if given.
template<class T, class C = std::less<>>
void quickSortTuned (std::vector< T > &A, std::size_t cutoff=16, C less=C(), std::size_t *depth=nullptr)
 quickSortTuned() above on a vector
template<class T, class C = std::less<>>
void quickSort (List< T > &L, C less=C())
 Quicksort of a list with pointers: the items go to three lists, smaller, equal and larger than the first one, the first and the last are sorted and the three are joined.
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { quickSort( v , std::forward< P >( p )... ); }
decltype(auto) quickSort (R &&A, P &&... p)
 quickSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { quickSortTuned( v , std::forward< P >( p )... ); }
decltype(auto) quickSortTuned (R &&A, P &&... p)
 quickSortTuned() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<RadixKey T>
auto radixKey (T x)
 the unsigned key of \( x \), whose order is the order of the numbers: the bits of \( x \) with the sign bit flipped for a signed integer, and for a floating point number all of them flipped if it is negative and the sign bit otherwise
template<SortStore Store, RadixKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void radixSort (Store &&A)
 the LSD radix sort of numbers
template<RadixKey T>
void radixSort (std::vector< T > &A)
 radixSort() above on a vector
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class K>
void radixSortBy (Store &&A, K key)
 the LSD radix sort of any items by the unsigned key( x ), stable
template<class T, class K>
void radixSortBy (std::vector< T > &A, K key)
 radixSortBy() above on a vector
template<SortStore Store, RadixKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void americanFlagSort (Store &&A)
 the MSD radix sort of numbers in place
template<RadixKey T>
void americanFlagSort (std::vector< T > &A)
 americanFlagSort() above on a vector
template<StringStore Store>
void msdRadixSort (Store &&A)
 the MSD radix sort of strings
void msdRadixSort (std::vector< std::string > &A)
 msdRadixSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { radixSort( v , std::forward< P >( p )... ); }
decltype(auto) radixSort (R &&A, P &&... p)
 radixSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { radixSortBy( v , std::forward< P >( p )... ); }
decltype(auto) radixSortBy (R &&A, P &&... p)
 radixSortBy() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { americanFlagSort( v , std::forward< P >( p )... ); }
decltype(auto) americanFlagSort (R &&A, P &&... p)
 americanFlagSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { msdRadixSort( v , std::forward< P >( p )... ); }
decltype(auto) msdRadixSort (R &&A, P &&... p)
 msdRadixSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void powerSort (Store &&A, C less=C(), std::size_t *runs=nullptr)
 Powersort; the number of runs found goes to *runs, if given.
template<class T, class C = std::less<>>
void powerSort (std::vector< T > &A, C less=C(), std::size_t *runs=nullptr)
 powerSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { powerSort( v , std::forward< P >( p )... ); }
decltype(auto) powerSort (R &&A, P &&... p)
 powerSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void sampleSort (Store &&A, C less=C())
 the in-place super scalar samplesort of \( A \) by less
template<class T, class C = std::less<>>
void sampleSort (std::vector< T > &A, C less=C())
 sampleSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { sampleSort( v , std::forward< P >( p )... ); }
decltype(auto) sampleSort (R &&A, P &&... p)
 sampleSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void selectionSort (Store &&A, C less=C())
 \( A \) in increasing order by less, by selection of the minimum
template<class T, class C = std::less<>>
void selectionSort (std::vector< T > &A, C less=C())
 selectionSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { selectionSort( v , std::forward< P >( p )... ); }
decltype(auto) selectionSort (R &&A, P &&... p)
 selectionSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
std::vector< std::size_t > knuthGaps (std::size_t n)
 the gaps \( h_1 = 1 \), \( h_{i+1} = 3 h_i + 1 \) below \( n \) (\( 1 , 4 , 13 , 40 , \ldots \)), increasing
std::vector< std::size_t > shellGaps (std::size_t n)
 the gaps \( 1 , \ldots , \lfloor n / 4 \rfloor , \lfloor n / 2 \rfloor \) of Shell, each half the next one, increasing
std::vector< std::size_t > hibbardGaps (std::size_t n)
 the gaps \( 2^k - 1 \) below \( n \) (\( 1 , 3 , 7 , 15 , \ldots \)), increasing
std::vector< std::size_t > prattGaps (std::size_t n)
 the gaps \( 3^i 2^j \) up to \( n \), increasing
std::vector< std::size_t > ciuraGaps (std::size_t n)
 the gaps of Ciura below \( n \), \( 1 , 4 , 10 , \ldots , 701 \) and then each \( 2.25 \) times the one before, increasing
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void shellSort (Store &&A, const std::vector< std::size_t > &gaps, C less=C())
 the Shell Sort with the given gaps, increasing and starting from 1
template<class T, class C = std::less<>>
void shellSort (std::vector< T > &A, const std::vector< std::size_t > &gaps, C less=C())
 shellSort() above on a vector
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void shellSort (Store &&A, C less=C())
 the Shell Sort of the book, with the gaps \( 1 , 4 , 13 , \ldots \)
template<class T, class C = std::less<>>
void shellSort (std::vector< T > &A, C less=C())
 shellSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { shellSort( v , std::forward< P >( p )... ); }
decltype(auto) shellSort (R &&A, P &&... p)
 shellSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void sort (Store &&A, C less=C())
 the sort chosen for \( A \) and less, not necessarily stable
template<class T, class C = std::less<>>
void sort (std::vector< T > &A, C less=C())
 sort() above on a vector
template<SortStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void stableSort (Store &&A, C less=C())
 the stable sort chosen for \( A \) and less
template<class T, class C = std::less<>>
void stableSort (std::vector< T > &A, C less=C())
 stableSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { sort( v , std::forward< P >( p )... ); }
decltype(auto) sort (R &&A, P &&... p)
 sort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { stableSort( v , std::forward< P >( p )... ); }
decltype(auto) stableSort (R &&A, P &&... p)
 stableSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
bool checkingContract (void)
 true while a contract of ADS is evaluated: a comparator that counts its calls skips those made by the contracts
std::vector< Comparator > mergeExchangeNetwork (std::size_t n)
 the merge exchange of Batcher for \( n \) items
std::vector< Comparator > bitonicNetwork (std::size_t n)
 the bitonic sorter for \( n \) items
template<RankStore Store, class T = std::ranges::range_value_t< std::remove_cvref_t< Store > >, class C = std::less<>>
void applyNetwork (Store &&A, const std::vector< Comparator > &N, C less=C())
 the comparators of \( N \) applied to \( A \) in their order
template<class T, class C = std::less<>>
void applyNetwork (std::vector< T > &A, const std::vector< Comparator > &N, C less=C())
 applyNetwork() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { applyNetwork( v , std::forward< P >( p )... ); }
decltype(auto) applyNetwork (R &&A, P &&... p)
 applyNetwork() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<class T, class C = std::less<>>
void strandSort (List< T > &L, C less=C(), std::size_t *strands=nullptr)
 the strand sort of a list; the number of strands goes to *strands, if given
template<StringStore Store>
void prefixKeySort (Store &&A)
 the stable sort of strings by integer keys of their prefixes
void prefixKeySort (std::vector< std::string > &A)
 prefixKeySort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { prefixKeySort( v , std::forward< P >( p )... ); }
decltype(auto) prefixKeySort (R &&A, P &&... p)
 prefixKeySort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
template<RankStore Store, std::totally_ordered T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void treeSort (Store &&A, bool balanced=true)
 the tree sort on a Red-Black tree, or on a search tree with no balance if balanced is false
template<std::totally_ordered T>
void treeSort (std::vector< T > &A, bool balanced=true)
 treeSort() above on a vector
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { treeSort( v , std::forward< P >( p )... ); }
decltype(auto) treeSort (R &&A, P &&... p)
 treeSort() on the range \( A \) [see SortRange], the other arguments as for a vector, in place: on the span of its items if \( A \) is contiguous, on its view otherwise, since the sort reads the items by their ranks only
template<SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void vectorQuickSort (Store &&A)
 the quicksort of \( A \) in the lanes of the vector registers, by the natural order (the total order of IEEE 754 for floating point numbers)
template<VectorKey T>
void vectorQuickSort (std::vector< T > &A)
 vectorQuickSort() above on a vector
template<VectorKey T>
void vectorQuickSort (T *a, std::size_t n)
 the sort of vectorQuickSort() above on \( a[ 0 .. n - 1 ] \)
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { vectorQuickSort( v , std::forward< P >( p )... ); }
decltype(auto) vectorQuickSort (R &&A, P &&... p)
 vectorQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses
long evalPostfix (std::string_view e)
 the value of the postfix expression \( e \)
std::string toPostfixParenthesized (std::string_view e)
 the postfix form of the fully parenthesized infix expression \( e \), its tokens separated by one space
std::string toPostfix (std::string_view e)
 the postfix form of the infix expression \( e \), with the usual precedences and the associativity to the left, its tokens separated by one space
bool isPalindrome (const std::string &s)
 whether \( s \) reads the same from both ends
template<Stack S>
void sortStack (S &s)
 sorts \( s \) with the least item on top
template<Stack S>
void removeGreater (S &s, const typename S::Item &k)
 removes the items larger than \( k \), the others in their order
template<Stack S, class F>
void forEachBottomUp (S &s, F &&f)
 f( x ) on each item \( x \), from the bottom to the top
bool isDyckWord (std::span< const int > w)
 whether the sequence \( w \) of \( +1 \) and \( -1 \) is a Dyck word, i.e., has no negative prefix sum
bool isMatched (std::string_view s)
 whether \( s \), a string of the brackets (), [] and {}, is matched, in \( O( n ) \)
template<Stack S, Queue Q = LinkedQueue< typename S::Item >>
void reverseWithQueue (S &s)
 the order of the items of \( s \) reversed by a QUEUE, the only operations of \( s \) being push() and pop()
template<class S>
int alignmentScore (const S &P, const S &T, Alignment kind)
 the best score of an alignment of \( P \) and \( T \)
template<class S>
std::pair< S, S > globalAlignment (const S &P, const S &T, typename S::value_type gap=' ')
 a best global alignment, the two strings with the spaces as gap
template<class S, class Hash = std::hash< S >>
std::vector< std::vector< S > > anagramGroups (const std::vector< S > &words)
 the classes of anagrams among the words, in the order of their first word, each in the order of the words
std::vector< std::vector< std::string > > anagramGroups (const std::vector< std::string > &words)
 the classes of anagramGroups() above, on std::string (or a list of literals)
template<class S>
Table matchingTable (const S &P, const S &T, bool edit=false)
 the table \( \mathit{DP} \) of \( P \) and \( T \), of \( m + 1 \) rows and \( n + 1 \) columns; with edit the first row is \( \mathit{DP}[ 0 ][ j ] = j \), that of the edit distance
template<class S>
std::pair< long, int > stringMatching (const S &P, const S &T)
 the end of an occurrence of \( P \) in \( T \) with the fewest errors, the first one, and their number; \( ( -1 , m ) \) if \( T \) is empty
template<class S>
std::size_t occurrence (const Table &DP, const S &P, const S &T, std::size_t j)
 the place where the occurrence of \( P \) starts in \( T \) that ends at \( T[ j - 1 ] \) with \( \mathit{DP}[ m ][ j ] \) errors, walking back on the table
template<class S>
int stringMatchingSingleRow (const S &P, const S &T)
 the least number of errors of an occurrence of \( P \) in \( T \), with two rows of the table only
template<class S>
int editDistance (const S &P, const S &T)
 the edit distance of \( P \) and \( T \), in \( O( \min( m , n ) ) \) space
std::size_t levenshtein (std::string_view a, std::string_view b)
 the edit distance of Levenshtein of \( a \) and \( b \)
std::size_t levenshtein (std::string_view a, std::string_view b, std::size_t k)
 the edit distance of \( a \) and \( b \) if at most \( k \), \( k + 1 \) otherwise
std::size_t lcsLength (std::string_view a, std::string_view b)
 the length of a longest common subsequence of \( a \) and \( b \)
std::vector< std::pair< std::size_t, std::size_t > > approximateMatches (std::string_view T, std::string_view P, std::size_t k)
 the ends \( j \), from 1 to \( n \), of the substrings of \( T \) at edit distance at most \( k \) from \( P \), in increasing order, with their distances
std::vector< FrontPair > frontCode (const std::vector< std::string > &D)
 the front coding of \( D \), a pair per string
std::vector< std::string > frontDecode (const std::vector< FrontPair > &F)
 the strings of the front coding \( F \)
void encodeLength (std::uint32_t l, std::string &out)
 appends to out the code of \( \ell \) in 1 to 4 bytes, the first two bits giving the number of bytes minus 1
std::uint32_t decodeLength (std::string_view in, std::size_t &pos)
 the length coded at in[ pos ], with pos moved past its code
template<class C, class F>
std::map< C, std::string > huffman (const std::map< C, F > &freq)
 the codes of Huffman of the characters with the given frequencies, at least one; a single character gets the code 0
template<class C>
std::string encode (const std::basic_string< C > &text, const std::map< C, std::string > &code)
 the text encoded by the codes, the code of each character in turn
template<class C>
std::basic_string< C > decode (const std::string &bits, const std::map< C, std::string > &code)
 the bits decoded by the codes, a prefix code
template<class S>
std::vector< std::vector< int > > lcsTable (const S &P, const S &T)
 the table of the lengths of the LCS of the prefixes of \( P \) and \( T \)
template<class S>
int lcsMemo (const S &P, const S &T, long *solved=nullptr)
 the length of the LCS by the memoization of the book, \( -1 \) marking the subproblems not solved yet; the number of the ones solved goes to *solved, if given
template<class S>
S lcs (const S &P, const S &T)
 a longest common subsequence, read back from the table
template<class S>
std::vector< std::pair< char, typename S::value_type > > diff (const S &P, const S &T)
 the differences from \( P \) to \( T \): ( '-' , p ) for an item of \( P \) only, ( '+' , t ) for an item of \( T \) only, ( ' ' , x ) for a common one
template<class S>
std::tuple< std::size_t, std::size_t, std::size_t > longestCommonSubstring (const S &P, const S &T)
 the longest common substring: its length and where it ends in \( P \) and \( T \), the first one found by rows of \( P \); \( ( 0 , 0 , 0 ) \) if they share nothing
bool isLyndon (std::string_view S)
 whether \( S \) is a Lyndon word, i.e., nonempty and smaller than all its proper suffixes, in \( O( n^2 ) \) by the definition
std::vector< std::size_t > lyndonFactorization (std::string_view S)
 the starts of the factors of the Lyndon factorization of \( S \), by Duval
std::size_t leastRotation (std::string_view S)
 the start of the least rotation of \( S \), 0 if \( S \) is empty
template<class S>
requires std::is_class_v< S >
std::pair< std::size_t, std::size_t > longestPalindrome (const S &s)
 where a longest palindromic substring of \( s \) starts and its length, the leftmost one among the longest; \( ( 0 , 0 ) \) for the empty \( s \)
template<class S>
requires std::is_class_v< S >
S longestPalindromicSubstring (const S &s)
 the leftmost of the longest palindromic substrings of \( s \)
std::string longestPalindromicSubstring (const std::string &s)
 the substring of longestPalindromicSubstring() above, on a std::string (or a literal)
template<class S>
requires std::is_class_v< S >
S longestPalindromicSubsequence (const S &s)
 a longest palindromic subsequence of \( s \)
std::string longestPalindromicSubsequence (const std::string &s)
 the subsequence of longestPalindromicSubsequence() above, on a std::string (or a literal)
template<class S>
requires std::is_class_v< S >
std::vector< S > palindromicPartition (const S &s)
 the fewest palindromes into which \( s \) can be cut, in their order; none for the empty \( s \)
std::vector< std::string > palindromicPartition (const std::string &s)
 the pieces of palindromicPartition() above, on a std::string (or a literal)
std::vector< std::string > palindromicFactorization (std::string_view s)
 the fewest palindromes into which \( s \) can be cut, in their order, by the series of the eertree, in \( O( n \log n ) \); none for the empty \( s \)
std::size_t longestBalancedSubsequence (std::string_view s, char open='(', char close=')')
 the length of a longest subsequence of \( s \) that is a balanced string of the parentheses open and close
std::pair< std::size_t, std::size_t > longestBalancedSubstring (std::string_view s, char open='(', char close=')')
 where the leftmost of the longest balanced substrings of \( s \) starts and its length, \( ( 0 , 0 ) \) if there is none
std::size_t lexicographicPosition (const std::vector< std::string > &A, std::string_view Q)
 the number of strings of the sorted \( A \) smaller than \( Q \)
std::size_t prefixEnd (const std::vector< std::string > &A, std::string_view P)
 the number of strings of the sorted \( A \) smaller than \( P\# \), i.e., smaller than \( P \) or prefixed by \( P \)
std::pair< std::size_t, std::size_t > prefixRange (const std::vector< std::string > &A, std::string_view P)
 the range \( [ l , r ) \) of the strings of the sorted \( A \) prefixed by \( P \)
std::size_t commonPrefixLength (std::string_view a, std::string_view b)
 the length of the longest common prefix of \( a \) and \( b \), by comparing them from their start
std::vector< RearPair > rearCode (const std::vector< std::string > &D)
 the rear coding of \( D \), a pair per string
std::vector< std::string > rearDecode (const std::vector< RearPair > &R)
 the strings of the rear coding \( R \)
template<class S>
requires std::is_class_v< S >
std::uint64_t countSegmentations (const S &X, const std::vector< S > &words)
 the number of ways of writing \( X \) as a sequence of the words, modulo \( 2^{64} \); a word repeated in the list counts once for each copy; 1 for the empty \( X \)
std::uint64_t countSegmentations (const std::string &X, const std::vector< std::string > &words)
 the count of countSegmentations() above, on std::string (or literals)
std::uint64_t countDecodings (const std::vector< int > &digits)
 the number of readings of the digits as letters \( A = 1 , \ldots , Z = 26 \), modulo \( 2^{64} \); 1 for no digits
template<class I>
I stringBreakingCost (const std::vector< I > &cuts, std::type_identity_t< I > length)
 the least total cost of the cuts of a string of the given length at the places cuts
std::int64_t stringBreakingCost (const std::vector< std::int64_t > &cuts, std::int64_t length)
 the cost of stringBreakingCost() above, on std::int64_t (or a braced list)
template<class I>
std::vector< I > stringBreakingOrder (const std::vector< I > &cuts, std::type_identity_t< I > length)
 the places cuts in an order of least total cost
std::vector< std::int64_t > stringBreakingOrder (const std::vector< std::int64_t > &cuts, std::int64_t length)
 the order of stringBreakingOrder() above, on std::int64_t (or a braced list)
std::vector< std::size_t > naiveMatching (std::string_view T, std::string_view P)
 the places of all the occurrences of \( P \) in \( T \), by trying every shift
std::vector< long > failure (std::string_view P)
 the failure function: \( F[ q ] \) is the length of the longest proper border of \( P[ 0 .. q - 1 ] \), and \( F[ 0 ] = -1 \)
std::vector< std::size_t > kmp (std::string_view T, std::string_view P, long *comparisons=nullptr)
 the places of all the occurrences of \( P \) in \( T \), by Knuth-Morris-Pratt; the comparisons of characters go to *comparisons, if given
std::vector< long > strongFailure (std::string_view P)
 the strong failure function: \( G[ q ] = F[ q ] \) unless \( P[ F[ q ] ] = P[ q ] \), in which case \( G[ q ] = G[ F[ q ] ] \); \( G[ m ] = F[ m ] \)
std::vector< std::size_t > kmpStrong (std::string_view T, std::string_view P, long *comparisons=nullptr)
 the occurrences of kmp() above, with the strong failure function on a mismatch
std::vector< std::size_t > boyerMoore (std::string_view T, std::string_view P, long *comparisons=nullptr)
 the places of all the occurrences of \( P \) in \( T \), by Boyer-Moore with the bad character and the strong good suffix rules
std::vector< std::size_t > horspool (std::string_view T, std::string_view P, long *comparisons=nullptr)
 the places of all the occurrences of \( P \) in \( T \), by Horspool
std::vector< std::size_t > shiftOr (std::string_view T, std::string_view P)
 the places of all the occurrences of \( P \) in \( T \), by Shift-Or
std::vector< std::size_t > zFunction (std::string_view S)
 the Z-function: \( Z[ i ] \) is the length of the longest common prefix of \( S \) and \( S[ i .. ] \), and \( Z[ 0 ] = |S| \)
std::vector< std::size_t > zMatching (std::string_view T, std::string_view P)
 the places of all the occurrences of \( P \) in \( T \), by the Z-function of \( P \) and the Z-boxes of \( T \)
std::vector< std::size_t > twoWay (std::string_view T, std::string_view P)
 the places of all the occurrences of \( P \) in \( T \), by the Two-Way algorithm of Crochemore and Perrin
std::size_t findFirst (std::string_view T, std::string_view P, std::size_t from=0)
 the first occurrence of \( P \) in \( T \) at or after from, npos if none, by a StringSearcher used once
std::vector< std::size_t > findAll (std::string_view T, std::string_view P)
 all the occurrences of \( P \) in \( T \), overlapping ones included, by a StringSearcher used once
template<class S>
requires std::is_class_v< S >
bool isInterleaving (const S &X, const S &Y, const S &Z)
 whether \( Z \) interleaves \( X \) and \( Y \) keeping the order of the items of each
bool isInterleaving (const std::string &X, const std::string &Y, const std::string &Z)
 isInterleaving() above on std::string (or literals)
template<class S>
requires std::is_class_v< S >
std::size_t scsLength (const S &X, const S &Y)
 the length of a shortest common supersequence of \( X \) and \( Y \)
std::size_t scsLength (const std::string &X, const std::string &Y)
 scsLength() above on std::string (or literals)
template<class S>
requires std::is_class_v< S >
S shortestCommonSupersequence (const S &X, const S &Y)
 a shortest common supersequence of \( X \) and \( Y \)
std::string shortestCommonSupersequence (const std::string &X, const std::string &Y)
 shortestCommonSupersequence() above on std::string (or literals)
template<class S>
requires std::is_class_v< S >
std::uint64_t subsequenceOccurrences (const S &P, const S &T)
 the number of occurrences of \( P \) as a subsequence of \( T \), modulo \( 2^{64} \): 1 for the empty \( P \), 0 if \( P \) is longer than \( T \)
std::uint64_t subsequenceOccurrences (const std::string &P, const std::string &T)
 subsequenceOccurrences() above on std::string (or literals)
template<class S>
requires std::is_class_v< S >
S lcs3 (const S &X, const S &Y, const S &Z)
 a longest common subsequence of \( X \), \( Y \) and \( Z \)
std::string lcs3 (const std::string &X, const std::string &Y, const std::string &Z)
 lcs3() above on std::string (or literals)
std::pair< std::size_t, std::size_t > longestRepeatedSubstring (const SuffixArray &SA)
 the place and the length of a longest substring that occurs twice (0 and 0 if none)
std::optional< std::size_t > repeatedSubstring (const SuffixArray &SA, std::size_t L, std::size_t C)
 the place of a substring of length \( L \) that occurs at least \( C \) times, if any
std::uint64_t distinctSubstrings (const SuffixArray &SA)
 the number of distinct nonempty substrings, \( n ( n + 1 ) / 2 - \sum_r \mathit{LCP}[ r ] \)
std::string longestCommonSubstring (const std::vector< std::string > &S, std::size_t k)
 a longest substring common to at least \( k \) of the strings \( S \)
std::vector< std::pair< std::size_t, std::size_t > > maximalRepeats (const SuffixTree &ST)
 the maximal repeats, as the place of an occurrence and the length
bool proximity (const SuffixArray &SA, std::string_view P, std::string_view Q, std::size_t k)
 whether an occurrence of \( P \) and one of \( Q \) start at most \( k \) places apart
std::vector< std::size_t > kMismatches (std::string_view T, std::string_view P, std::size_t k)
 the places where \( P \) occurs in \( T \) with at most \( k \) mismatches
std::vector< CopyPhrase > lz77ByTree (std::string_view T)
 the parsing of Ziv and Lempel of \( T \), the copies from the farthest occurrence, by the suffix tree
std::string decodeCopyPhrases (const std::vector< CopyPhrase > &Z)
 the text of a parsing, each phrase copying its symbols one at a time, so that a copy may overlap the symbols it writes
Symbols toSymbols (std::string_view T)
 the bytes of \( T \) as symbols in \( [ 0 , 256 ) \)
std::vector< std::size_t > suffixArraySorting (const Symbols &T)
 the suffix array of \( T \) by a sort of comparisons of its suffixes
std::vector< std::size_t > suffixArraySorting (std::string_view T)
 the array of suffixArraySorting() above, on the bytes of \( T \)
std::vector< std::size_t > suffixArrayDoubling (const Symbols &T)
 the suffix array of \( T \) by the prefix doubling of Manber and Myers
std::vector< std::size_t > suffixArrayDoubling (std::string_view T)
 the array of suffixArrayDoubling() above, on the bytes of \( T \)
std::vector< std::size_t > suffixArrayLarssonSadakane (const Symbols &T)
 the suffix array of \( T \) by the doubling of Larsson and Sadakane
std::vector< std::size_t > suffixArrayLarssonSadakane (std::string_view T)
 the array of suffixArrayLarssonSadakane() above, on the bytes of \( T \)
std::vector< std::size_t > suffixArraySkew (const Symbols &T, std::size_t K)
 the suffix array of \( T \) by the Skew algorithm of Kärkkäinen and Sanders
std::vector< std::size_t > suffixArraySkew (std::string_view T)
 the array of suffixArraySkew() above, on the bytes of \( T \)
std::vector< std::size_t > suffixArraySais (const Symbols &T, std::size_t K)
 the suffix array of \( T \) by the induced sorting of Nong, Zhang and Chan
std::vector< std::size_t > suffixArraySais (std::string_view T)
 the array of suffixArraySais() above, on the bytes of \( T \)
std::vector< std::size_t > suffixArrayScan (const Symbols &T, std::size_t m)
 the suffix array of \( T \) by the scan-based algorithm of Baeza-Yates, Gonnet and Snider, on blocks of \( m \) symbols
std::vector< std::size_t > suffixArrayScan (std::string_view T, std::size_t m)
 the array of suffixArrayScan() above, on the bytes of \( T \)
std::vector< std::size_t > inversePermutation (const std::vector< std::size_t > &SA)
 the inverse of a permutation: \( R[ \mathit{SA}[ r ] ] = r \)
std::vector< std::size_t > lcpArray (const Symbols &T, const std::vector< std::size_t > &SA)
 the LCP array of Kasai et al., \( n - 1 \) entries (none if \( n < 2 \))
std::vector< std::size_t > lcpArray (std::string_view T, const std::vector< std::size_t > &SA)
 the array of lcpArray() above, on the bytes of \( T \)
template<class I = std::uint32_t>
requires ( std::same_as< I , std::uint32_t > || std::same_as< I , std::uint64_t > )
std::vector< I > suffixArray (std::string_view T)
 the suffix array of the bytes of \( T \), by SA-IS on integers I (32 or 64 bits, unsigned)
template<class I>
requires ( std::same_as< I , std::uint32_t > || std::same_as< I , std::uint64_t > )
std::vector< I > suffixArray (const std::vector< I > &T, std::size_t K)
 the suffix array of an integer text, by SA-IS
template<class I>
std::vector< I > plcpArray (std::string_view T, const std::vector< I > &SA)
 the permuted LCP array: \( \mathit{PLCP}[ i ] \) is the lcp of the suffix \( i \) and the one before it in \( \mathit{SA} \) (0 for the first)
template<class I>
std::vector< I > lcpArrayPhi (std::string_view T, const std::vector< I > &SA)
 the LCP array by the permuted LCP array, \( n - 1 \) entries (none if \( n < 2 \))
template<class F>
std::optional< std::vector< std::string > > wordBreak (const std::string &s, F &&lookup, std::size_t longest=std::string::npos, long *lookups=nullptr)
 the words of \( s \), if it is a sequence of words, by the lookup( word ) of a dictionary; the lookups made go to *lookups, if given
constexpr int selectInWord (Word x, int k)
 the place of the \( k \)-th 1 of the word \( x \), counting \( k \) from 0 and the places from the least significant bit
template<class T, class Pre, class In, class Post>
void dfs (BinaryTree< T > *t, Pre &&pre, In &&in, Post &&post)
 the visit in depth: pre( t ) before the subtrees, in( t ) between them, post( t ) after them; nothing on an empty tree.
template<class T, class F>
void pre_visit (BinaryTree< T > *t, F &&f)
 the previsit of a binary tree, dfs() with f as pre alone
template<class T, class F>
void in_visit (BinaryTree< T > *t, F &&f)
 the invisit (symmetric visit) of a binary tree, dfs() with f as in alone
template<class T, class F>
void post_visit (BinaryTree< T > *t, F &&f)
 the postvisit of a binary tree, dfs() with f as post alone
template<class T>
BinaryTree< T > * copy (const BinaryTree< T > *t)
 a deep copy of the subtree \( t \), nil if \( t \) is nil; the caller owns it
template<class T>
BinaryTree< T > * join (const T &v, const BinaryTree< T > *l, const BinaryTree< T > *r)
 a new root of value \( v \) with copies of \( l \) and \( r \), each possibly nil, as its children; the caller owns it
template<class T>
std::string to_list (const BinaryTree< T > *t)
 the parenthesized list of \( t \), () if \( t \) is nil
template<class T>
BinaryTree< T > * from_list (std::string_view s)
 the binary tree of the parenthesized list \( s \), nil for (); the caller owns it
template<class T>
BinaryTree< T > * to_binary (const Tree< T > *t)
 the binary tree that represents the ordered tree \( t \) (figure 5.9): the left child of a node is its first child in \( t \), the right one its next sibling; the caller owns the result
long dary_child (long i, long d, long j)
 the place \( d i + j \) of the \( j \)-th child, \( 1 \le j \le d \), of the node in the place \( i \) of a complete \( d \)-ary tree stored in a vector
long dary_parent (long i, long d)
 the place \( \lfloor ( i - 1 ) / d \rfloor \) of the parent of the node in the place \( i > 0 \)
template<class T>
auto preorder (BinaryTree< T > *t)
 the nodes of the subtree of \( t \) in preorder, \( t \) first, by the links to the parents
template<class T>
auto inorder (BinaryTree< T > *t)
 the nodes of the subtree of \( t \) in symmetric order, by the links to the parents
template<class T>
auto postorder (BinaryTree< T > *t)
 the nodes of the subtree of \( t \) in postorder, \( t \) last, by the links to the parents
template<ParentBinaryNode N>
N lowestCommonAncestor (N u, N v)
 the deepest node that is an ancestor of both \( u \) and \( v \), each node being an ancestor of itself; \( O( h ) \) time, \( O( 1 ) \) space
template<KeyedBinaryNode N, KeyedBinaryNode M, class Equal = std::equal_to<>>
bool equalTrees (N t, M s, Equal eq={})
 whether \( t \) and \( s \) have the same shape and eq( a , b ) holds on the keys \( a \) and \( b \) of each two nodes in the same place; \( O( n ) \) time, \( O( h ) \) space
template<KeyedBinaryNode N, class Compare = std::less<>>
bool isSearchTree (N t, Compare less={})
 whether the keys of \( t \) are strictly increasing in the invisit, by less; \( O( n ) \) time, \( O( h ) \) space
template<BinaryNode N, class Red>
bool isRedBlackTree (N t, Red red)
 whether the coloring of \( t \), red( u ) telling whether the node \( u \) is red, respects the constraints of a Red-Black tree: the root black, no red node with a red child, the same number of black nodes on every path from the root down to a leaf nil; \( O( n ) \) time, \( O( h ) \) space
template<KeyedBinaryNode N, class K, class F, class Compare = std::less<>>
std::size_t searchTreeRange (N t, const K &lo, const K &hi, F &&f, Compare less={})
 f( u ) on the nodes \( u \) of the binary search tree \( t \) whose keys are in \( [ \mathit{lo} , \mathit{hi} ] \), in increasing order of the keys; the number of the nodes examined, at most \( k + 2 ( h + 1 ) \) for \( k \) keys in the range; \( O( h + k ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
N searchTreeFind (N t, const K &k, Compare less={})
 the node of the key \( k \) in the binary search tree \( t \), nil if absent; \( O( h ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
auto searchTreeLookup (N t, const K &k, Compare less={})
 the value of the key \( k \) in the binary search tree \( t \), nothing if absent, by searchTreeFind(); \( O( h ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
N searchTreeLowerBound (N t, const K &k, Compare less={})
 the node of the smallest key not smaller than \( k \) in the binary search tree \( t \), nil if none (the find(x) of an SSet of Morin); \( O( h ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
auto searchTreeFindKey (N t, const K &k, Compare less={})
 the address of the key \( k \) in the binary search tree \( t \), nil if absent (the find(x) of a USet of Morin), by searchTreeLowerBound() and one more comparison; \( O( h ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
auto searchTreeLowerBoundKey (N t, const K &k, Compare less={})
 the address of the smallest key not smaller than \( k \) in the binary search tree \( t \), nil if none, by searchTreeLowerBound(); \( O( h ) \) time
template<KeyedBinaryNode N, class K, class Compare = std::less<>>
auto searchTreeLowerBoundEntry (N t, const K &k, Compare less={})
 the key and the value of the smallest key not smaller than \( k \) in the binary search tree \( t \) as a pair, nothing if none, by searchTreeLowerBound(); \( O( h ) \) time
template<SizedBinaryNode N>
N searchTreeSelect (N t, std::size_t i)
 the node of rank \( i \) of the binary search tree \( t \), i.e., with \( i \) smaller keys, by the sizes of the left subtrees; \( O( h ) \) time
template<SizedBinaryNode N, class K, class Compare = std::less<>>
std::size_t searchTreeRank (N t, const K &k, Compare less={})
 the number of the keys smaller than \( k \) in the binary search tree \( t \), the sizes of the left subtrees passed on the right along the search of \( k \), plus one for each node so passed; \( O( h ) \) time
template<class N, class K, class Compare = std::less<>>
requires KeyedBinaryNode< N * > && std::is_pointer_v< decltype( N::left ) >
N ** searchTreeLink (N **link, const K &k, std::vector< N * > &P, Compare less={})
 the link at which the key \( k \) is, or would be inserted, in the binary search tree whose root is *link, i.e., the address of the root or of the field left or right of the parent, the nodes passed above it pushed on \( P \) from the root down; the key is there if and only if the node at the link returned is not nil; \( O( h ) \) time
template<class N>
requires BinaryNode< N * > && std::is_pointer_v< decltype( N::left ) >
N * searchTreeSplice (N **link, std::vector< N * > &P)
 the node at link (as given by searchTreeLink()) taken out of its binary search tree: if it has two children, its key and its value are replaced by those of its successor, which is taken out instead, and the nodes down to the successor are pushed on \( P \); the node taken out is returned, to be freed, and its parent (the last node of \( P \)) links its only child; \( O( h ) \) time
template<ParentBinaryNode N>
N nextPreorder (N u)
 the node after \( u \) in the previsit of its tree, nil after the last; \( O( 1 ) \) amortized over a whole visit (exercise 6.8 of Morin)
template<ParentBinaryNode N>
N nextInorder (N u)
 the node after \( u \) in the invisit of its tree, nil after the last; \( O( 1 ) \) amortized over a whole visit (exercise 6.8 of Morin)
template<ParentBinaryNode N>
N nextPostorder (N u)
 the node after \( u \) in the postvisit of its tree, nil after the root; \( O( 1 ) \) amortized over a whole visit (exercise 6.8 of Morin)
template<BinaryNode N>
N firstInorder (N u)
 the first node of the invisit of the subtree of \( u \), its leftmost node, from which nextInorder() starts; \( O( h ) \) time
template<BinaryNode N>
N firstPostorder (N u)
 the first node of the postvisit of the subtree of \( u \), reached by going left when possible and right otherwise, from which nextPostorder() starts; \( O( h ) \) time (the first node of the previsit is \( u \) itself)
template<BinaryNode N>
long treeHeight (N t)
 the height of the tree \( t \), \( -1 \) if empty, by levels with no recursion: \( O( n ) \) time and \( O( w ) \) space for a tree of width \( w \), on a degenerate tree of any height
template<ParentBinaryNode N>
std::size_t subtreeSize (N u)
 the number of nodes of the subtree of \( u \), by a walk along the links to the parents that never leaves the subtree, with no recursion and no stack: \( O( n_u ) \) time and \( O( 1 ) \) space (the size2(u) of exercise 6.4 of Morin)
template<ParentBinaryNode N>
long subtreeHeight (N u)
 the height of the subtree of \( u \), \( -1 \) for nil, by the walk of subtreeSize() that keeps the depth below \( u \): \( O( n_u ) \) time and \( O( 1 ) \) space (the height2(u) of exercise 6.5 of Morin)
template<BinaryNode N>
bool isSizeBalanced (N t)
 whether every node \( u \) of \( t \) has subtrees whose sizes differ by 1 at most (exercise 6.6 of Morin), by a postvisit that returns the size of each subtree, or stops at the first that is not balanced: \( O( n ) \) time, against the \( \Theta( n \log n ) \) to \( \Theta( n^2 ) \) of a test that computes each size again
template<BinaryNode N, class F>
void orderNumbers (N t, F &&f)
 f( u , pre , in , post ) on each node \( u \) of \( t \) with its numbers in the previsit, in the invisit and in the postvisit, from 0, in one visit: \( O( n ) \) time, \( O( h ) \) space (exercise 6.7 of Morin).
template<BinaryNode N>
std::vector< bool > shapeCode (N t)
 the shape of \( t \) in \( 2 ( n - 1 ) \) bits, none for \( n \le 1 \) (exercise 6.11 of Morin): for each node in the previsit but the last, which is a leaf, whether it has a left and whether it has a right child; \( O( n ) \) time.
BinaryTree< std::size_t > * fromShapeCode (const std::vector< bool > &c, std::size_t n)
 the tree of the shape of shapeCode() above, its values the numbers of the previsit; the caller owns it, nil if \( n = 0 \); \( O( n ) \)
template<KeyedBinaryNode N, class K, class F, class Compare = std::less<>>
std::size_t lessOrEqual (N t, const K &x, F &&f, Compare less={})
 f( u ) on the nodes \( u \) of the binary search tree \( t \) whose keys are not larger than \( x \), in increasing order, and their number \( n' \); \( O( n' + h ) \) time (the getLE(x) of exercise 6.14 of Morin)
template<class T, class Make, class Compare = std::less<>>
auto minimumHeightSearchTree (const std::vector< T > &A, Make make, Compare less={}) -> std::invoke_result_t< Make &, const T &, std::nullptr_t, std::nullptr_t >
 the binary search tree of the keys of \( A \) of the least height, the lower middle key at the root of each subtree, whose nodes are made by make( v , l , r ) over the subtrees \( l \) and \( r \), nil if \( A \) is empty; \( O( n ) \) time
template<class T, class Compare = std::less<>>
requires std::predicate< Compare & , const T & , const T & >
BinaryTree< T > * minimumHeightSearchTree (const std::vector< T > &A, Compare less={})
 the tree of minimumHeightSearchTree() above as a BinaryTree, which the caller owns
template<class T>
BinaryTree< T > * fromPreorderInorder (const std::vector< T > &pre, const std::vector< T > &in)
 the binary tree whose previsit is pre and whose invisit is in, nil if they are empty; \( O( n ) \) time; the caller owns it
template<class T, class Compare = std::less< T >>
BinaryTree< T > * cartesianBinaryTree (const std::vector< T > &A, Compare less={})
 the Cartesian tree of \( A \), the leftmost minimum by less at the root, a heap whose invisit is \( A \), nil if \( A \) is empty; \( O( n ) \) time; the caller owns it
BinaryTree< std::string > * expressionTree (std::string_view e)
 the expression tree of the postfix expression \( e \), whose tokens are separated by spaces; the caller owns it
double evaluate (const BinaryTree< std::string > *t, const std::map< std::string, double > &env={})
 the value of the expression \( t \), with the variables valued by env; a leaf is a number, possibly signed (e.g., -3, +2.5, .5), or a variable
std::string prefixForm (const BinaryTree< std::string > *t)
 the prefix form of \( t \), each subtree in parentheses, by a previsit (section 5.6)
std::string infixForm (const BinaryTree< std::string > *t)
 the infix form of \( t \), fully parenthesized, by an invisit (section 5.6)
template<class T, class C = std::less<>>
void maxHeapSiftUp (std::vector< T > &A, std::size_t i, C less=C())
 \( A[ i ] \) up in the heap \( A[ 0 .. i ] \), with the order less; \( O( \log i ) \) time
template<class T, class C = std::less<>>
void heapBuildByInsertion (std::vector< T > &A, C less=C())
 \( A \) made a max-heap by inserting its items one at a time; \( O( n \log n ) \) time
template<class T, class Pre, class Post>
void dfs (Tree< T > *t, Pre &&pre, Post &&post)
 the visit in depth: pre( u ) on each node before its subtrees are visited, post( u ) after; pre_visit() and post_visit() are dfs() with one of them.
template<class T, class F>
void pre_visit (Tree< T > *t, F &&f)
 the previsit: f( u ) on the root, then on the subtrees in order
template<class T, class F>
void post_visit (Tree< T > *t, F &&f)
 the postvisit: f( u ) on the subtrees in order, then on the root
template<class T, class F>
void in_visit (Tree< T > *t, int i, F &&f)
 the invisit: the first \( i \) subtrees, the root, the other subtrees
template<class T>
Tree< T > * copy (const Tree< T > *t)
 a deep copy of the subtree \( t \) and of its children, not of its siblings; the caller owns it
template<class T, class F>
void bfs (Tree< T > *t, F &&f)
 the visit by levels, with a queue of the nodes to examine
template<class T>
int maxWeightLevel (Tree< T > *t)
 the first level of largest weight, the weight of a level being the sum of the values of its nodes (the root at level 0), by a visit by levels
template<class T>
std::string to_list (const Tree< T > *t)
 the parenthesized list of \( t \), \( ( r \, T_1 \cdots T_k ) \) for the root \( r \) with the subtrees \( T_1 , \ldots , T_k \), e.g., ( a ( b ( e ) ( f ) ) ( c ( g ) ) ); the values are written with << and must contain no space nor parenthesis
template<class T>
Tree< T > * tree_from_list (std::string_view s)
 the tree of the parenthesized list \( s \), its values read with >>; the caller owns it
template<class T>
auto children (Tree< T > *t)
 the children of \( t \), from the leftmost, as a range
template<class T>
auto preorder (Tree< T > *t)
 the nodes of the subtree of \( t \) in preorder, \( t \) first, as a range by the links to the parents and the siblings, with no stack

Variables

template<class G>
constexpr bool exact_v
 whether the values of G are exact, false for the floating point types, whose groups drift by rounding when a value leaves by its inverse
template<class S>
constexpr bool 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 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 stable_references {}
 the tags of the queries
constexpr thread_safe_reads_t thread_safe_reads {}
constexpr rank_complexity_t rank_complexity {}
constexpr event_set_t event_set {}
template<class S, forwarding_query_tag T>
constexpr auto 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 query_meet_v
 the answer of the composition of A and B to the query T
constexpr detail::Query query {}
 the answer of \( s \) to the query of the tag \( t \), query_v< S , T >
constexpr detail::Reserve reserve {}
 room for \( n \) items in \( s \): s.reserve( n ), else reserve( s , n ) found by ADL, else nothing (the builders)
constexpr detail::Prefetch 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 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 \)
constexpr std::size_t bwtWideFrom = ( std::size_t( 1 ) << 31 ) - 1
 the transform of \( s \)
template<class K, class V, class H, class Eq>
constexpr bool nonmonotone_values< ConcurrentCuckooTable< K, V, H, Eq > > = true
 the values of the table may rise as well as fall [see Capabilities.h]: a lookup reads a pair under the version of its region, or under its lock, so that it returns a value that one write left whole, whatever the direction of the writes
constexpr std::array< GridCell, 4 > FOUR_MOVES
 the moves to the four sides of a cell: up, left, down, right
constexpr std::array< GridCell, 8 > EIGHT_MOVES
 the moves to the sides and to the corners of a cell, those of the king
constexpr std::array< GridCell, 8 > KNIGHT_MOVES
 the moves of the knight
constexpr int INF = std::numeric_limits< int >::max()
 the infinite distance
constexpr int NIL = -1
 no node
constexpr no_rebuild_t no_rebuild {}
 the promise of quiet( s , no_rebuild )
constexpr std::size_t kGemmBlock = 256
 the columns and the rows of \( B \) of a block of the product of the definition, without the CBLAS: a round number, not measured
constexpr U64 kMersenne61 = ( U64( 1 ) << 61 ) - 1
 the Mersenne prime \( 2^{61} - 1 \)
constexpr std::size_t kBlocks = 64
 the largest number of blocks into which the loops and the reductions cut their indices, by default
constexpr std::size_t kGrain = 1024
 the least number of indices of a block of the loops, by default
constexpr std::size_t kParallelSort = std::size_t( 1 ) << 15
 the items from which the parallel sorts use more than one thread, \( 2^{15} \)
constexpr std::size_t kParallelSortThreads = 3
 the threads from which the parallel sorts distribute: on 2 threads the passes of the distribution cost more than the second thread saves (on the benchmark, 0.6 to 1.5 times the time of the sequential sort, 0.8 in the median), and the sequential sort runs instead
template<class T, std::totally_ordered P, class A>
constexpr bool enable_stable_references< FibonacciHeapPriorityQueue< T, P, A > > = true
 the items of a Fibonacci heap stay in their nodes, which the handles point to [see Capabilities.h]
template<class T, std::totally_ordered P, bool Aux, class A>
constexpr bool enable_stable_references< PairingHeap< T, P, Aux, A > >
 the items of a pairing heap stay in their nodes, which the handles point to [see Capabilities.h]
constexpr detail::QueueMin queue_min {}
 the item of smallest priority of \( q \): q.min(), else queue_min( q ) found by ADL, else q.top()
constexpr detail::QueueDeleteMin queue_deleteMin {}
 the item of smallest priority of \( q \), removed: q.deleteMin(), else queue_deleteMin( q ) found by ADL, else q.pop() if it returns the item, else q.top() and then q.pop()
constexpr detail::QueueInsert queue_insert {}
 \( x \) inserted in \( q \) with the keys \( a \) of its order: q.insert( x , a... ), else queue_insert( q , x , a... ) found by ADL, else q.push( x , a... )
constexpr detail::QueueDecrease queue_decrease {}
 the priority of the item of the handle \( h \) of \( q \) lowered to \( p \), i.e., the item moved toward the minimum: q.decrease( h , p ) if Q declares a Handle, the handles of the book, else queue_decrease( q , h , p ) found by ADL.
constexpr std::size_t kFlagSmall = kVectorSort ? 8192 : 256
 the groups that americanFlagSort() leaves to a sort by comparisons are those of fewer items than this: many with the vector registers, whose quicksort beats the radix passes that it replaces, few otherwise
constexpr std::size_t kRadix = 512
 the items from which the numbers go to radixSort()
constexpr std::size_t kStrings = 64
 the items from which the strings go to the sorts by characters
constexpr std::size_t kRuns = 16
 the runs up to which the numbers and the strings go to powerSort()
constexpr bool kVectorSort = ADS_VECTOR_SORT != 0
 true if vectorQuickSort() runs in the vectors of the processor, by the quicksort of Highway, false if in the arrays of the portable code
constexpr std::size_t kJoinGrain = 2048
 the sum of the sizes of two trees below which the algorithms run on the calling thread alone

Typedef documentation

◆ Adjacency

using ADS::Adjacency = std::vector< std::vector< bool > >

an adjacency

◆ Bits

using ADS::Bits = std::vector< int >

the bits, the least significant first

◆ Clause

using ADS::Clause = std::vector< int >

some literals

◆ Cnf

using ADS::Cnf = std::vector< Clause >

a formula

◆ Grid

using ADS::Grid = std::vector< std::vector< int > >

the squares, 0 empty

◆ Matrix

template<class T>
using ADS::Matrix = std::vector< std::vector< T > >

by rows

◆ Nodes

using ADS::Nodes = std::vector< int >

a set, a path

◆ Philox4x32

using ADS::Philox4x32 = PhiloxT< std::uint32_t >

◆ Philox4x64

using ADS::Philox4x64 = PhiloxT< std::uint64_t >

< Philox4x32-10

◆ Tiling

using ADS::Tiling = std::vector< std::vector< int > >

the tile of ( i , j )

◆ Tuple

using ADS::Tuple = std::vector< int >

a tuple, a permutation, a string

◆ U64

using ADS::U64 = std::uint64_t

the unsigned integers of 64 bits

◆ Word

using ADS::Word = std::uint64_t

a word of 64 bits

◆ Xoshiro256

using ADS::Xoshiro256 = Xoshiro256T< false >

◆ Xoshiro256StarStar

< xoshiro256++

Variable documentation

◆ event_set

event_set_t ADS::event_set {}
inlineconstexpr

◆ rank_complexity

rank_complexity_t ADS::rank_complexity {}
inlineconstexpr

◆ thread_safe_reads

thread_safe_reads_t ADS::thread_safe_reads {}
inlineconstexpr