ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
FMIndex.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File FMIndex.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
84/*--------------------------------------------------------------------------*/
85/*----------------------------- DEFINITIONS --------------------------------*/
86/*--------------------------------------------------------------------------*/
87
88#ifndef __ADS_FMIndex
89 #define __ADS_FMIndex
90/* self-identification: #endif constant */
91
92/*--------------------------------------------------------------------------*/
93/*------------------------------ INCLUDES ----------------------------------*/
94/*--------------------------------------------------------------------------*/
95
96#include "ADS/Contract.h"
99
100#include <algorithm>
101#include <array>
102#include <bit>
103#include <cstddef>
104#include <cstdint>
105#include <cstring>
106#include <string>
107#include <string_view>
108#include <utility>
109#include <vector>
110
111/*--------------------------------------------------------------------------*/
112/*--------------------------- NAMESPACE ------------------------------------*/
113/*--------------------------------------------------------------------------*/
114
115namespace ADS
116{
117
118/*--------------------------------------------------------------------------*/
119/*----------------------------- CLASS FMIndex ------------------------------*/
120/*--------------------------------------------------------------------------*/
121
126{
127
128/*--------------------------------------------------------------------------*/
129 public:
131 FMIndex( void ) : FMIndex( std::string_view() ) { }
132
154 explicit FMIndex( std::string_view s , std::size_t b = 64 ,
155 std::size_t mu = 32 );
156
158 [[nodiscard]] std::size_t size( void ) const { return( f_n ); }
159
161 [[nodiscard]] BWT transform( void ) const;
162
182 [[nodiscard]] std::size_t rank( char c , std::size_t k ) const;
183
205 [[nodiscard]] std::pair< std::size_t , std::size_t >
206 range( std::string_view P ) const;
207
218 [[nodiscard]] std::size_t count( std::string_view P ) const;
219
241 [[nodiscard]] std::vector< std::size_t > locate( std::string_view P ) const;
242
263 [[nodiscard]] std::string extract( std::size_t i , std::size_t j ) const;
264
267 [[nodiscard]] std::size_t sizeInBits( void ) const;
268
269/*----------------------------- THE PERSISTENCE ----------------------------*/
270
272 static constexpr std::string_view persistName = "FMIndex";
273
276 template< class A >
277 void persist( A & a );
278
279/*--------------------------------------------------------------------------*/
280 private:
284 [[nodiscard]] std::size_t lf( std::size_t r ) const;
285
287 [[nodiscard]] std::size_t place( std::size_t r ) const;
288
290 [[nodiscard]] bool marked( std::size_t r ) const { return( f_mark[ r ] ); }
291
292 std::size_t f_n , f_b , f_mu;
293 std::string f_L;
294 std::size_t f_dollar;
295 std::array< std::size_t , 257 > f_C;
296 std::array< int , 256 > f_id;
297 std::size_t f_sigma = 0;
298 std::vector< std::uint32_t > f_occ;
299 RankSelect f_mark;
300 std::vector< std::size_t > f_place;
301 std::vector< std::size_t > f_row;
302
303 }; // end( class FMIndex )
304
305/*--------------------------------------------------------------------------*/
306
307} // end( namespace ADS )
308
309/*--------------------------------------------------------------------------*/
310/*-------------------------- IMPLEMENTATION --------------------------------*/
311/*--------------------------------------------------------------------------*/
312
313#include "ADS/compression/impl/FMIndex.tpp"
314
315/*--------------------------------------------------------------------------*/
316
317#endif /* FMIndex.h included */
318
319/*--------------------------------------------------------------------------*/
320/*--------------------------- End File FMIndex.h ---------------------------*/
321/*--------------------------------------------------------------------------*/
The transform of Burrows and Wheeler and the compressor built on it (chapter 14, Block-Sorting Compre...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Rank and select on a static vector of bits of bits with 1s (chapter 15, Compressed Data Structures...
std::pair< std::size_t, std::size_t > range(std::string_view P) const
the range of the rows of prefixed by , empty if none, by backward search
std::vector< std::size_t > locate(std::string_view P) const
the places of the occurrences of , in increasing order
FMIndex(std::string_view s, std::size_t b=64, std::size_t mu=32)
the index of
std::string extract(std::size_t i, std::size_t j) const
the substring
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t sizeInBits(void) const
the bits of the index: , the counts, the marks with their directory, the samples and the arrays of th...
std::size_t size(void) const
the length of the text
Definition FMIndex.h:158
std::size_t count(std::string_view P) const
the number of the occurrences of
BWT transform(void) const
the transform of the text
std::size_t rank(char c, std::size_t k) const
the occurrences of in , the excluded
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition FMIndex.h:272
FMIndex(void)
the index of the empty text
Definition FMIndex.h:131
BasicRankSelect< false > RankSelect
the directory with its inventories of select built in the constructor, the fastest select
Definition RankSelect.h:556
Definition ADT.h:96
the transform of Burrows and Wheeler: the last column of without the , and the row of the
Definition BurrowsWheeler.h:127