Bitcoin Core 28.99.0
P2P Digital Currency
|
This implements a Golomb-coded set as defined in BIP 158. More...
#include <blockfilter.h>
Classes | |
struct | Params |
Public Types | |
typedef std::vector< unsigned char > | Element |
typedef std::unordered_set< Element, ByteVectorHash > | ElementSet |
Public Member Functions | |
GCSFilter (const Params ¶ms=Params()) | |
Constructs an empty filter. More... | |
GCSFilter (const Params ¶ms, std::vector< unsigned char > encoded_filter, bool skip_decode_check) | |
Reconstructs an already-created filter from an encoding. More... | |
GCSFilter (const Params ¶ms, const ElementSet &elements) | |
Builds a new filter from the params and set of elements. More... | |
uint32_t | GetN () const |
const Params & | GetParams () const LIFETIMEBOUND |
const std::vector< unsigned char > & | GetEncoded () const LIFETIMEBOUND |
bool | Match (const Element &element) const |
Checks if the element may be in the set. More... | |
bool | MatchAny (const ElementSet &elements) const |
Checks if any of the given elements may be in the set. More... | |
Private Member Functions | |
uint64_t | HashToRange (const Element &element) const |
Hash a data element to an integer in the range [0, N * M). More... | |
std::vector< uint64_t > | BuildHashedSet (const ElementSet &elements) const |
bool | MatchInternal (const uint64_t *sorted_element_hashes, size_t size) const |
Helper method used to implement Match and MatchAny. More... | |
Private Attributes | |
Params | m_params |
uint32_t | m_N |
Number of elements in the filter. More... | |
uint64_t | m_F |
Range of element hashes, F = N * M. More... | |
std::vector< unsigned char > | m_encoded |
This implements a Golomb-coded set as defined in BIP 158.
It is a compact, probabilistic data structure for testing set membership.
Definition at line 28 of file blockfilter.h.
typedef std::vector<unsigned char> GCSFilter::Element |
Definition at line 31 of file blockfilter.h.
typedef std::unordered_set<Element, ByteVectorHash> GCSFilter::ElementSet |
Definition at line 32 of file blockfilter.h.
Constructs an empty filter.
Definition at line 44 of file blockfilter.cpp.
GCSFilter::GCSFilter | ( | const Params & | params, |
std::vector< unsigned char > | encoded_filter, | ||
bool | skip_decode_check | ||
) |
Reconstructs an already-created filter from an encoding.
Definition at line 48 of file blockfilter.cpp.
GCSFilter::GCSFilter | ( | const Params & | params, |
const ElementSet & | elements | ||
) |
Builds a new filter from the params and set of elements.
Definition at line 73 of file blockfilter.cpp.
|
private |
Definition at line 33 of file blockfilter.cpp.
|
inline |
|
inline |
|
inline |
|
private |
Hash a data element to an integer in the range [0, N * M).
Definition at line 25 of file blockfilter.cpp.
bool GCSFilter::Match | ( | const Element & | element | ) | const |
Checks if the element may be in the set.
False positives are possible with probability 1/M.
Definition at line 135 of file blockfilter.cpp.
bool GCSFilter::MatchAny | ( | const ElementSet & | elements | ) | const |
Checks if any of the given elements may be in the set.
False positives are possible with probability 1/M per element checked. This is more efficient that checking Match on multiple elements separately.
Definition at line 141 of file blockfilter.cpp.
|
private |
Helper method used to implement Match and MatchAny.
Definition at line 103 of file blockfilter.cpp.
|
private |
Definition at line 50 of file blockfilter.h.
|
private |
Range of element hashes, F = N * M.
Definition at line 49 of file blockfilter.h.
|
private |
Number of elements in the filter.
Definition at line 48 of file blockfilter.h.
|
private |
Definition at line 47 of file blockfilter.h.