ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RRRBitVector.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File RRRBitVector.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
65/*--------------------------------------------------------------------------*/
66/*----------------------------- DEFINITIONS --------------------------------*/
67/*--------------------------------------------------------------------------*/
68
69#ifndef __ADS_RRRBitVector
70 #define __ADS_RRRBitVector
71/* self-identification: #endif constant */
72
73/*--------------------------------------------------------------------------*/
74/*------------------------------ INCLUDES ----------------------------------*/
75/*--------------------------------------------------------------------------*/
76
77#include "ADS/Contract.h"
80
81#include <array>
82#include <bit>
83#include <cstddef>
84#include <cstdint>
85#include <string_view>
86#include <vector>
87
88/*--------------------------------------------------------------------------*/
89/*--------------------------- NAMESPACE ------------------------------------*/
90/*--------------------------------------------------------------------------*/
91
92namespace ADS
93{
94
95/*--------------------------------------------------------------------------*/
96/*--------------------------- CLASS RRRBitVector ---------------------------*/
97/*--------------------------------------------------------------------------*/
98
101{
102
103/*--------------------------------------------------------------------------*/
104 public:
107
129 explicit RRRBitVector( const BitVector & b );
130
132 [[nodiscard]] std::size_t size( void ) const { return( f_m ); }
133
135 [[nodiscard]] std::size_t ones( void ) const { return( f_ones ); }
136
138 [[nodiscard]] std::size_t zeros( void ) const { return( f_m - f_ones ); }
139
143 [[nodiscard]] bool operator[]( std::size_t i ) const;
144
170 [[nodiscard]] std::size_t rank1( std::size_t i ) const;
171
175 [[nodiscard]] std::size_t rank0( std::size_t i ) const {
176 return( i - rank1( i ) );
177 }
178
202 [[nodiscard]] std::size_t select1( std::size_t k ) const;
203
209 [[nodiscard]] std::size_t select0( std::size_t k ) const;
210
212 [[nodiscard]] std::size_t sizeInBits( void ) const;
213
214/*----------------------------- THE PERSISTENCE ----------------------------*/
215
217 static constexpr std::string_view persistName = "RRRBitVector";
218
220 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
221 return( detail::persistMix( { std::uint64_t( kB ) , kSuper } ) );
222 }
223
226 template< class A >
227 void persist( A & a );
228
229/*--------------------------------------------------------------------------*/
230 private:
231 static constexpr int kB = 63;
232 static constexpr std::size_t kSuper = 32;
233
235 struct Tables
236 {
238 std::array< std::array< std::uint64_t , 64 > , 64 > C{};
240 std::array< std::uint8_t , 64 > len{};
241 };
242 static const Tables & tables( void );
243
245 static std::uint64_t offset( std::uint64_t x , int c );
246
249 static int below( std::uint64_t o , int c , int q );
250
252 [[nodiscard]] std::uint64_t locate( std::size_t j , int & c ,
253 std::size_t & ones ) const;
254
256 [[nodiscard]] int cls( std::size_t j ) const {
257 return( int( f_cls.get( 6 * j , 6 ) ) );
258 }
259
261 [[nodiscard]] std::size_t select( std::size_t k , bool b ) const;
262
263 std::size_t f_m = 0 , f_ones = 0;
264 BitVector f_cls;
265 BitVector f_off;
266 BitVector f_rank;
267 BitVector f_ptr;
268 int f_wr = 1 , f_wp = 1;
269
270 }; // end( class RRRBitVector )
271
272/*--------------------------------------------------------------------------*/
273
274} // end( namespace ADS )
275
276/*--------------------------------------------------------------------------*/
277/*-------------------------- IMPLEMENTATION --------------------------------*/
278/*--------------------------------------------------------------------------*/
279
280#include "ADS/succinct/impl/RRRBitVector.tpp"
281
282/*--------------------------------------------------------------------------*/
283
284#endif /* RRRBitVector.h included */
285
286/*--------------------------------------------------------------------------*/
287/*------------------------ End File RRRBitVector.h -------------------------*/
288/*--------------------------------------------------------------------------*/
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
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition RRRBitVector.h:217
std::size_t rank1(std::size_t i) const
the number of 1s in the places
std::size_t ones(void) const
the number of 1s
Definition RRRBitVector.h:135
RRRBitVector(const BitVector &b)
the bits of , compressed
std::size_t size(void) const
the number of bits,
Definition RRRBitVector.h:132
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t rank0(std::size_t i) const
the number of 0s in the places , i.e.,
Definition RRRBitVector.h:175
std::size_t sizeInBits(void) const
the bits of the classes, of the offsets and of the superblocks
bool operator[](std::size_t i) const
the bit , i.e., whether the rank changes past it within its block
RRRBitVector(void)
the vector of no bit
Definition RRRBitVector.h:106
static constexpr std::uint64_t persistTag(void)
the parameters of the layout of the blocks, in a file
Definition RRRBitVector.h:220
std::size_t select1(std::size_t k) const
the place of the -th 1
std::size_t zeros(void) const
the number of 0s
Definition RRRBitVector.h:138
std::size_t select0(std::size_t k) const
the place of the -th 0, as select1() above with the 0s of each block counted as its length less its c...
Definition ADT.h:96