com.hazelcast.util.collection

## Class OAHashSet<E>

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractSet<E>
    - - com.hazelcast.util.collection.OAHashSet<E>

- Type Parameters:
    `E` - The type of the elements stored in the set
  All Implemented Interfaces:
    Iterable<E>, Collection<E>, Set<E>

      public class OAHashSet<E>
      extends AbstractSet<E>

  Not thread-safe open-addressing hash `Set` implementation with linear probing for CPU cache efficiency. This implementation caches the hashes of the elements stored in the set. This caching enables avoiding expensive `hashCode()` calls when rehashing at the cost of the increased memory consumption.

  Besides avoiding `hashCode()` calls on rehashing, this implementation offers methods that accept the hash together with the element if it is already known on the caller side. See `add(Object, int)`, `contains(Object, int)`, `remove(Object, int)`.

  This `Set` implementation does not permit null elements.

  This `Set` implementation does not permit concurrent modifications during iteration.

  Please note that this `Set` implementation does not shrink when elements are removed.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OAHashSet()` Constructs an `OAHashSet` instance with default initial capacity and default load factor
    `OAHashSet(int initialCapacity)` Constructs an `OAHashSet` instance with the specified initial capacity and with the default load factor
    `OAHashSet(int initialCapacity, float loadFactor)` Constructs an `OAHashSet` instance with the specified initial capacity and load factor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(E element)`
    `boolean` | `add(E elementToAdd, int hash)` Adds the specified element to this set if it is not already present.
    `int` | `capacity()` Returns the capacity of the set
    `void` | `clear()`
    `boolean` | `contains(Object objectToCheck)`
    `boolean` | `contains(Object objectToCheck, int hash)` Returns `true` if this set contains the specified element with the hash provided in parameter.
    `long` | `footprint()` Returns the current memory consumption (in bytes)
    `int` | `hashCode()`
    `Iterator<E>` | `iterator()`
    `float` | `loadFactor()` Returns the load factor of the set
    `boolean` | `remove(Object objectToRemove)`
    `boolean` | `remove(Object objectToRemove, int hash)` Removes the specified element from this set if it is present with the hash provided in parameter.
    `boolean` | `removeAll(Collection<?> elementsToRemove)`
    `boolean` | `retainAll(Collection<?> elementsToRetain)`
    `int` | `size()`
    `Object[]` | `toArray()`
    `<T> T[]` | `toArray(T[] array)`

    - ### Methods inherited from class java.util.AbstractSet

      `equals`

    - ### Methods inherited from class java.util.AbstractCollection

      `addAll, containsAll, isEmpty, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Set

      `addAll, containsAll, isEmpty, spliterator`

    - ### Methods inherited from interface java.util.Collection

      `parallelStream, removeIf, stream`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach`

- - ### Constructor Detail

    - #### OAHashSet

          public OAHashSet()

      Constructs an `OAHashSet` instance with default initial capacity and default load factor
      See Also:
        `DEFAULT_INITIAL_CAPACITY`, `DEFAULT_LOAD_FACTOR`

    - #### OAHashSet

          public OAHashSet(int initialCapacity)

      Constructs an `OAHashSet` instance with the specified initial capacity and with the default load factor
      Parameters:
        `initialCapacity` - the initial capacity of the set to be created
      See Also:
        `DEFAULT_LOAD_FACTOR`

    - #### OAHashSet

          public OAHashSet(int initialCapacity,
                           float loadFactor)

      Constructs an `OAHashSet` instance with the specified initial capacity and load factor
      Parameters:
        `initialCapacity` - the initial capacity of the set to be created
        `loadFactor` - the load factor of the set to be created

  - ### Method Detail

    - #### add

          public boolean add(E element)

      Specified by:
        `add` in interface `Collection<E>`
      Specified by:
        `add` in interface `Set<E>`
      Overrides:
        `add` in class `AbstractCollection<E>`

    - #### add

          public boolean add(E elementToAdd,
                             int hash)

      Adds the specified element to this set if it is not already present.

      This variant of `add(Object)` acts as an optimisation to enable avoiding `hashCode()` calls if the hash is already known on the caller side.

      Parameters:
        `elementToAdd` - element to be added to this set
        `hash` - the hash of the element to be added
      Returns:
        `true` if this set did not already contain the specified element
      See Also:
        `add(Object)`

    - #### contains

          public boolean contains(Object objectToCheck)

      Specified by:
        `contains` in interface `Collection<E>`
      Specified by:
        `contains` in interface `Set<E>`
      Overrides:
        `contains` in class `AbstractCollection<E>`

    - #### contains

          public boolean contains(Object objectToCheck,
                                  int hash)

      Returns `true` if this set contains the specified element with the hash provided in parameter.

      This variant of `contains(Object)` acts as an optimisation to enable avoiding `hashCode()` calls if the hash is already known on the caller side.

      Parameters:
        `objectToCheck` - element whose presence in this set is to be tested
        `hash` - the hash of the element to be tested
      Returns:
        `true` if this set contains the specified element
      See Also:
        `contains(Object)`

    - #### remove

          public boolean remove(Object objectToRemove)

      Specified by:
        `remove` in interface `Collection<E>`
      Specified by:
        `remove` in interface `Set<E>`
      Overrides:
        `remove` in class `AbstractCollection<E>`

    - #### remove

          public boolean remove(Object objectToRemove,
                                int hash)

      Removes the specified element from this set if it is present with the hash provided in parameter.

      This variant of `remove(Object)` acts as an optimisation to enable avoiding `hashCode()` calls if the hash is already known on the caller side.

      Parameters:
        `objectToRemove` - object to be removed from this set, if present
        `hash` - the hash of the element to be removed
      Returns:
        `true` if this set contained the specified element
      See Also:
        `remove(Object)`

    - #### removeAll

          public boolean removeAll(Collection<?> elementsToRemove)

      Specified by:
        `removeAll` in interface `Collection<E>`
      Specified by:
        `removeAll` in interface `Set<E>`
      Overrides:
        `removeAll` in class `AbstractSet<E>`

    - #### retainAll

          public boolean retainAll(Collection<?> elementsToRetain)

      Specified by:
        `retainAll` in interface `Collection<E>`
      Specified by:
        `retainAll` in interface `Set<E>`
      Overrides:
        `retainAll` in class `AbstractCollection<E>`

    - #### size

          public int size()

      Specified by:
        `size` in interface `Collection<E>`
      Specified by:
        `size` in interface `Set<E>`
      Specified by:
        `size` in class `AbstractCollection<E>`

    - #### iterator

          public Iterator<E> iterator()

      Specified by:
        `iterator` in interface `Iterable<E>`
      Specified by:
        `iterator` in interface `Collection<E>`
      Specified by:
        `iterator` in interface `Set<E>`
      Specified by:
        `iterator` in class `AbstractCollection<E>`

    - #### toArray

          public Object[] toArray()

      Specified by:
        `toArray` in interface `Collection<E>`
      Specified by:
        `toArray` in interface `Set<E>`
      Overrides:
        `toArray` in class `AbstractCollection<E>`

    - #### toArray

          public <T> T[] toArray(T[] array)

      Specified by:
        `toArray` in interface `Collection<E>`
      Specified by:
        `toArray` in interface `Set<E>`
      Overrides:
        `toArray` in class `AbstractCollection<E>`

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Collection<E>`
      Specified by:
        `clear` in interface `Set<E>`
      Overrides:
        `clear` in class `AbstractCollection<E>`

    - #### capacity

          public int capacity()

      Returns the capacity of the set
      Returns:
        the capacity of the set

    - #### footprint

          public long footprint()

      Returns the current memory consumption (in bytes)
      Returns:
        the current memory consumption

    - #### loadFactor

          public float loadFactor()

      Returns the load factor of the set
      Returns:
        the load factor of the set

    - #### hashCode

          public int hashCode()

      Specified by:
        `hashCode` in interface `Collection<E>`
      Specified by:
        `hashCode` in interface `Set<E>`
      Overrides:
        `hashCode` in class `AbstractSet<E>`

Copyright © 2019. All rights reserved.