public class DecayingBloomFilter extends Object
Provides a series of Bloom filters with automatic time-based decay to handle time-sensitive data with minimal false positive rates. Uses fixed-size buffers with periodic switching to maintain consistent memory usage while allowing high-throughput operations.
Optimized for scenarios requiring hundreds of entries per second with virtually no false positive rate. Memory usage is carefully controlled through configurable filter parameters and buffer sizes.
Performance characteristics:
Suitable for high-throughput applications like message validation, tunnel IV filtering, and router message processing where memory efficiency and low false positive rates are critical.
DecayingHashSet,
BloomFilterIVValidator| Modifier and Type | Field and Description |
|---|---|
protected I2PAppContext |
_context |
protected long |
_currentDuplicates |
protected SimpleTimer2.TimedEvent |
_decayEvent |
protected int |
_durationMs |
protected int |
_entryBytes |
protected boolean |
_keepDecaying |
protected Log |
_log |
protected String |
_name
just for logging
|
protected ReentrantReadWriteLock |
_reorganizeLock
synchronize against this lock when switching double buffers
|
| Modifier | Constructor and Description |
|---|---|
|
DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes)
Create a bloom filter that will decay its entries over time.
|
|
DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes,
String name)
Uses default m of 23, memory usage is 2 MB.
|
|
DecayingBloomFilter(I2PAppContext context,
int durationMs,
int entryBytes,
String name,
int m)
Memory usage is 2 * (2**m) bits or 2**(m-2) bytes.
|
protected |
DecayingBloomFilter(int durationMs,
int entryBytes,
String name,
I2PAppContext context)
only for extension by DHS
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(byte[] entry) |
boolean |
add(byte[] entry,
int off,
int len) |
boolean |
add(long entry) |
void |
clear() |
protected void |
decay() |
long |
getCurrentDuplicateCount() |
double |
getFalsePositiveRate()
unsynchronized, only used for logging elsewhere
|
int |
getInsertedCount()
unsynchronized but only used for logging elsewhere
|
protected void |
getReadLock() |
protected boolean |
getWriteLock() |
boolean |
isKnown(long entry) |
protected void |
releaseReadLock() |
protected void |
releaseWriteLock() |
void |
stopDecaying() |
protected final I2PAppContext _context
protected long _currentDuplicates
protected final SimpleTimer2.TimedEvent _decayEvent
protected final int _durationMs
protected final int _entryBytes
protected volatile boolean _keepDecaying
protected final Log _log
protected final String _name
protected final ReentrantReadWriteLock _reorganizeLock
public DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes)
durationMs - entries last for at least this long, but no more than twice this longentryBytes - how large are the entries to be added? if this is less than 32 bytes,
the entries added will be expanded by concatenating their XORing
against with sufficient random values.public DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes, String name)
name - just for logging / debugging / statspublic DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes, String name, int m)
m - filter size exponent, max is 29protected DecayingBloomFilter(int durationMs,
int entryBytes,
String name,
I2PAppContext context)
public boolean add(byte[] entry)
public boolean add(byte[] entry,
int off,
int len)
public boolean add(long entry)
public void clear()
protected void decay()
public long getCurrentDuplicateCount()
public double getFalsePositiveRate()
public int getInsertedCount()
protected void getReadLock()
protected boolean getWriteLock()
public boolean isKnown(long entry)
protected void releaseReadLock()
protected void releaseWriteLock()
public void stopDecaying()