public class DecayingHashSet extends DecayingBloomFilter
Extends DecayingBloomFilter to provide dual-buffered hash sets with automatic decay switching between active and previous buffers. Optimized for high-throughput scenarios with frequent insertions and periodic cleanup operations.
Memory usage analysis shows significant optimization potential:
Performance characteristics:
Uses read/write locks with SimpleTimer2 for thread safety and efficient buffer switching without synchronization overhead.
_context, _currentDuplicates, _decayEvent, _durationMs, _entryBytes, _keepDecaying, _log, _name, _reorganizeLock| Constructor and Description |
|---|
DecayingHashSet(I2PAppContext context,
int durationMs,
int entryBytes)Create a double-buffered hash set that will decay its entries over time. |
DecayingHashSet(I2PAppContext context,
int durationMs,
int entryBytes,
String name)Decaying hash set with a custom name. |
| Modifier and Type | Method and Description |
|---|---|
boolean | add(byte[] entry,
int off,
int len)Add the entry, returning whether it was a duplicate. |
boolean | add(long entry)Add the long entry, returning whether it was a duplicate. |
void | clear()Clear all filters and reset counts |
protected void | decay()Decay the filter, moving the current buffer to the previous. |
double | getFalsePositiveRate()Stubbed rate; only used for logging elsewhere. |
int | getInsertedCount()Unsynchronized but only used for logging elsewhere. |
boolean | isKnown(long entry)Check whether the entry is already known, without adding it. |
void | stopDecaying()Super doesn't call clear, but neither do the users, so it seems like we should here. |
add, getCurrentDuplicateCount, getReadLock, getWriteLock, releaseReadLock, releaseWriteLockpublic DecayingHashSet(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? 1 to 32 bytespublic DecayingHashSet(I2PAppContext context, int durationMs, int entryBytes, String name)
name - just for logging / debugging / statspublic boolean add(byte[] entry,
int off,
int len)add in class DecayingBloomFilterentry - the entry dataoff - the offsetlen - the lengthpublic boolean add(long entry)
add in class DecayingBloomFilterentry - the long value to addpublic void clear()
DecayingBloomFilterclear in class DecayingBloomFilterprotected void decay()
DecayingBloomFilterdecay in class DecayingBloomFilterpublic double getFalsePositiveRate()
getFalsePositiveRate in class DecayingBloomFilterpublic int getInsertedCount()
getInsertedCount in class DecayingBloomFilterpublic boolean isKnown(long entry)
isKnown in class DecayingBloomFilterentry - the long value to checkpublic void stopDecaying()
stopDecaying in class DecayingBloomFilter