public class FastApproximateByteArrayCache
extends java.lang.Object
This cache stores 128-bit MurmurHash3 fingerprints of byte arrays. Fingerprints are stored in
a number of stripes whose access is synchronized. Each stripe is an open-address linked hash table
similar to a LongLinkedOpenHashSet
.
Fingerprints are evicted using a standard LRU strategy. Since we store fingerprints, it is in principle
possible to get false positives (i.e., add(byte[])
might return
false
even if the argument was never added to the cache).
The number of objects created by this map is very small, and depends only on the number of stripes, not on the size of the cache.
Modifier and Type | Class | Description |
---|---|---|
protected static class |
FastApproximateByteArrayCache.Stripe |
A class containing a stripe of the cache.
|
Constructor | Description |
---|---|
FastApproximateByteArrayCache(long byteSize) |
Creates a new cache with specified size and concurrency level equal to
Runtime.availableProcessors() . |
FastApproximateByteArrayCache(long byteSize,
int concurrencyLevel) |
Creates a new cache with specified size.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(byte[] key) |
|
boolean |
add(byte[] key,
int offset,
int length) |
|
boolean |
add(ByteArrayList key) |
|
long |
hits() |
Returns the number of cache hits.
|
long |
misses() |
Returns the number of cache misses.
|
public FastApproximateByteArrayCache(long byteSize)
Runtime.availableProcessors()
.byteSize
- the approximate size of the cache in bytes.public FastApproximateByteArrayCache(long byteSize, int concurrencyLevel)
byteSize
- the approximate size of the cache in bytes.concurrencyLevel
- the number of stripes (it will be forced to be a power of two).public boolean add(byte[] key)
public boolean add(ByteArrayList key)
public boolean add(byte[] key, int offset, int length)
public long hits()
public long misses()