ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
GrafiteFilter.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File GrafiteFilter.h --------------------------*/
3/*--------------------------------------------------------------------------*/
152/*--------------------------------------------------------------------------*/
153/*----------------------------- DEFINITIONS --------------------------------*/
154/*--------------------------------------------------------------------------*/
155
156#ifndef __ADS_GrafiteFilter
157 #define __ADS_GrafiteFilter
158/* self-identification: #endif constant */
159
160/*--------------------------------------------------------------------------*/
161/*------------------------------ INCLUDES ----------------------------------*/
162/*--------------------------------------------------------------------------*/
163
164#include "ADS/Contract.h"
167#include "ADS/sort/RadixSort.h"
169
170#include <algorithm>
171#include <bit>
172#include <cstddef>
173#include <cstdint>
174#include <string_view>
175#include <vector>
176
177/*--------------------------------------------------------------------------*/
178/*--------------------------- NAMESPACE ------------------------------------*/
179/*--------------------------------------------------------------------------*/
180
181namespace ADS
182{
183
184/*--------------------------------------------------------------------------*/
185/*-------------------------- CLASS GrafiteFilter ---------------------------*/
186/*--------------------------------------------------------------------------*/
187
191template< RadixKey T = std::uint64_t >
193{
194
195/*--------------------------------------------------------------------------*/
196 public:
198 GrafiteFilter( void ) : GrafiteFilter( std::vector< T >() ) { }
199
217 explicit GrafiteFilter( const std::vector< T > & keys , int B = 16 ,
218 std::uint64_t seed = 1 );
219
249 [[nodiscard]] bool mayContain( const T & a , const T & b ) const;
250
253 [[nodiscard]] bool maybe( const T & x ) const;
254
257 [[nodiscard]] double falsePositiveBound( double l ) const;
258
260 [[nodiscard]] std::size_t size( void ) const;
261
263 [[nodiscard]] bool empty( void ) const;
264
267 [[nodiscard]] std::size_t codes( void ) const;
268
270 [[nodiscard]] std::uint64_t reduced( void ) const;
271
273 [[nodiscard]] std::size_t sizeInBits( void ) const;
274
275/*----------------------------- THE PERSISTENCE ----------------------------*/
276
278 static constexpr std::string_view persistName = "GrafiteFilter";
279
281 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
282 return( detail::persistMix( { sizeof( T ) } ) );
283 }
284
287 template< class A >
288 void persist( A & a );
289
290/*--------------------------------------------------------------------------*/
291 private:
293 [[nodiscard]] std::uint64_t code( std::uint64_t x ) const;
294
297 [[nodiscard]] bool meets( std::uint64_t x , std::uint64_t y ) const;
298
299 EliasFano f_codes;
300 std::uint64_t f_r = 1;
301 std::uint64_t f_alo = 0 , f_ahi = 0;
302 std::uint64_t f_blo = 0 , f_bhi = 0;
303 std::uint64_t f_first = 0;
304 std::size_t f_n = 0;
305 int f_B;
306
307 }; // end( class GrafiteFilter )
308
309/*--------------------------------------------------------------------------*/
310/*------------------------- CLASS BucketingFilter --------------------------*/
311/*--------------------------------------------------------------------------*/
312
317template< RadixKey T = std::uint64_t >
319{
320
321/*--------------------------------------------------------------------------*/
322 public:
324 BucketingFilter( void ) : BucketingFilter( std::vector< T >() ) { }
325
342 explicit BucketingFilter( const std::vector< T > & keys , int B = 16 );
343
357 [[nodiscard]] bool mayContain( const T & a , const T & b ) const;
358
360 [[nodiscard]] bool maybe( const T & x ) const;
361
363 [[nodiscard]] std::uint64_t bucketWidth( void ) const;
364
366 [[nodiscard]] std::size_t buckets( void ) const;
367
369 [[nodiscard]] std::size_t sizeInBits( void ) const;
370
371/*----------------------------- THE PERSISTENCE ----------------------------*/
372
374 static constexpr std::string_view persistName = "BucketingFilter";
375
377 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
378 return( detail::persistMix( { sizeof( T ) } ) );
379 }
380
383 template< class A >
384 void persist( A & a );
385
386/*--------------------------------------------------------------------------*/
387 private:
388 EliasFano f_buckets;
389 std::uint64_t f_s = 1;
390
391 }; // end( class BucketingFilter )
392
393/*--------------------------------------------------------------------------*/
394
395} // end( namespace ADS )
396
397/*--------------------------------------------------------------------------*/
398/*-------------------------- IMPLEMENTATION --------------------------------*/
399/*--------------------------------------------------------------------------*/
400
401#include "ADS/set/impl/GrafiteFilter.tpp"
402
403/*--------------------------------------------------------------------------*/
404
405#endif /* GrafiteFilter.h included */
406
407/*--------------------------------------------------------------------------*/
408/*------------------------ End File GrafiteFilter.h ------------------------*/
409/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The Elias-Fano representation of a non-decreasing sequence of integers in (chapters 11,...
The engineered hash functions of ADS, beyond the book [see HashFunctions.h for those of section 7....
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
The sorts by the digits of the keys, beyond the book (which has Counting Sort and Pigeonhole Sort,...
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition GrafiteFilter.h:374
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition GrafiteFilter.h:377
std::size_t sizeInBits(void) const
the bits of the buckets and of the directory of select
std::size_t buckets(void) const
the buckets that hold a key
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::uint64_t bucketWidth(void) const
the keys of a bucket,
bool maybe(const T &x) const
mayContain( x , x )
bool mayContain(const T &a, const T &b) const
true if holds a key, and if a bucket of a key meets it
BucketingFilter(const std::vector< T > &keys, int B=16)
the filter of the keys, which may repeat, in at most bits per key
BucketingFilter(void)
the filter of no key
Definition GrafiteFilter.h:324
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
bool mayContain(const T &a, const T &b) const
true if holds a key, and with probability at most otherwise
double falsePositiveBound(double l) const
the bound of the false positive probability of a range of keys
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition GrafiteFilter.h:281
std::size_t codes(void) const
the distinct codes, less the keys of that share a code
std::size_t sizeInBits(void) const
the bits of the codes and of the directory of select
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition GrafiteFilter.h:278
GrafiteFilter(const std::vector< T > &keys, int B=16, std::uint64_t seed=1)
the filter of the keys, which may repeat, in bits per key
bool empty(void) const
true if the filter has no key
bool maybe(const T &x) const
mayContain( x , x ): true for a key, and with probability at most otherwise
std::size_t size(void) const
the keys of the build, the repeated ones once each
std::uint64_t reduced(void) const
the reduced universe
GrafiteFilter(void)
the filter of no key
Definition GrafiteFilter.h:198
BasicEliasFano< false > EliasFano
Elias-Fano with the inventories of built in the constructor, the fastest access() and nextGEQ().
Definition EliasFano.h:291
Definition ADT.h:96