|
ADS
Algorithms and Data Structures
|
the search by interpolation of a sorted array of strings by bins More...
#include <ADS/string/PrefixSearch.h>
Public member functions | |
| BinnedStringSearch (std::vector< std::string > A) | |
| the bins of the integers of the first 8 characters of \( A \), a BinnedSearch on them | |
| std::size_t | lexicographicPosition (std::string_view Q) const |
| the number of strings smaller than \( Q \) | |
| std::size_t | prefixEnd (std::string_view P) const |
| the number of strings smaller than \( P\# \) | |
| std::pair< std::size_t, std::size_t > | prefixRange (std::string_view P) const |
| the range \( [ l , r ) \) of the strings prefixed by \( P \), by lexicographicPosition() and prefixEnd() | |
| const BinnedSearch & | keys (void) const |
| the BinnedSearch of the integers of the strings | |
the search by interpolation of a sorted array of strings by bins
|
explicit |
the bins of the integers of the first 8 characters of \( A \), a BinnedSearch on them
|
nodiscard |
the BinnedSearch of the integers of the strings
|
nodiscard |
the number of strings smaller than \( Q \)
In pseudocode (Demaine, Jones and Pătrașcu, beyond the book), \( k( s ) \) the integer of the first 8 characters of \( s \), which keeps the order of the strings:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lexicographicPosition}( Q ) \cr 2 & \quad \textbf{if}\ n = 0\ \textbf{or}\ k( Q ) < k( A[ 0 ] ) \ \textbf{then return}\ 0 \cr 3 & \quad \textbf{if}\ k( Q ) > k( A[ n - 1 ] )\ \textbf{then return} \ n \cr 4 & \quad [ \mathit{lo} , \mathit{hi} ) \gets \text{the bin of } k( Q ) \cr 5 & \quad \textbf{return}\ \text{the first place } r \in [ \mathit{lo} , \mathit{hi} ) \text{ with } Q \le A[ r ] \text{ (or } \mathit{hi} \text{), by a binary search} \end{array}} \]
|
nodiscard |
the number of strings smaller than \( P\# \)
In pseudocode (Demaine, Jones and Pătrașcu, beyond the book), the search of lexicographicPosition() from the largest integer of a string prefixed by \( P \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{prefixEnd}( P ) \cr 2 & \quad \kappa \gets k( P ) \text{ with the bytes past } P \text{ set } \text{to } 255 \cr 3 & \quad \textbf{if}\ n = 0\ \textbf{or}\ \kappa < k( A[ 0 ] ) \ \textbf{then return}\ 0 \cr 4 & \quad \textbf{if}\ \kappa > k( A[ n - 1 ] )\ \textbf{then return} \ n \cr 5 & \quad [ \mathit{lo} , \mathit{hi} ) \gets \text{the bin of } \kappa \cr 6 & \quad \textbf{return}\ \text{the first place } r \in [ \mathit{lo} , \mathit{hi} ) \text{ with } A[ r ] \ge P\# \text{ (or } \mathit{hi} \text{)} \end{array}} \]
|
nodiscard |
the range \( [ l , r ) \) of the strings prefixed by \( P \), by lexicographicPosition() and prefixEnd()