ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
BloomFilter.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*--------------------------- File BloomFilter.h ---------------------------*/
3
/*--------------------------------------------------------------------------*/
37
/*--------------------------------------------------------------------------*/
38
/*----------------------------- DEFINITIONS --------------------------------*/
39
/*--------------------------------------------------------------------------*/
40
41
#ifndef __ADS_BloomFilter
42
#define __ADS_BloomFilter
43
/* self-identification: #endif constant */
44
45
/*--------------------------------------------------------------------------*/
46
/*------------------------------ INCLUDES ----------------------------------*/
47
/*--------------------------------------------------------------------------*/
48
49
#include "
ADS/Contract.h
"
50
#include "
ADS/dictionary/RandomHashing.h
"
51
#include "
ADS/external/MappedFile.h
"
52
53
#include <cmath>
54
#include <cstddef>
55
#include <cstdint>
56
#include <functional>
57
#include <string_view>
58
#include <vector>
59
60
/*--------------------------------------------------------------------------*/
61
/*--------------------------- NAMESPACE ------------------------------------*/
62
/*--------------------------------------------------------------------------*/
63
64
namespace
ADS
65
{
66
67
/*--------------------------------------------------------------------------*/
68
/*--------------------------- CLASS BloomFilter ----------------------------*/
69
/*--------------------------------------------------------------------------*/
70
72
template
<
class
T ,
class
H = std::hash< T > >
73
class
BloomFilter
74
{
75
76
/*--------------------------------------------------------------------------*/
77
public
:
79
BloomFilter
(
void
) :
BloomFilter
( 64 , 1 ) { }
80
83
BloomFilter
( std::size_t m ,
int
k , H h = H() );
84
90
static
BloomFilter
forItems
( std::size_t n ,
double
p );
91
107
void
insert
(
const
T & x );
108
125
[[nodiscard]]
bool
maybe
(
const
T & x )
const
;
126
129
[[nodiscard]]
double
falsePositiveRate
(
void
)
const
;
130
132
[[nodiscard]] std::size_t
bits
(
void
)
const
;
133
135
[[nodiscard]]
int
hashes
(
void
)
const
;
136
137
/*----------------------------- THE PERSISTENCE ----------------------------*/
138
140
static
constexpr
std::string_view
persistName
=
"BloomFilter"
;
141
143
[[nodiscard]]
static
constexpr
std::uint64_t
persistTag
(
void
) {
144
return
( detail::persistMix( {
sizeof
( T ) } ) );
145
}
146
149
template
<
class
A >
150
void
persist
( A & a );
151
152
/*--------------------------------------------------------------------------*/
153
private
:
154
std::vector< std::uint64_t > f_B;
155
std::size_t f_m;
156
int
f_k;
157
std::size_t f_n = 0;
158
H f_h;
159
160
};
// end( class BloomFilter )
161
162
/*--------------------------------------------------------------------------*/
163
164
}
// end( namespace ADS )
165
166
/*--------------------------------------------------------------------------*/
167
/*-------------------------- IMPLEMENTATION --------------------------------*/
168
/*--------------------------------------------------------------------------*/
169
170
#include "ADS/set/impl/BloomFilter.tpp"
171
172
/*--------------------------------------------------------------------------*/
173
174
#endif
/* BloomFilter.h included */
175
176
/*--------------------------------------------------------------------------*/
177
/*------------------------- End File BloomFilter.h -------------------------*/
178
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
MappedFile.h
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
RandomHashing.h
Hashing with random tables, beyond the book:
ADS::BloomFilter::persistTag
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition
BloomFilter.h:143
ADS::BloomFilter::hashes
int hashes(void) const
the hashes
ADS::BloomFilter::persistName
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition
BloomFilter.h:140
ADS::BloomFilter::insert
void insert(const T &x)
into the filter, by setting its bits
ADS::BloomFilter::persist
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
ADS::BloomFilter::bits
std::size_t bits(void) const
the bits
ADS::BloomFilter::forItems
static BloomFilter forItems(std::size_t n, double p)
the filter of the best for items and the false positives : bits and rounded, at least 1
ADS::BloomFilter::BloomFilter
BloomFilter(void)
a filter of 64 bits and one hash, empty
Definition
BloomFilter.h:79
ADS::BloomFilter::falsePositiveRate
double falsePositiveRate(void) const
the expected false positives after the insertions made,
ADS::BloomFilter::maybe
bool maybe(const T &x) const
whether may be in the set: false only if was never inserted
ADS::BloomFilter::BloomFilter
BloomFilter(std::size_t m, int k, H h=H())
the empty filter of bits and hashes
ADS
Definition
ADT.h:96
ADS
set
BloomFilter.h
Generated by
1.17.0