ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BlockedBloomFilter.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File BlockedBloomFilter.h -----------------------*/
3/*--------------------------------------------------------------------------*/
55/*--------------------------------------------------------------------------*/
56/*----------------------------- DEFINITIONS --------------------------------*/
57/*--------------------------------------------------------------------------*/
58
59#ifndef __ADS_BlockedBloomFilter
60 #define __ADS_BlockedBloomFilter
61/* self-identification: #endif constant */
62
63/*--------------------------------------------------------------------------*/
64/*------------------------------ INCLUDES ----------------------------------*/
65/*--------------------------------------------------------------------------*/
66
67#include "ADS/Contract.h"
68#include "ADS/SimdInline.h"
71
72#include <algorithm>
73#include <cmath>
74#include <cstddef>
75#include <cstdint>
76#include <string_view>
77#include <vector>
78
79/*--------------------------------------------------------------------------*/
80/*--------------------------- NAMESPACE ------------------------------------*/
81/*--------------------------------------------------------------------------*/
82
83namespace ADS
84{
85
86/*--------------------------------------------------------------------------*/
87/*------------------------ CLASS BlockedBloomFilter ------------------------*/
88/*--------------------------------------------------------------------------*/
89
91template< class T , class H = DefaultHash< T > >
93{
94
95/*--------------------------------------------------------------------------*/
96 public:
99
104 explicit BlockedBloomFilter( std::size_t n , double bitsPerItem = 10 ,
105 H h = H() );
106
109 void insert( const T & x );
110
113 [[nodiscard]] bool maybe( const T & x ) const;
114
130 void insertHash( std::uint64_t h );
131
146 [[nodiscard]] bool maybeHash( std::uint64_t h ) const;
147
151 void unite( const BlockedBloomFilter & o );
152
154 void clear( void );
155
157 [[nodiscard]] std::size_t size( void ) const;
158
160 [[nodiscard]] bool empty( void ) const;
161
163 [[nodiscard]] std::size_t bits( void ) const;
164
166 [[nodiscard]] std::size_t blocks( void ) const;
167
188 [[nodiscard]] double falsePositiveRate( void ) const;
189
190/*----------------------------- THE PERSISTENCE ----------------------------*/
191
193 static constexpr std::string_view persistName = "BlockedBloomFilter";
194
196 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
197 return( detail::persistMix( { sizeof( T ) } ) );
198 }
199
202 template< class A >
203 void persist( A & a );
204
205/*--------------------------------------------------------------------------*/
206 private:
208 struct alignas( 32 ) Block
209 {
210 std::uint32_t w[ 8 ];
211 using persist_unit = std::uint32_t;
212 };
213
215 [[nodiscard]] std::uint64_t hash( const T & x ) const;
216
218 [[nodiscard]] std::size_t block( std::uint64_t h ) const;
219
220 std::vector< Block , MappableAllocator< Block > > f_B;
221 std::size_t f_n = 0;
222 H f_h;
223
224 }; // end( class BlockedBloomFilter )
225
226/*--------------------------------------------------------------------------*/
227
228} // end( namespace ADS )
229
230/*--------------------------------------------------------------------------*/
231/*-------------------------- IMPLEMENTATION --------------------------------*/
232/*--------------------------------------------------------------------------*/
233
234#include "ADS/set/impl/BlockedBloomFilter.tpp"
235
236/*--------------------------------------------------------------------------*/
237
238#endif /* BlockedBloomFilter.h included */
239
240/*--------------------------------------------------------------------------*/
241/*---------------------- End File BlockedBloomFilter.h ---------------------*/
242/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
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 vector kernels of ADS that are inlined in the middle of a search, on Google Highway,...
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
void insert(const T &x)
into the filter, by insertHash() of its hash
BlockedBloomFilter(void)
a filter of one block, empty
Definition BlockedBloomFilter.h:98
void insertHash(std::uint64_t h)
the hash of 64 bits, which must be random, into the filter
std::size_t size(void) const
the insertions made
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition BlockedBloomFilter.h:193
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition BlockedBloomFilter.h:196
bool empty(void) const
whether no item was inserted
void unite(const BlockedBloomFilter &o)
the items of o added, as if they had been inserted here, by the OR of the blocks
BlockedBloomFilter(std::size_t n, double bitsPerItem=10, H h=H())
the empty filter of about bitsPerItem bits for each of items, in at least one block,...
std::size_t bits(void) const
the bits, 256 per block
bool maybeHash(std::uint64_t h) const
whether the hash may be in the set: false only if it was never inserted
std::size_t blocks(void) const
the blocks
bool maybe(const T &x) const
whether may be in the set, by maybeHash() of its hash: false only if was never inserted
double falsePositiveRate(void) const
the expected false positives after the insertions made, the mean over the Poisson loads of the blocks...
void clear(void)
removes all the items
Definition ADT.h:96