Package org.apache.hadoop.hdfs.util
Class LightWeightLinkedSet<T>
java.lang.Object
org.apache.hadoop.hdfs.util.LightWeightHashSet<T>
org.apache.hadoop.hdfs.util.LightWeightLinkedSet<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>
A low memory linked hash set implementation, which uses an array for storing
the elements and linked lists for collision resolution. In addition it stores
elements in a linked list to ensure ordered traversal. This class does not
support null element.
This class is not thread safe.
-
Field Summary
Fields inherited from class org.apache.hadoop.hdfs.util.LightWeightHashSet
DEFAULT_MAX_LOAD_FACTOR, DEFAUT_MIN_LOAD_FACTOR, entries, MINIMUM_CAPACITY, modification, size -
Constructor Summary
ConstructorsConstructorDescriptionLightWeightLinkedSet(int initCapacity, float maxLoadFactor, float minLoadFactor) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanAdd given element to the hash tablevoidclear()Clear the set.Returns a new iterator starting at the bookmarked element.iterator()pollAll()Remove all elements from the set and return them in order.Remove and return first element on the linked list of all elements.pollN(int n) Remove and return n elements from the hashtable.protected org.apache.hadoop.hdfs.util.LightWeightLinkedSet.DoubleLinkedElement<T>removeElem(T key) Remove the element corresponding to the key, given key.hashCode() == index.voidResets the bookmark to the beginning of the list.<U> U[]toArray(U[] a) Methods inherited from class org.apache.hadoop.hdfs.util.LightWeightHashSet
add, addAll, contains, containsAll, expandIfNecessary, getCapacity, getContainedElem, getElement, getIndex, isEmpty, pollToArray, printDetails, remove, removeAll, retainAll, shrinkIfNecessary, size, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
LightWeightLinkedSet
public LightWeightLinkedSet(int initCapacity, float maxLoadFactor, float minLoadFactor) - Parameters:
initCapacity- Recommended size of the internal array.maxLoadFactor- used to determine when to expand the internal arrayminLoadFactor- used to determine when to shrink the internal array
-
LightWeightLinkedSet
public LightWeightLinkedSet()
-
-
Method Details
-
addElem
Add given element to the hash table- Overrides:
addElemin classLightWeightHashSet<T>- Returns:
- true if the element was not present in the table, false otherwise
-
removeElem
Remove the element corresponding to the key, given key.hashCode() == index.- Overrides:
removeElemin classLightWeightHashSet<T>- Returns:
- Return the entry with the element if exists. Otherwise return null.
-
pollFirst
Remove and return first element on the linked list of all elements.- Returns:
- first element
-
pollN
Remove and return n elements from the hashtable. The order in which entries are removed is corresponds to the order in which they were inserted.- Overrides:
pollNin classLightWeightHashSet<T>- Returns:
- first element
-
pollAll
Remove all elements from the set and return them in order. Traverse the link list, don't worry about hashtable - faster version of the parent method.- Overrides:
pollAllin classLightWeightHashSet<T>
-
toArray
public <U> U[] toArray(U[] a) - Specified by:
toArrayin interfaceCollection<T>- Overrides:
toArrayin classLightWeightHashSet<T>
-
iterator
- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Overrides:
iteratorin classLightWeightHashSet<T>
-
clear
public void clear()Clear the set. Resize it to the original capacity.- Specified by:
clearin interfaceCollection<T>- Overrides:
clearin classLightWeightHashSet<T>
-
getBookmark
Returns a new iterator starting at the bookmarked element.- Returns:
- the iterator to the bookmarked element.
-
resetBookmark
public void resetBookmark()Resets the bookmark to the beginning of the list.
-