java.lang.Object
net.i2p.util.SimpleByteCache.IntCacheMap
- Enclosing class:
SimpleByteCache
A set of
SimpleByteCache, keyed by array size. Open addressed with linear probing: lookups are lock-free and unboxed, and only putIfAbsent and the occasional growth take the lock.Values are read through an AtomicReferenceArray, which both marks the occupied slots - every int is a legal key, so there is no value to spare as an empty-slot sentinel - and publishes each cache's fully built internals.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classReplaced wholesale on growth, so a reader always sees a complete one.Field Summary
FieldsModifier and TypeFieldDescriptionprivate intOccupied slots in the current table.The current hash table.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescription(package private) SimpleByteCacheget(int key) The cached array for the key, creating it if needed.grow()Double the table.(package private) SimpleByteCacheputIfAbsent(int key, SimpleByteCache val) Store a cache unless the key is already present.private static intslot(int key, int mask) Mixes the key, so that nearby sizes land in different slots.(package private) List<SimpleByteCache> values()Snapshot of the caches, for the cleanup task andSimpleByteCache.clearAll().
Field Details
_table
The current hash table._size
private int _sizeOccupied slots in the current table. Guarded by this.
Constructor Details
IntCacheMap
IntCacheMap(int expectedSize) Builds the map of caches by size.- Parameters:
expectedSize- entries expected in the map
Method Details
slot
private static int slot(int key, int mask) Mixes the key, so that nearby sizes land in different slots.- Parameters:
key- the array size being cachedmask- table capacity minus one- Returns:
- the table slot index for the key
get
The cached array for the key, creating it if needed.- Parameters:
key- the array size- Returns:
- the cache for the key, or null
putIfAbsent
Store a cache unless the key is already present.- Parameters:
key- the array sizeval- the cache to store if the key is free- Returns:
- the value now stored for the key - val, or the one that was already there
grow
Double the table. Caller must synchronize on this.- Returns:
- the new table, twice the size, already rehashed
values
List<SimpleByteCache> values()Snapshot of the caches, for the cleanup task andSimpleByteCache.clearAll().- Returns:
- never null