Class SoftHashSet<E>

  • Type Parameters:
    E - is the type of the values.
    All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>

    public class SoftHashSet<E>
    extends AbstractReferencedSet<E,​SoftReference<E>>
    A Set implementation with soft values. An entry in a SoftHashSet will automatically be removed when its value is no longer in ordinary use or null.

    This class was inspirated from WeakHashMap and uses a HashSet as its internal data structure.

    This class has a special flag which permits to control the way how the released references are expurged: AbstractReferencedSet.isDeeplyExpurge(), AbstractReferencedSet.setDeeplyExpurge(boolean). If this flag is true, all the released references will be immediately removed from the map even if they are not enqueued by the virtual machine (see AbstractReferencedSet.expurge(). If this flag is false, only the enqueued references will be removed from the map (see AbstractReferencedSet.expurgeQueuedReferences().

    If this map does not use a "deep expurge" of the released references, it could contains null values that corresponds to values that are released by the garbage collector. If a "deep expurge" is used, all the values released by the garbage collector will be removed from the map.

    "Deep expurge" consumes much more time that "No deep expurge". This is the reason why this feature is not activated by default.

    The "deep expurge" feature was added to fix the uncoherent behavior of the garbage collector which seems to not always enqueued the released values (sometimes the queue is empty even if a value was released).

    Since:
    5.9
    Version:
    17.0 2020-01-04 14:41:38
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    references
    • Constructor Detail

      • SoftHashSet

        public SoftHashSet()
        Constructs an empty HashSet.
      • SoftHashSet

        public SoftHashSet​(int initialCapacity)
        Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and default load factor (0.75).
        Parameters:
        initialCapacity - the initial capacity of the hash table
        Throws:
        IllegalArgumentException - if the initial capacity is less than zero
      • SoftHashSet

        public SoftHashSet​(int initialCapacity,
                           float loadFactor)
        Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and the specified load factor.
        Parameters:
        initialCapacity - the initial capacity of the hash map
        loadFactor - the load factor of the hash map
        Throws:
        IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive
      • SoftHashSet

        public SoftHashSet​(Collection<? extends E> collection)
        Constructs a new set containing the elements in the specified collection. The HashSet is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.
        Parameters:
        collection - the collection whose elements are to be placed into this set
        Throws:
        NullPointerException - if the specified collection is null