ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Sdsl.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------------ File Sdsl.h -------------------------------*/
3/*--------------------------------------------------------------------------*/
45/*--------------------------------------------------------------------------*/
46/*----------------------------- DEFINITIONS --------------------------------*/
47/*--------------------------------------------------------------------------*/
48
49#ifndef __ADS_Sdsl
50 #define __ADS_Sdsl
51/* self-identification: #endif constant */
52
53/*--------------------------------------------------------------------------*/
54/*------------------------------ INCLUDES ----------------------------------*/
55/*--------------------------------------------------------------------------*/
56
57#include "ADS/Contract.h"
61
62#include <sdsl/int_vector.hpp>
63
64#include <cstddef>
65#include <cstdint>
66#include <cstring>
67#include <span>
68#include <stdexcept>
69
70/*--------------------------------------------------------------------------*/
71/*--------------------------- NAMESPACE ------------------------------------*/
72/*--------------------------------------------------------------------------*/
73
74namespace ADS
75{
76
77/*--------------------------------------------------------------------------*/
78/*------------------------------- FUNCTIONS --------------------------------*/
79/*--------------------------------------------------------------------------*/
80
83[[nodiscard]] inline sdsl::bit_vector toSdsl( const BitVector & b )
84{
85 sdsl::bit_vector v( b.size() , 0 );
86 if( b.size() > 0 )
87 std::memcpy( v.data() , b.words().data() ,
88 ( b.size() + 63 ) / 64 * sizeof( Word ) );
89 return( v );
90 }
91
94[[nodiscard]] inline BitVector toBitVector( const sdsl::bit_vector & v )
95{
96 if( v.size() == 0 )
97 return( BitVector() );
98 return( BitVector(
99 std::span< const Word >( v.data() , ( v.size() + 63 ) / 64 ) , v.size() ) );
100 }
101
104template< unsigned B , bool S >
105[[nodiscard]] sdsl::int_vector< B > toSdsl( const PackedArray< B , S > & a )
106{
107 sdsl::int_vector< B > v( a.size() , 0 , B );
108 if( a.size() > 0 )
109 std::memcpy( v.data() , a.words().data() ,
110 ( a.size() * B + 63 ) / 64 * sizeof( Word ) );
111 return( v );
112 }
113
120template< unsigned B , bool S = false , std::uint8_t W >
121[[nodiscard]] PackedArray< B , S >
122toPackedArray( const sdsl::int_vector< W > & v )
123{
124 using P = PackedArray< B , S >;
125 const std::size_t n = v.size();
126 if( v.width() == B ) {
127 if( n == 0 )
128 return( P() );
129 return( P( std::span< const Word >( v.data() , ( n * B + 63 ) / 64 ) , n ) );
130 }
131 if constexpr( ! S )
132 for( std::size_t i = 0 ; i < n ; ++i )
133 if( std::uint64_t( v[ i ] ) > P::MAX )
134 throw( std::invalid_argument( "ADS::toPackedArray: a field of the "
135 "int_vector of more bits than B" ) );
136 Sequential q;
137 return( P(
138 q , n ,
139 [ & ]( std::size_t i ) { return( typename P::Word( v[ i ] ) ); } ) );
140 }
141
142/*--------------------------------------------------------------------------*/
143
144} // end( namespace ADS )
145
146/*--------------------------------------------------------------------------*/
147
148#endif /* Sdsl.h included */
149
150/*--------------------------------------------------------------------------*/
151/*---------------------------- End File Sdsl.h -----------------------------*/
152/*--------------------------------------------------------------------------*/
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,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
Arrays of small unsigned integers packed in words, beyond the book:
a vector of bits packed in words of 64 bits
Definition BitVector.h:479
const Words & words(void) const
the words, the bits past the size being 0; they are at least , a multiple of 8, and start on a line o...
std::size_t size(void) const
the number of bits
unsigned fields of bits, to a word, the values above clamped to it if Saturate
Definition PackedArray.h:96
const std::vector< Word > & words(void) const
the words, the field in the word , the bits past the last field 0
Definition PackedArray.h:193
std::size_t size(void) const
the number of fields,
Definition PackedArray.h:152
the executor of the calling thread alone, which makes the calls in their order
Definition Executor.h:265
PackedArray< B, S > toPackedArray(const ArrowArray &a, const ArrowSchema &s)
the column of type copied into a PackedArray< B , S >: a column of booleans if ,...
Definition Arrow.h:567
BitVector toBitVector(const ArrowArray &a, const ArrowSchema &s)
the column of booleans of type copied into a BitVector; and are only read
Definition Arrow.h:539
sdsl::bit_vector toSdsl(const BitVector &b)
the bits of as a bit_vector of sdsl-lite, by a copy of the words
Definition Sdsl.h:83
Definition ADT.h:96
std::uint64_t Word
a word of 64 bits
Definition Bitwise.h:73