LightWeightResizableGSet (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.util, class: LightWeightResizableGSet

Package org.apache.hadoop.util

# Class LightWeightResizableGSet<K,E extends K>

java.lang.Object
org.apache.hadoop.util.LightWeightGSet<K,E>
org.apache.hadoop.util.LightWeightResizableGSet<K,E>

Type Parameters:
  `K` - Key type for looking up the elements
  `E` - Element type, which must be (1) a subclass of K, and (2) implementing `LightWeightGSet.LinkedElement` interface.

All Implemented Interfaces:
  `Iterable<E>`, `GSet<K,E>`

@Private public class LightWeightResizableGSet<K,E extends K> extends LightWeightGSet<K,E>
A low memory footprint `GSet` implementation, which uses an array for storing the elements and linked lists for collision resolution. If the size of elements exceeds the threshold, the internal array will be resized to double length. This class does not support null element. This class is thread safe.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.hadoop.util.LightWeightGSet

  `LightWeightGSet.LinkedElement, LightWeightGSet.SetIterator`

- ## Field Summary

  ### Fields inherited from class org.apache.hadoop.util.LightWeightGSet

  `entries, hash_mask, modification, size`

  ### Fields inherited from interface org.apache.hadoop.util.GSet

  `LOG`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LightWeightResizableGSet()`
  `LightWeightResizableGSet(int initCapacity)`
  `LightWeightResizableGSet(int initCapacity, float loadFactor)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `expandIfNecessary()`
  Checks if we need to expand, and expands if necessary.
  `E`
  `get(K key)`
  Return the stored element which is equal to the given key.
  `void`
  `getIterator(Consumer<Iterator<E>> consumer)`
  `E`
  `put(E element)`
  Add/replace an element.
  `E`
  `remove(K key)`
  Remove the element corresponding to the given key.
  `protected void`
  `resize(int cap)`
  Resize the internal table to given capacity.
  `int`
  `size()`

  ### Methods inherited from class org.apache.hadoop.util.LightWeightGSet

  `actualArrayLength, clear, computeCapacity, contains, convert, getIndex, iterator, printDetails, remove, toString, values`

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

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

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

  `forEach, spliterator`

- ## Constructor Details

  - ### LightWeightResizableGSet

    public LightWeightResizableGSet(int initCapacity, float loadFactor)

  - ### LightWeightResizableGSet

    public LightWeightResizableGSet()

  - ### LightWeightResizableGSet

    public LightWeightResizableGSet(int initCapacity)

- ## Method Details

  - ### put

    public E put(E element)
    Description copied from interface: `GSet`
    Add/replace an element. If the element does not exist, add it to the set. Otherwise, replace the existing element. Note that this operation is similar to `Map.put(Object, Object)` but is different from `Set.add(Object)` which does not replace the existing element if there is any.
    Specified by:
      `put` in interface `GSet<K,E extends K>`
    Overrides:
      `put` in class `LightWeightGSet<K,E extends K>`
    Parameters:
      `element` - The element being put.
    Returns:
      the previous stored element if there is any. Otherwise, return null.

  - ### get

    public E get(K key)
    Description copied from interface: `GSet`
    Return the stored element which is equal to the given key. This operation is similar to `Map.get(Object)`.
    Specified by:
      `get` in interface `GSet<K,E extends K>`
    Overrides:
      `get` in class `LightWeightGSet<K,E extends K>`
    Parameters:
      `key` - The given key.
    Returns:
      The stored element if it exists. Otherwise, return null.

  - ### remove

    public E remove(K key)
    Description copied from interface: `GSet`
    Remove the element corresponding to the given key. This operation is similar to `Map.remove(Object)`.
    Specified by:
      `remove` in interface `GSet<K,E extends K>`
    Overrides:
      `remove` in class `LightWeightGSet<K,E extends K>`
    Parameters:
      `key` - The key of the element being removed.
    Returns:
      If such element exists, return it. Otherwise, return null.

  - ### size

    public int size()
    Specified by:
      `size` in interface `GSet<K,E extends K>`
    Overrides:
      `size` in class `LightWeightGSet<K,E extends K>`
    Returns:
      The size of this set.

  - ### getIterator

    public void getIterator(Consumer<Iterator<E>> consumer)

  - ### resize

    protected void resize(int cap)
    Resize the internal table to given capacity.
    Parameters:
      `cap` - capacity.

  - ### expandIfNecessary

    protected void expandIfNecessary()
    Checks if we need to expand, and expands if necessary.