ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::BVGraph Class Reference

a static directed graph with the lists compressed by reference, copy blocks, intervals and gaps More...

#include <ADS/succinct/BVGraph.h>

Public types

using List = std::vector< std::size_t >
 an adjacency list, strictly increasing
using Interval = std::pair< std::size_t , std::size_t >
 an interval of extra nodes, its left extreme and its length

Public member functions

 BVGraph (void)=default
 the graph with no node
 BVGraph (const std::vector< List > &a, std::size_t w=7, std::size_t r=3, std::size_t lmin=4)
 the graph of the adjacency lists \( a \), with the window \( w \), chains of references at most \( r \) long and intervals at least \( \mathit{lmin} \) long
std::size_t order (void) const
 the number of nodes, \( n \)
std::size_t edges (void) const
 the number of edges, \( m \)
std::size_t outdegree (std::size_t x) const
 the number of successors of \( x \), the first code of its list
List successors (std::size_t x) const
 the successors of \( x \), in increasing order
std::size_t reference (std::size_t x) const
 the reference of \( x \), 0 for none
std::size_t codeBits (void) const
 the bits of the lists
std::size_t sizeInBits (void) const
 the bits of the lists and of their places
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]

Static public member functions

static BitVector copyList (const List &s, const List &ref)
 the copy list of \( s \) against the reference list ref: a bit per item of ref, 1 if it is in \( s \) (found by a binary search)
static std::pair< bool, std::vector< std::size_t > > copyBlocks (const BitVector &c)
 the copy blocks of the copy list \( c \): its first bit and the lengths less 1 of its runs but the last
static std::pair< std::vector< Interval >, List > intervals (const List &e, std::size_t lmin)
 the runs of at least \( \mathit{lmin} \) consecutive integers of the strictly increasing \( e \), and the residuals
static std::vector< std::uint64_t > residualGaps (const List &res, std::size_t x)
 the residuals res of \( x \) as written: the first as signedToNatural() of its difference from \( x \), the others as the gaps less 1, \( \mathit{res}[ i ] - \mathit{res}[ i - 1 ] - 1 \)

Static public attributes

static constexpr std::string_view persistName = "BVGraph"
 the name of the structure in a file [see Persistence.h]

Detailed description

a static directed graph with the lists compressed by reference, copy blocks, intervals and gaps

Member typedef documentation

◆ Interval

using ADS::BVGraph::Interval = std::pair< std::size_t , std::size_t >

an interval of extra nodes, its left extreme and its length

◆ List

using ADS::BVGraph::List = std::vector< std::size_t >

an adjacency list, strictly increasing

Constructor and destructor documentation

◆ BVGraph() [1/2]

ADS::BVGraph::BVGraph ( void )
default

the graph with no node

◆ BVGraph() [2/2]

ADS::BVGraph::BVGraph ( const std::vector< List > & a,
std::size_t w = 7,
std::size_t r = 3,
std::size_t lmin = 4 )
explicit

the graph of the adjacency lists \( a \), with the window \( w \), chains of references at most \( r \) long and intervals at least \( \mathit{lmin} \) long

In pseudocode (Boldi and Vigna, beyond the book), the list \( S \) of each node \( x \) in turn, \( \gamma( v ) \) and \( \delta( v ) \) the codes of \( v + 1 \), \( \zeta( v ) \) for signedToNatural(), and \( \mathit{chain}[ x ] \) the length of the chain of references of \( x \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{encode}( x , S ) \cr 2 & \quad \mathit{start}[ x ] \gets \text{the bits written so far}; \ \text{write } \gamma( |S| ) \cr 3 & \quad \textbf{if}\ S = ()\ \textbf{then return} \cr 4 & \quad b \gets \text{the } k \in [ 1 , \min\{ w , x \} ] \text{ with } \mathit{chain}[ x - k ] < r \text{ and the most items of } a[ x - k ] \text{ in } S \text{, 0 if none} \cr 5 & \quad \text{write } \gamma( b );\ E \gets S \cr 6 & \quad \textbf{if}\ b > 0\ \textbf{then} \cr 7 & \qquad ( f , \mathit{len} ) \gets \mathrm{copyBlocks}( \mathrm{copyList}( S , a[ x - b ] ) ) \cr 8 & \qquad \text{write } \gamma( |\mathit{len}| ) \text{, the bit } f \text{, and } \gamma( l ) \text{ for each } l \in \mathit{len} \cr 9 & \qquad E \gets S \setminus a[ x - b ];\ \mathit{chain}[ x ] \gets \mathit{chain}[ x - b ] + 1 \cr 10 & \quad ( I , \mathit{res} ) \gets \mathrm{intervals}( E , \mathit{lmin} );\ \text{write } \gamma( |I| ) \cr 11 & \quad \textbf{foreach}\ ( \mathit{left} , \mathit{len} ) \in I \ \textbf{do} \cr 12 & \qquad \text{write } \gamma( \zeta( \mathit{left} - x ) ) \text{ for the first, } \gamma( \mathit{left} - \mathit{right} - 2 ) \text{ for the others} \cr 13 & \qquad \text{write } \gamma( \mathit{len} - \mathit{lmin} ); \ \mathit{right} \gets \mathit{left} + \mathit{len} - 1 \cr 14 & \quad \textbf{foreach}\ g \in \mathrm{residualGaps}( \mathit{res} , x )\ \textbf{do}\ \text{write } \delta( g ) \end{array}} \]

Precondition
each \( a[ u ] \) strictly increasing in \( [ 0 , n ) \), \( w , r \ge 1 \) and \( \mathit{lmin} \ge 2 \)

Member function documentation

◆ codeBits()

std::size_t ADS::BVGraph::codeBits ( void ) const
nodiscard

the bits of the lists

◆ copyBlocks()

std::pair< bool, std::vector< std::size_t > > ADS::BVGraph::copyBlocks ( const BitVector & c)
staticnodiscard

the copy blocks of the copy list \( c \): its first bit and the lengths less 1 of its runs but the last

In pseudocode (Boldi and Vigna, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{copyBlocks}( c ) \cr 2 & \quad \textbf{if}\ c = ()\ \textbf{then return}\ ( 0 , () ) \cr 3 & \quad \mathit{len} \gets ();\ \mathit{run} \gets 1 \cr 4 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ |c| - 1\ \textbf{do} \cr 5 & \qquad \textbf{if}\ c[ i ] = c[ i - 1 ]\ \textbf{then} \ \mathit{run} \gets \mathit{run} + 1 \cr 6 & \qquad \textbf{else}\ \text{append } \mathit{run} - 1 \text{ to } \mathit{len};\ \mathit{run} \gets 1 \cr 7 & \quad \textbf{return}\ ( c[ 0 ] , \mathit{len} )\quad \triangleright\ \text{the last run omitted} \end{array}} \]

◆ copyList()

BitVector ADS::BVGraph::copyList ( const List & s,
const List & ref )
staticnodiscard

the copy list of \( s \) against the reference list ref: a bit per item of ref, 1 if it is in \( s \) (found by a binary search)

◆ edges()

std::size_t ADS::BVGraph::edges ( void ) const
nodiscard

the number of edges, \( m \)

◆ intervals()

std::pair< std::vector< Interval >, List > ADS::BVGraph::intervals ( const List & e,
std::size_t lmin )
staticnodiscard

the runs of at least \( \mathit{lmin} \) consecutive integers of the strictly increasing \( e \), and the residuals

In pseudocode (Boldi and Vigna, beyond the book), by maximal runs:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{intervals}( e , \mathit{lmin} ) \cr 2 & \quad I \gets ();\ \mathit{res} \gets ();\ i \gets 0 \cr 3 & \quad \textbf{while}\ i < |e|\ \textbf{do} \cr 4 & \qquad j \gets i + 1;\ \textbf{while}\ j < |e|\ \textbf{and}\ e[ j ] = e[ j - 1 ] + 1\ \textbf{do}\ j \gets j + 1 \cr 5 & \qquad \textbf{if}\ j - i \ge \mathit{lmin}\ \textbf{then} \ \text{append } ( e[ i ] , j - i ) \text{ to } I \cr 6 & \qquad \textbf{else}\ \text{append } e[ i .. j - 1 ] \text{ to } \mathit{res} \cr 7 & \qquad i \gets j \cr 8 & \quad \textbf{return}\ ( I , \mathit{res} ) \end{array}} \]

◆ order()

std::size_t ADS::BVGraph::order ( void ) const
nodiscard

the number of nodes, \( n \)

◆ outdegree()

std::size_t ADS::BVGraph::outdegree ( std::size_t x) const
nodiscard

the number of successors of \( x \), the first code of its list

Precondition
\( x < \mathrm{order}() \)

◆ persist()

template<class A>
void ADS::BVGraph::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ reference()

std::size_t ADS::BVGraph::reference ( std::size_t x) const
nodiscard

the reference of \( x \), 0 for none

Precondition
\( x < \mathrm{order}() \)

◆ residualGaps()

std::vector< std::uint64_t > ADS::BVGraph::residualGaps ( const List & res,
std::size_t x )
staticnodiscard

the residuals res of \( x \) as written: the first as signedToNatural() of its difference from \( x \), the others as the gaps less 1, \( \mathit{res}[ i ] - \mathit{res}[ i - 1 ] - 1 \)

◆ sizeInBits()

std::size_t ADS::BVGraph::sizeInBits ( void ) const
nodiscard

the bits of the lists and of their places

◆ successors()

List ADS::BVGraph::successors ( std::size_t x) const
nodiscard

the successors of \( x \), in increasing order

In pseudocode (Boldi and Vigna, beyond the book), reading the codes that BVGraph() writes, from \( \mathit{start}[ x ] \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{successors}( x ) \cr 2 & \quad d \gets \text{the outdegree};\ \textbf{if}\ d = 0 \ \textbf{then return}\ () \cr 3 & \quad S \gets ();\ b \gets \text{the reference} \cr 4 & \quad \textbf{if}\ b > 0\ \textbf{then} \cr 5 & \qquad T \gets \mathrm{successors}( x - b );\ f \gets \text{the } \text{first bit} \cr 6 & \qquad \textbf{foreach}\ \text{block, of the length read or of the } \text{rest of } T \text{ for the last}\ \textbf{do} \cr 7 & \qquad\quad \textbf{if}\ f = 1\ \textbf{then}\ \text{append the } \text{next items of } T \text{ to } S\ \textbf{else}\ \text{skip } \text{them} \cr 8 & \qquad\quad f \gets 1 - f \cr 9 & \quad \textbf{foreach}\ \text{interval read}\ \textbf{do} \ \text{append its integers to } S \cr 10 & \quad \textbf{while}\ |S| < d\ \textbf{do}\ \text{append the next } \text{residual, from its gap, to } S \cr 11 & \quad \textbf{return}\ S \text{ sorted} \end{array}} \]

Precondition
\( x < \mathrm{order}() \)

Member data documentation

◆ persistName

std::string_view ADS::BVGraph::persistName = "BVGraph"
staticconstexpr

the name of the structure in a file [see Persistence.h]


The documentation for this class was generated from the following file: