the function of Czech, Havas and Majewski that maps \( \mathit{keys}[ i ] \) to \( i \)
More...
#include <ADS/dictionary/PerfectHashing.h>
|
| using | Key = K |
| | the type of the keys
|
|
| | OrderedMinimalPerfectHash (void) |
| | the function of no key
|
| | OrderedMinimalPerfectHash (const std::vector< K > &keys, int r=2, double c=0, std::uint64_t seed=1) |
| | the function of the distinct keys, on \( r = 2 \) or 3 functions and \( c n \) vertices; \( c = 0 \) stands for 3 if \( r = 2 \) and for 1.25 if \( r = 3 \)
|
| std::size_t | operator() (const K &k) const |
| | the value of \( k \), \( ( g( h_1( k ) ) + \cdots + g( h_r( k ) ) ) \bmod n \), in \( [ 0 , n ) \); anything in it for a key out of \( S \)
|
| std::size_t | size (void) const |
| | the number \( n \) of keys
|
| std::size_t | vertices (void) const |
| | the number \( m' \) of vertices, i.e., of values of \( g \)
|
| std::size_t | trials (void) const |
| | the graphs drawn by the build
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]
|
|
| static std::optional< std::vector< std::uint32_t > > | labelAcyclicGraph (std::size_t m, const std::vector< std::size_t > &E, const std::vector< std::size_t > &h, std::size_t n) |
| | the labeling of an acyclic graph: \( g \) on the \( m \) vertices such that \( g[ u ] + g[ v ] = h[ e ] \bmod n \) on each edge \( e = ( E[ 2 e ] , E[ 2 e + 1 ] ) \), each tree labeled from its least vertex with \( g = 0 \); nothing if a visit finds an edge that it cannot satisfy (a cycle whose values do not add up)
|
| static std::optional< std::vector< std::uint32_t > > | labelByPeeling (std::size_t m, const std::vector< std::size_t > &E, int r, const std::vector< std::size_t > &h, std::size_t n) |
| | \( g \) on the \( m \) vertices such that the \( g \) of the \( r \) vertices of each hyperedge \( e \) add up to \( h[ e ] \bmod n \), by the reverse order of the peeling; nothing if the hypergraph has a 2-core (is not peelable)
|
| static constexpr std::uint64_t | persistTag (void) |
| | the parameters of the layout, in a file
|
|
| static constexpr std::string_view | persistName = "OrderedMinimalPerfectHash" |
| | the name of the structure in a file [see Persistence.h]
|
template<class K>
requires ( std::integral< K > || std::convertible_to< const K & , std::string_view > )
class ADS::OrderedMinimalPerfectHash< K >
the function of Czech, Havas and Majewski that maps \( \mathit{keys}[ i ] \) to \( i \)
◆ Key
◆ OrderedMinimalPerfectHash() [1/2]
◆ OrderedMinimalPerfectHash() [2/2]
the function of the distinct keys, on \( r = 2 \) or 3 functions and \( c n \) vertices; \( c = 0 \) stands for 3 if \( r = 2 \) and for 1.25 if \( r = 3 \)
In pseudocode (Czech, Havas and Majewski, chapter 8 of Ferragina), the key \( t_i \) an edge of value \( i \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{build}( t_0 , \ldots , t_{n-1} ) \cr
2 & \quad \textbf{repeat} \cr
3 & \qquad h_1 , \ldots , h_r \gets \text{functions at random} \cr
4 & \qquad E \gets \{ ( h_1( t_i ) , \ldots , h_r( t_i ) ) : 0 \le i < n
\} \cr
5 & \qquad g \gets \mathrm{labelAcyclicGraph}( E )\ \text{(}r = 2
\text{) or } \mathrm{labelByPeeling}( E )\ \text{(}r = 3\text{)} \cr
6 & \quad \textbf{until}\ g \ne \textbf{nil}
\end{array}}
\]
- Precondition
- the keys are distinct (an audit) and fewer than \( 2^{32} \), \( r = 2 \) with \( c > 2 \) or \( r = 3 \) with \( c > 1.23 \) (or \( c = 0 \))
- Postcondition
- ( *this )( keys[ i ] ) == i for each \( i \) (an audit)
◆ labelAcyclicGraph()
template<class K>
| std::optional< std::vector< std::uint32_t > > ADS::OrderedMinimalPerfectHash< K >::labelAcyclicGraph |
( |
std::size_t | m, |
|
|
const std::vector< std::size_t > & | E, |
|
|
const std::vector< std::size_t > & | h, |
|
|
std::size_t | n ) |
|
staticnodiscard |
the labeling of an acyclic graph: \( g \) on the \( m \) vertices such that \( g[ u ] + g[ v ] = h[ e ] \bmod n \) on each edge \( e = ( E[ 2 e ] , E[ 2 e + 1 ] ) \), each tree labeled from its least vertex with \( g = 0 \); nothing if a visit finds an edge that it cannot satisfy (a cycle whose values do not add up)
In pseudocode (chapter 8 of Ferragina), a visit in depth of each tree with a stack:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{labelAcyclicGraph}( m , E , h , n ) \cr
2 & \quad \textbf{foreach}\ v\ \textbf{do}\ g[ v ] \gets \textbf{nil} \cr
3 & \quad \textbf{for}\ v_0 \gets 0\ \textbf{to}\ m - 1\ \textbf{with}\ g[
v_0 ] = \textbf{nil}\ \textbf{do} \cr
4 & \qquad g[ v_0 ] \gets 0;\ \mathrm{push}( S , v_0 ) \cr
5 & \qquad \textbf{while}\ S \ne \emptyset\ \textbf{do} \cr
6 & \qquad\quad v \gets \mathrm{pop}( S ) \cr
7 & \qquad\quad \textbf{foreach}\ \text{edge } e = ( v , u )\ \textbf{do}
\cr
8 & \qquad\qquad x \gets ( h[ e ] - g[ v ] ) \bmod n \cr
9 & \qquad\qquad \textbf{if}\ g[ u ] = \textbf{nil}\ \textbf{then}\ g[ u ]
\gets x;\ \mathrm{push}( S , u ) \cr
10 & \qquad\qquad \textbf{else if}\ g[ u ] \ne x\ \textbf{then return nil}
\cr
11 & \quad \textbf{return}\ g
\end{array}}
\]
- Precondition
- \( n \ge 1 \), \( E \) has \( 2 |h| \) vertices below \( m \)
- Postcondition
- every edge is satisfied, if a labeling is returned
◆ labelByPeeling()
template<class K>
| std::optional< std::vector< std::uint32_t > > ADS::OrderedMinimalPerfectHash< K >::labelByPeeling |
( |
std::size_t | m, |
|
|
const std::vector< std::size_t > & | E, |
|
|
int | r, |
|
|
const std::vector< std::size_t > & | h, |
|
|
std::size_t | n ) |
|
staticnodiscard |
\( g \) on the \( m \) vertices such that the \( g \) of the \( r \) vertices of each hyperedge \( e \) add up to \( h[ e ] \bmod n \), by the reverse order of the peeling; nothing if the hypergraph has a 2-core (is not peelable)
In pseudocode (Majewski, Wormald, Havas and Czech, beyond the book), a vertex of degree 1 knowing its edge as the XOR of the edges on it:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{labelByPeeling}( m , E , r , h , n ) \cr
2 & \quad Q \gets \text{the vertices of degree 1};\ O \gets \text{an }
\text{empty sequence} \cr
3 & \quad \textbf{while}\ Q \ne \emptyset\ \textbf{do} \cr
4 & \qquad v \gets \mathrm{dequeue}( Q ) \cr
5 & \qquad \textbf{if}\ v \text{ has degree 1 }\ \textbf{then} \cr
6 & \qquad\quad e \gets \text{the edge of } v;\ \text{append } ( e , v )
\text{ to } O \cr
7 & \qquad\quad \text{remove } e \text{, enqueueing the vertices left of }
\text{degree 1} \cr
8 & \quad \textbf{if}\ |O| < |h|\ \textbf{then return nil}\quad
\triangleright\ \text{a 2-core is left} \cr
9 & \quad \textbf{foreach}\ ( e , v ) \in O \text{ backwards}
\ \textbf{do}\ g[ v ] \gets ( h[ e ] - \sum_{u \in e , u \ne v} g[ u ]
)
\bmod n \cr
10 & \quad \textbf{return}\ g
\end{array}}
\]
Each vertex \( v \) is labeled after all the other vertices of its edge \( e \), which are removed later or never, and no edge labeled later contains \( v \); hence every edge is satisfied.
- Precondition
- \( n \ge 1 \), \( r \ge 2 \), \( E \) has \( r |h| \) vertices below \( m \), those of an edge distinct
- Postcondition
- every edge is satisfied, if a labeling is returned
◆ operator()()
the value of \( k \), \( ( g( h_1( k ) ) + \cdots + g( h_r( k ) ) ) \bmod n \), in \( [ 0 , n ) \); anything in it for a key out of \( S \)
- Precondition
- size() \( \ge 1 \)
◆ persist()
template<class K>
template<class A>
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistTag()
template<class K>
|
|
inlinestaticnodiscardconstexpr |
the parameters of the layout, in a file
◆ size()
the number \( n \) of keys
◆ trials()
the graphs drawn by the build
◆ vertices()
the number \( m' \) of vertices, i.e., of values of \( g \)
◆ persistName
The documentation for this class was generated from the following file: