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.
  • 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.