java.lang.Object
net.i2p.util.SimpleByteCache.IntCacheMap
Enclosing class:
SimpleByteCache

private static final class SimpleByteCache.IntCacheMapextends Object
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.

  • Field Details

    • _table

      private volatile SimpleByteCache.IntCacheMap.Table _table
      The current hash table.
    • _size

      private int _size
      Occupied 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 cached
      mask - table capacity minus one
      Returns:
      the table slot index for the key
    • get

      SimpleByteCache get(int key)
      The cached array for the key, creating it if needed.
      Parameters:
      key - the array size
      Returns:
      the cache for the key, or null
    • putIfAbsent

      SimpleByteCache putIfAbsent(int key, SimpleByteCache val)
      Store a cache unless the key is already present.
      Parameters:
      key - the array size
      val - 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

      Snapshot of the caches, for the cleanup task and SimpleByteCache.clearAll().
      Returns:
      never null