|
ADS
Algorithms and Data Structures
|
The ranking of a list, the distance of each item from the tail, in the memory and in the two-level memory [see TwoLevelMemory.h], following chapter 4, List Ranking, of Ferragina's book. More...
#include "ADS/Contract.h"#include "ADS/external/ExternalSorting.h"#include "ADS/external/TwoLevelMemory.h"#include "ADS/search/BinarySearch.h"#include <algorithm>#include <bit>#include <cstddef>#include <cstdint>#include <utility>#include <vector>#include "ADS/external/impl/ListRanking.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| bool | ADS::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 > | ADS::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 > | ADS::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 > | ADS::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 > | ADS::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 > | ADS::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 > | ADS::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 | ADS::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 | ADS::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 | ADS::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 | |
The ranking of a list, the distance of each item from the tail, in the memory and in the two-level memory [see TwoLevelMemory.h], following chapter 4, List Ranking, of Ferragina's book.
A list of \( n \) items is the vector \( \mathit{succ} \) of their successors, the items being \( 0 , \ldots , n - 1 \) and the tail \( t \) the only one with \( \mathit{succ}[ t ] = t \).
Compared with the literature: the optimal parallel rankings of Cole and Vishkin and of Anderson and Miller reach \( O( n ) \) operations in \( O( \log n ) \) time by the same independent sets; on the disk the bound \( \Theta( \mathrm{sort}( n ) ) \) of Chiang et al. is optimal, and is what externalListRank() attains, while the deterministic recursion on the disk would repeat the joins of the coins \( \log^* n \) times per level, and is here only in the memory. The records of the disk are atomic items of the model.
The contracts [see Contract.h]: \( \mathit{succ} \) is a list, one tail and every item reached from the only head, an audit; the operations of a parallel step have distinct destinations and the indices are in \( A \), an audit; the colors of adjacent items differ and the independent sets are independent, audits; the files share the memory, which is at least \( 3 B \), and the outputs are empty. The functions are defined in ListRanking.tpp.