130#ifndef __ADS_RankSelect
131 #define __ADS_RankSelect
154#include <string_view>
155#include <type_traits>
254 template< Executor E >
260 template< Executor E >
283 [[nodiscard]] std::size_t
size(
void )
const;
290 [[nodiscard]] std::size_t
ones(
void )
const;
293 [[nodiscard]] std::size_t
zeros(
void )
const;
315 [[nodiscard]] std::size_t
rank1( std::size_t i )
const;
320 [[nodiscard]] std::size_t
rank0( std::size_t i )
const;
351 [[nodiscard]] std::size_t
select1( std::size_t k )
const;
358 [[nodiscard]] std::size_t
select0( std::size_t k )
const;
368 Lazy ?
"LazyRankSelect" :
"RankSelect";
371 [[nodiscard]]
static constexpr std::uint64_t
persistTag(
void ) {
372 return( detail::persistMix(
373 { kBlock , std::uint64_t( kRel ) , std::uint64_t( kTop ) , kGroup } ) );
414 static constexpr std::size_t kBlock = 256;
415 static constexpr int kRel = 8;
416 static constexpr std::size_t kQuarter = kBlock / 4;
417 static constexpr std::uint64_t kRelMask = ( std::uint64_t( 1 ) << kRel ) - 1;
420#ifndef ADS_RANKSELECT_TOP
421 static constexpr int kTop = 64 - 3 * kRel;
423 static constexpr int kTop = ADS_RANKSELECT_TOP;
427#ifndef ADS_RANKSELECT_FUSE
428 static constexpr std::size_t kFuse = std::size_t( 1 ) << 23;
430 static constexpr std::size_t kFuse = ADS_RANKSELECT_FUSE;
434#ifndef ADS_RANKSELECT_CHUNK
435 static constexpr std::size_t kChunk = 4096;
437 static constexpr std::size_t kChunk = ADS_RANKSELECT_CHUNK;
442 static constexpr std::size_t kGroup = 4096;
443 static constexpr std::size_t kSparse = std::size_t( 1 ) << 16;
457 std::vector< std::uint64_t , MappableAllocator< std::uint64_t > > pos;
459 std::vector< std::uint16_t , detail::LineAllocator< std::uint16_t > > off;
463 void persist( A & a ) {
464 a( l , g , s , pos , off );
469 [[nodiscard]] std::size_t before( std::size_t t ,
bool b )
const;
482 void shape(
bool b , Inventory & I , std::size_t & groups )
const;
485 const Inventory & inventory(
bool b )
const;
488 void build(
bool b )
const;
492 template< Executor E >
493 void directory( E & ex ,
Selects s ,
const Word * w );
497 template< Executor E >
498 void build( E & ex ,
bool b )
const;
503 void samples(
bool b , std::size_t t0 , std::size_t t1 ,
int e ,
504 std::size_t total , F && f )
const;
507 void first(
bool b )
const;
513 [[nodiscard]] std::size_t select( std::size_t k ,
bool b )
const;
517 [[nodiscard]] std::size_t selectSparse( std::size_t k ,
bool b ,
519 std::size_t q )
const;
522 [[nodiscard]]
bool consistent(
void )
const;
526 [[nodiscard]]
bool fits(
void )
const;
527 [[nodiscard]]
bool fits(
bool b )
const;
533 std::vector< std::uint64_t , detail::LineAllocator< std::uint64_t > > f_dir;
535 std::vector< std::uint64_t > f_top;
537 mutable Inventory f_inv[ 2 ];
538 bool f_has[ 2 ] = { true ,
true };
539 std::size_t f_ones = 0;
544 mutable std::once_flag flag[ 2 ];
546 mutable std::atomic< bool > ready[ 2 ] = { false ,
false };
571#include "ADS/succinct/impl/RankSelect.tpp"
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
The broadword tricks of Knuth (section 7.1.3 of The Art of Computer Programming), beyond the book: op...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
BasicRankSelect(void)
the directory of no bit
BasicRankSelect(const BasicRankSelect &o)
a copy, with the inventories that has built
const_iterator cbegin(void) const
the same as begin()
Definition RankSelect.h:407
SubscriptIterator< BasicRankSelect, bool > const_iterator
the constant iterator, random access
Definition RankSelect.h:394
std::size_t size_type
the type of a size
Definition RankSelect.h:386
BasicRankSelect(BitVector b, Selects s=Selects::BOTH)
the directory of the bits , which it keeps, with the selects
const_iterator cend(void) const
the same as end()
Definition RankSelect.h:409
~BasicRankSelect(void)=default
the directory and its bits released
static constexpr std::uint64_t persistTag(void)
the parameters of the layout of the directory, in a file
Definition RankSelect.h:371
static constexpr std::string_view persistName
Definition RankSelect.h:367
const_iterator iterator
the same as const_iterator
Definition RankSelect.h:396
const_iterator end(void) const
the iterator past the last item
Definition RankSelect.h:403
std::size_t rank0(std::size_t i) const
the number of 0s in the places , i.e.,
BasicRankSelect & operator=(const BasicRankSelect &o)
a copy, with the inventories that has built
std::size_t ones(void) const
the number of 1s
std::ptrdiff_t difference_type
the type of the distance of two places
Definition RankSelect.h:388
BasicRankSelect(BasicRankSelect &&o) noexcept
a move, with the inventories that has built
std::size_t zeros(void) const
the number of 0s
std::size_t select1(std::size_t k) const
the place of the -th 1
BasicRankSelect(E &ex, BitVector b, Selects s=Selects::BOTH)
the directory of BasicRankSelect( b , s ) above, the same entries and inventories,...
const BitVector & bits(void) const
the bits
bool value_type
the type of an item
Definition RankSelect.h:384
const_iterator begin(void) const
the iterator on the first item
Definition RankSelect.h:399
bool operator[](std::size_t i) const
the bit
bool const_reference
an item, returned by value
Definition RankSelect.h:392
std::size_t size(void) const
the number of bits,
std::size_t directoryBits(void) const
the bits of the directory, beyond those of the vector, with those of the inventories of the selects a...
BasicRankSelect(std::span< const Word > w, std::size_t n, Selects s=Selects::BOTH)
the directory of the bits of the words , copied as they are counted, with the selects
std::size_t rank1(std::size_t i) const
the number of 1s in the places
bool reference
an item, returned by value
Definition RankSelect.h:390
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
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
BasicRankSelect & operator=(BasicRankSelect &&o) noexcept
a move, with the inventories that has built
BasicRankSelect(E &ex, std::span< const Word > w, std::size_t n, Selects s=Selects::BOTH)
the directory of BasicRankSelect( w , n , s ) above, the words copied by the chunks that count them,...
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
the random-access constant iterator on the items T of the owner O, read by ( *o )[ i ]
Definition BitVector.h:372
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
BasicRankSelect< false > RankSelect
the directory with its inventories of select built in the constructor, the fastest select
Definition RankSelect.h:556
BasicRankSelect< true > LazyRankSelect
the directory with its inventories of select built at the first select of each value,...
Definition RankSelect.h:561
std::uint64_t Word
a word of 64 bits
Definition Bitwise.h:73
the values whose select a directory answers: a structure that needs only rank, or one of the selects,...
Definition RankSelect.h:173
Selects
the selects that a directory answers
Definition RankSelect.h:175
@ ZEROS
select0()
Definition RankSelect.h:178
@ BOTH
select1() and select0()
Definition RankSelect.h:179
@ NONE
no select, the rank only
Definition RankSelect.h:176
@ ONES
select1()
Definition RankSelect.h:177