the positions of objects of type T, by their addresses
More...
#include <ADS/dictionary/PositionIndex.h>
|
| using | Position = std::uint32_t |
| | the type of the positions
|
|
| | PositionIndex (std::size_t n=0, H h=H()) |
| | an empty index with room for \( n \) keys
|
| Position | find (const T *p) const |
| | the position of \( p \), NONE if absent
|
| bool | contains (const T *p) const |
| | true if \( p \) is in the index
|
| bool | insert (const T *p, Position i) |
| | gives \( p \) the position \( i \); true if \( p \) was absent, false if its position was replaced
|
| bool | erase (const T *p) |
| | removes \( p \); false if it was absent
|
| template<std::ranges::random_access_range R> |
| void | assign (const R &v) |
| | the index of the vector \( v \) of pointers (any range with \( v[ i ] \)): \( v[ i ] \) at the position \( i \), all the other keys gone
|
| void | renumber (std::span< const Position > E) |
| | the erasure of the positions \( E \) from the vector: the keys at a position in \( E \) go away, and each other position \( p \) becomes \( p - |\{ e \in E : e < p \}| \)
|
| std::size_t | size (void) const |
| | the number of keys
|
| bool | empty (void) const |
| | true if there are no keys
|
| std::size_t | capacity (void) const |
| | the number of places of the table
|
| void | reserve (std::size_t n) |
| | room for \( n \) keys with no rebuild
|
| void | clear (void) |
| | removes all the keys, keeping the places
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( p , i ) for each key \( p \) at the position \( i \), in the order of the places
|
| void | swap (PositionIndex &o) noexcept |
| | exchanges the contents with o in \( O( 1 ) \)
|
|
| static constexpr Position | NONE = std::numeric_limits< Position >::max() |
| | the position of a key absent
|
template<class T, class H = FastHash< const T * >>
class ADS::PositionIndex< T, H >
the positions of objects of type T, by their addresses
◆ Position
template<class T, class H = FastHash< const T * >>
the type of the positions
◆ PositionIndex()
template<class T, class H = FastHash< const T * >>
an empty index with room for \( n \) keys
◆ assign()
template<class T, class H = FastHash< const T * >>
template<std::ranges::random_access_range R>
the index of the vector \( v \) of pointers (any range with \( v[ i ] \)): \( v[ i ] \) at the position \( i \), all the other keys gone
- Precondition
- no \( v[ i ] \) is nil, and \( v \) has fewer than NONE items
◆ capacity()
template<class T, class H = FastHash< const T * >>
the number of places of the table
◆ clear()
template<class T, class H = FastHash< const T * >>
removes all the keys, keeping the places
◆ contains()
template<class T, class H = FastHash< const T * >>
true if \( p \) is in the index
◆ empty()
template<class T, class H = FastHash< const T * >>
true if there are no keys
◆ erase()
template<class T, class H = FastHash< const T * >>
removes \( p \); false if it was absent
◆ find()
template<class T, class H = FastHash< const T * >>
the position of \( p \), NONE if absent
◆ forEach()
template<class T, class H = FastHash< const T * >>
template<class F>
f( p , i ) for each key \( p \) at the position \( i \), in the order of the places
◆ insert()
template<class T, class H = FastHash< const T * >>
gives \( p \) the position \( i \); true if \( p \) was absent, false if its position was replaced
- Precondition
- \( p \) is not nil and \( i < \) NONE
◆ renumber()
template<class T, class H = FastHash< const T * >>
the erasure of the positions \( E \) from the vector: the keys at a position in \( E \) go away, and each other position \( p \) becomes \( p - |\{ e \in E : e < p \}| \)
In pseudocode (beyond the book, the rank by the counts of the words of Jacobson), \( B \) the bit vector of \( E \), \( w_j \) its words of 64 bits and \( r_j \) the number of 1s in \( w_0 , \ldots , w_{j-1} \), \( N = \max E + 1 \) and \( m = |E| \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{renumber}( E ) \cr
2 & \quad \text{build } B \text{ and the counts } r_j \cr
3 & \quad D \gets \emptyset \cr
4 & \quad \textbf{foreach}\ ( k , p ) \text{ in the order of the places}
\ \textbf{do} \cr
5 & \qquad \textbf{if}\ p \ge N\ \textbf{then}\ p \gets p - m \cr
6 & \qquad \textbf{else} \cr
7 & \qquad\quad \textbf{if}\ B[ p ] = 1\ \textbf{then}\ D \gets D \cup
\{ k \} \cr
8 & \qquad\quad p \gets p - r_{\lfloor p / 64 \rfloor} -
\mathrm{popcount}( w_{\lfloor p / 64 \rfloor} \bmod 2^{p \bmod 64} )
\cr
9 & \quad \textbf{foreach}\ k \in D\ \textbf{do}\ \mathrm{remove}( k )
\end{array}}
\]
- Precondition
- \( E \) is strictly increasing
◆ reserve()
template<class T, class H = FastHash< const T * >>
room for \( n \) keys with no rebuild
◆ size()
template<class T, class H = FastHash< const T * >>
◆ swap()
template<class T, class H = FastHash< const T * >>
exchanges the contents with o in \( O( 1 ) \)
◆ NONE
template<class T, class H = FastHash< const T * >>
the position of a key absent
The documentation for this class was generated from the following file: