111#ifndef __ADS_CuckooFilter
112 #define __ADS_CuckooFilter
128#include <string_view>
129#include <type_traits>
133#ifndef ADS_FILTER_INLINE
134 #define ADS_FILTER_INLINE ADS_ALWAYS_INLINE
150template<
class T ,
class F = std::u
int8_t ,
class H = DefaultHash< T > >
154 static_assert( std::is_same_v< F , std::uint8_t > ||
155 std::is_same_v< F , std::uint16_t > ,
156 "the fingerprints have 8 or 16 bits" );
181 [[nodiscard]]
bool maybe(
const T & x )
const;
251 [[nodiscard]] std::size_t
size(
void )
const;
254 [[nodiscard]]
bool empty(
void )
const;
260 [[nodiscard]]
double load(
void )
const;
263 [[nodiscard]] std::size_t
bits(
void )
const;
271 [[nodiscard]]
static constexpr std::uint64_t
persistTag(
void ) {
272 return( detail::persistMix( {
sizeof( T ) ,
sizeof( F ) } ) );
284 std::conditional_t<
sizeof( F ) == 1 , std::uint32_t , std::uint64_t >;
286 static constexpr int kLane = 8 *
sizeof( F );
287 static constexpr W kOnes = W( ~W( 0 ) ) / W( F( ~F( 0 ) ) );
288 static constexpr W kLow = kOnes * W( F( ~F( 0 ) ) >> 1 );
289 static constexpr int kMaxKicks = 500;
292 [[nodiscard]]
static constexpr W zeros( W w ) {
293 return( W( ~( ( ( w & kLow ) + kLow ) | w | kLow ) ) );
297 [[nodiscard]] std::uint64_t hash(
const T & x )
const;
300 [[nodiscard]]
static F tag( std::uint64_t h );
303 [[nodiscard]] std::size_t bucket( std::uint64_t h )
const;
306 [[nodiscard]] std::size_t other( std::size_t b , F t )
const;
309 bool put( std::size_t b , F t );
313 void place( std::size_t b , F t );
316 std::uint64_t random(
void );
318 std::vector< W , MappableAllocator< W > > f_T;
319 std::size_t f_mask = 0;
321 std::size_t f_vb = 0;
323 std::uint64_t f_rng = 0x9E3779B97F4A7C15ULL;
336#include "ADS/set/impl/CuckooFilter.tpp"
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 primitives of the processor that the compilers spell each in their own way, in one form for all: ...
std::size_t bits(void) const
the bits of the buckets
CuckooFilter(void)
a filter for one key, empty
Definition CuckooFilter.h:161
CuckooFilter(std::size_t n, H h=H())
the empty filter for keys, at the load 0.94 when they are in, in at least one bucket: buckets,...
void clear(void)
removes all the keys
bool maybe(const T &x) const
whether may be in the set, by maybeHash() of its hash: false only if is not in the set
double load(void) const
size() / capacity(), the load
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition CuckooFilter.h:271
std::size_t size(void) const
the keys in, with their repetitions
bool empty(void) const
whether no key is in
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition CuckooFilter.h:268
std::size_t capacity(void) const
the places, 4 per bucket
bool insertHash(std::uint64_t h)
the hash of 64 bits, which must be random, into the filter, false (and nothing changed) if the filte...
bool removeHash(std::uint64_t h)
one insertion of the hash removed, false if it is not there
bool insert(const T &x)
into the filter by insertHash() of its hash, false (and nothing changed) if the filter is full
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
bool remove(const T &x)
one insertion of removed by removeHash() of its hash, false if is not there
bool maybeHash(std::uint64_t h) const
whether the hash may be in the set: false only if it is not