ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RowFingerprint.h

The fingerprints of the rows of doubles, beyond the book. More...

Files

file  ADS/dictionary/RowFingerprint.h
 The fingerprints of the rows of doubles, beyond the book: a hash of 64 bits of a dense row \( ( x_0 , \dots , x_{n-1} ) \) or of a sparse one, its indices and values \( ( j_k , v_k ) \) in their order, for finding the rows already seen, e.g., a cut generated twice, by a table of the fingerprints; sameRow() then tells whether two rows with the same fingerprint are really equal.

Functions

std::uint64_t ADS::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 ADS::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 ADS::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 ADS::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 ADS::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

Detailed description

The fingerprints of the rows of doubles, beyond the book.

The definitions, the invariants and the costs of the area are in Theory of dictionaries.

Function documentation

◆ canonicalWord()

std::uint64_t ADS::canonicalWord ( double x)
inlinenodiscard

the canonical word of \( x \): 0 for \( +0 \) and \( -0 \), one quiet NaN for every NaN, the bits of \( x \) otherwise

◆ rowFingerprint() [1/2]

template<class I>
std::uint64_t ADS::rowFingerprint ( std::size_t n,
const I * ind,
const double * val,
std::uint64_t seed = 0 )
nodiscard

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

Precondition
ind and val are not nil if \( n > 0 \)

◆ rowFingerprint() [2/2]

std::uint64_t ADS::rowFingerprint ( std::span< const double > x,
std::uint64_t seed = 0 )
nodiscard

the fingerprint of the dense row \( x \) under the seed

In pseudocode (beyond the book), the canonical words hashed a block of 64 at a time, each block seeded by the hash of the one before:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rowFingerprint}( x , h ) \cr 2 & \quad \textbf{if}\ n = 0\ \textbf{then return}\ \mathrm{hashBytes}( \text{nothing} , h ) \cr 3 & \quad \textbf{foreach}\ \text{block } x_i , \ldots , x_{i + 63} \text{ of } x\ \textbf{do} \cr 4 & \qquad b \gets ( \mathrm{canonicalWord}( x_i ) , \ldots , \mathrm{canonicalWord}( x_{i + 63} ) ) \cr 5 & \qquad h \gets \mathrm{hashBytes}( b , h ) \cr 6 & \quad \textbf{return}\ h \end{array}} \]

◆ sameRow() [1/2]

template<class I>
bool ADS::sameRow ( std::size_t na,
const I * ia,
const double * va,
std::size_t nb,
const I * ib,
const double * vb )
nodiscard

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

Precondition
the pointers are not nil where there are entries

◆ sameRow() [2/2]

bool ADS::sameRow ( std::span< const double > a,
std::span< const double > b )
nodiscard

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

In pseudocode (beyond the book), the bytes first, which settle the common case of two copies of a row:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{sameRow}( a , b ) \cr 2 & \quad \textbf{if}\ |a| \ne |b|\ \textbf{then return false} \cr 3 & \quad \textbf{if}\ \text{the bytes of } a \text{ and } b \text{ are } \text{equal}\ \textbf{then return true} \cr 4 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ |a| - 1\ \textbf{do} \cr 5 & \qquad \textbf{if}\ a_i \ne b_i\ \textbf{and not}\ ( a_i \text{ and } b_i \text{ are NaN} )\ \textbf{then return false} \cr 6 & \quad \textbf{return true} \end{array}} \]