ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
InterleavedRankSelect.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------- File InterleavedRankSelect.h ----------------------*/
3/*--------------------------------------------------------------------------*/
62/*--------------------------------------------------------------------------*/
63/*----------------------------- DEFINITIONS --------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66#ifndef __ADS_InterleavedRankSelect
67 #define __ADS_InterleavedRankSelect
68/* self-identification: #endif constant */
69
70/*--------------------------------------------------------------------------*/
71/*------------------------------ INCLUDES ----------------------------------*/
72/*--------------------------------------------------------------------------*/
73
74#include "ADS/Contract.h"
77
78#include <algorithm>
79#include <bit>
80#include <cstddef>
81#include <cstdint>
82#include <span>
83#include <string_view>
84#include <vector>
85
86/*--------------------------------------------------------------------------*/
87/*--------------------------- NAMESPACE ------------------------------------*/
88/*--------------------------------------------------------------------------*/
89
90namespace ADS
91{
92
93/*--------------------------------------------------------------------------*/
94/*----------------------- CLASS InterleavedRankSelect ----------------------*/
95/*--------------------------------------------------------------------------*/
96
100{
101
102/*--------------------------------------------------------------------------*/
103 public:
106
108 explicit InterleavedRankSelect( const BitVector & b );
109
113 InterleavedRankSelect( std::span< const Word > w , std::size_t n );
114
116 [[nodiscard]] std::size_t size( void ) const { return( f_n ); }
117
119 [[nodiscard]] std::size_t ones( void ) const { return( f_ones ); }
120
122 [[nodiscard]] std::size_t zeros( void ) const { return( f_n - f_ones ); }
123
126 [[nodiscard]] bool operator[]( std::size_t i ) const;
127
143 [[nodiscard]] std::size_t rank1( std::size_t i ) const;
144
148 [[nodiscard]] std::size_t rank0( std::size_t i ) const {
149 return( i - rank1( i ) );
150 }
151
181 [[nodiscard]] std::size_t select1( std::size_t k ) const;
182
187 [[nodiscard]] std::size_t select0( std::size_t k ) const;
188
191 [[nodiscard]] std::size_t directoryBits( void ) const;
192
193/*----------------------------- THE PERSISTENCE ----------------------------*/
194
196 static constexpr std::string_view persistName = "InterleavedRankSelect";
197
199 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
200 return( detail::persistMix( { kData , kLines , kSample } ) );
201 }
202
205 template< class A >
206 void persist( A & a );
207
208/*--------------------------------------------------------------------------*/
209 private:
210 static constexpr std::size_t kData = 496;
211 static constexpr std::size_t kLines = 128;
212 static constexpr std::size_t kSample = 8192;
213
215 void build( const Word * w , std::size_t n );
216
218 [[nodiscard]] std::size_t before( std::size_t l ) const {
219 return( std::size_t( f_S[ l / kLines ] ) +
220 std::size_t( f_L[ 8 * l ] & 0xFFFF ) );
221 }
222
224 [[nodiscard]] std::size_t inLine( std::size_t l , unsigned p ) const;
225
227 [[nodiscard]] std::size_t select( std::size_t k , bool b ) const;
228
230 [[nodiscard]] bool consistent( void ) const;
231
232 std::size_t f_n = 0 , f_ones = 0;
233 std::vector< Word , detail::LineAllocator< Word > > f_L;
235 std::vector< std::uint64_t , MappableAllocator< std::uint64_t > > f_S;
237 std::vector< std::uint32_t , MappableAllocator< std::uint32_t > > f_sl[ 2 ];
239 std::vector< std::uint64_t , MappableAllocator< std::uint64_t > > f_sc[ 2 ];
240
241 }; // end( class InterleavedRankSelect )
242
243/*--------------------------------------------------------------------------*/
244
245} // end( namespace ADS )
246
247/*--------------------------------------------------------------------------*/
248/*-------------------------- IMPLEMENTATION --------------------------------*/
249/*--------------------------------------------------------------------------*/
250
251#include "ADS/succinct/impl/InterleavedRankSelect.tpp"
252
253/*--------------------------------------------------------------------------*/
254
255#endif /* InterleavedRankSelect.h included */
256
257/*--------------------------------------------------------------------------*/
258/*-------------------- End File InterleavedRankSelect.h --------------------*/
259/*--------------------------------------------------------------------------*/
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
std::size_t rank0(std::size_t i) const
the number of 0s in the places , i.e.,
Definition InterleavedRankSelect.h:148
InterleavedRankSelect(void)
the directory of no bit
Definition InterleavedRankSelect.h:105
bool operator[](std::size_t i) const
the bit
std::size_t zeros(void) const
the number of 0s
Definition InterleavedRankSelect.h:122
std::size_t size(void) const
the number of bits,
Definition InterleavedRankSelect.h:116
InterleavedRankSelect(std::span< const Word > w, std::size_t n)
the directory of the bits of the words , laid out with them
static constexpr std::uint64_t persistTag(void)
the parameters of the layout of the lines, in a file
Definition InterleavedRankSelect.h:199
std::size_t directoryBits(void) const
the bits of the counts in the lines, of the superblocks and of the samples, beyond the bits
InterleavedRankSelect(const BitVector &b)
the directory of the bits , laid out with them
std::size_t ones(void) const
the number of 1s
Definition InterleavedRankSelect.h:119
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t select1(std::size_t k) const
the place of the -th 1
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition InterleavedRankSelect.h:196
std::size_t rank1(std::size_t i) const
the number of 1s in the places
std::size_t select0(std::size_t k) const
the place of the -th 0, by the select of select1() above on the complemented words
int select(Word x, int r)
the place of the 1 of rank of , from 0
Definition ADT.h:96
std::uint64_t Word
a word of 64 bits
Definition Bitwise.h:73