Package org.apache.hadoop.util
Class LightWeightGSet<K,E extends K>
java.lang.Object
org.apache.hadoop.util.LightWeightGSet<K,E>
- Type Parameters:
K- Key type for looking up the elementsE- Element type, which must be (1) a subclass of K, and (2) implementingLightWeightGSet.LinkedElementinterface.
- Direct Known Subclasses:
LightWeightCache,LightWeightResizableGSet
A low memory footprint
GSet implementation,
which uses an array for storing the elements
and linked lists for collision resolution.
No rehash will be performed.
Therefore, the internal array will never be resized.
This class does not support null element.
This class is not thread safe.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LightWeightGSet.LinkedElement[]An internal array of entries, which are the rows of the hash table.protected intA mask for computing the array index from the hash value of an element.protected intModification version for fail-fast.protected intThe size of the set (not the entry array). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intactualArrayLength(int recommended) voidclear()Clear the set.static intcomputeCapacity(double percentage, String mapName) Let t = percentage of max memory.booleanDoes this set contain an element corresponding to the given key?protected EReturn the stored element which is equal to the given key.protected intiterator()voidprintDetails(PrintStream out) Print detailed information of this object.Add/replace an element.protected ERemove the element corresponding to the key, given key.hashCode() == index.Remove the element corresponding to the given key.intsize()toString()values()Returns aCollectionview of the values contained in this set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
entries
An internal array of entries, which are the rows of the hash table. The size must be a power of two. -
hash_mask
protected int hash_maskA mask for computing the array index from the hash value of an element. -
size
protected int sizeThe size of the set (not the entry array). -
modification
protected int modificationModification version for fail-fast.- See Also:
-
-
Constructor Details
-
LightWeightGSet
protected LightWeightGSet() -
LightWeightGSet
public LightWeightGSet(int recommended_length) - Parameters:
recommended_length- Recommended size of the internal array.
-
-
Method Details
-
actualArrayLength
protected static int actualArrayLength(int recommended) -
size
public int size() -
getIndex
-
convert
-
get
Description copied from interface:GSetReturn the stored element which is equal to the given key. This operation is similar toMap.get(Object). -
contains
Description copied from interface:GSetDoes this set contain an element corresponding to the given key? -
put
Description copied from interface:GSetAdd/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 toMap.put(Object, Object)but is different fromSet.add(Object)which does not replace the existing element if there is any. -
remove
Remove the element corresponding to the key, given key.hashCode() == index.- Parameters:
key- key.index- index.- Returns:
- If such element exists, return it. Otherwise, return null.
-
remove
Description copied from interface:GSetRemove the element corresponding to the given key. This operation is similar toMap.remove(Object). -
values
Description copied from interface:GSetReturns aCollectionview of the values contained in this set. The collection is backed by the set, so changes to the set are reflected in the collection, and vice-versa. -
iterator
-
toString
-
printDetails
Print detailed information of this object.- Parameters:
out- out.
-
computeCapacity
Let t = percentage of max memory. Let e = round(log_2 t). Then, we choose capacity = 2^e/(size of reference), unless it is outside the close interval [1, 2^30].- Parameters:
mapName- mapName.percentage- percentage.- Returns:
- compute capacity.
-
clear
public void clear()Description copied from interface:GSetClear the set.
-