net.i2p.util
Class DecayingBloomFilter

java.lang.Object
  extended by net.i2p.util.DecayingBloomFilter

public class DecayingBloomFilter
extends java.lang.Object

Series of bloom filters which decay over time, allowing their continual use for time sensitive data. This has a fixed size (currently 1MB per decay period, using two periods overall), allowing this to pump through hundreds of entries per second with virtually no false positive rate. Down the line, this may be refactored to allow tighter control of the size necessary for the contained bloom filters, but a fixed 2MB overhead isn't that bad.


Constructor Summary
DecayingBloomFilter(I2PAppContext context, int durationMs, int entryBytes)
          Create a bloom filter that will decay its entries over time.
 
Method Summary
 boolean add(byte[] entry)
          return true if the entry added is a duplicate
 boolean add(byte[] entry, int off, int len)
           
 boolean add(long entry)
          return true if the entry added is a duplicate.
 void clear()
           
 long getCurrentDuplicateCount()
           
 double getFalsePositiveRate()
           
 int getInsertedCount()
           
 boolean isKnown(long entry)
          return true if the entry is already known.
static void main(java.lang.String[] args)
           
 void stopDecaying()
           
static void testByBytes(int kbps, int numRuns)
           
static void testByLong(int kbps, int numRuns)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecayingBloomFilter

public DecayingBloomFilter(I2PAppContext context,
                           int durationMs,
                           int entryBytes)
Create a bloom filter that will decay its entries over time.

Parameters:
durationMs - entries last for at least this long, but no more than twice this long
entryBytes - 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.
Method Detail

getCurrentDuplicateCount

public long getCurrentDuplicateCount()

getInsertedCount

public int getInsertedCount()

getFalsePositiveRate

public double getFalsePositiveRate()

add

public boolean add(byte[] entry)
return true if the entry added is a duplicate


add

public boolean add(byte[] entry,
                   int off,
                   int len)

add

public boolean add(long entry)
return true if the entry added is a duplicate. the number of low order bits used is determined by the entryBytes parameter used on creation of the filter.


isKnown

public boolean isKnown(long entry)
return true if the entry is already known. this does NOT add the entry however.


clear

public void clear()

stopDecaying

public void stopDecaying()

main

public static void main(java.lang.String[] args)

testByLong

public static void testByLong(int kbps,
                              int numRuns)

testByBytes

public static void testByBytes(int kbps,
                               int numRuns)