[#CRollingBloomFilter]
= CRollingBloomFilter
:mrdocs:

RollingBloomFilter is a probabilistic &quot;keep track of most recently inserted&quot; set&period; Construct it with the number of items to keep track of, and a false&hyphen;positive rate&period; Unlike CBloomFilter, by default nTweak is set to a cryptographically secure random value for you&period; Similarly rather than clear() the method reset() is provided, which also changes nTweak to decrease the impact of false&hyphen;positives&period;

== Synopsis

Declared in `&lt;common&sol;bloom&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class CRollingBloomFilter;
----

== Description

contains(item) will always return true if item was one of the last N to 1&period;5&ast;N insert()&apos;ed &period;&period;&period; but may also return true for items that were not inserted&period;

It needs around 1&period;8 bytes per element per factor 0&period;1 of false positive rate&period; For example, if we want 1000 elements, we&apos;d need&colon;

* &#126;1800 bytes for a false positive rate of 0&period;1
* &#126;3600 bytes for a false positive rate of 0&period;01
* &#126;5400 bytes for a false positive rate of 0&period;001

If we make these simplifying assumptions&colon;

* logFpRate &sol; log(0&period;5) doesn&apos;t get rounded or clamped in the nHashFuncs calculation
* nElements is even, so that nEntriesPerGeneration &equals;&equals; nElements &sol; 2

Then we get a more accurate estimate for filter bytes&colon;

3&sol;(log(256)&ast;log(2)) &ast; log(1&sol;fpRate) &ast; nElements

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:CRollingBloomFilter/2constructor.adoc[`CRollingBloomFilter`]         [.small]#[constructor]#
| Construct a rolling filter sized for a number of elements and a false&hyphen;positive rate&period;
| xref:CRollingBloomFilter/contains.adoc[`contains`] 
| Test whether a raw key was recently inserted&period;
| xref:CRollingBloomFilter/insert.adoc[`insert`] 
| Add a raw key to the filter, evicting older entries as needed&period;
| xref:CRollingBloomFilter/reset.adoc[`reset`] 
| Clear the filter and re&hyphen;randomize the hash seed&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
