Class OptimizableHashSet
- java.lang.Object
-
- org.apache.flink.table.runtime.util.collections.OptimizableHashSet
-
- Direct Known Subclasses:
DoubleHashSet,FloatHashSet,IntHashSet,LongHashSet,ObjectHashSet,ShortHashSet
public abstract class OptimizableHashSet extends Object
A type-specific hash set with with a fast, small-footprint implementation. Refer to the implementation of fastutil.Instances of this class use a hash table to represent a set. The table is enlarged as needed by doubling its size when new entries are created.
The difference with fastutil is that if the range of the maximum and minimum values is small or the data is dense, a Dense array will be used to greatly improve the access speed.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancontainsNullIs this set has a null key.protected booleancontainsZeroIs this set has a zero key.static intDEFAULT_INITIAL_SIZEThe initial default size of a hash table.static floatDEFAULT_LOAD_FACTORThe default load factor of a hash table.static intDENSE_THRESHOLDDecide whether to convert to dense mode if it does not require more memory or could fit within L1 cache.protected floatfThe acceptable load factor.protected booleanisDenseIs now dense mode.protected intmaskThe mask for wrapping a position counter.protected intmaxFillThreshold after which we rehash.protected intnThe current table size.protected intsizeNumber of entries in the set.protected boolean[]usedUsed array for dense mode.
-
Constructor Summary
Constructors Constructor Description OptimizableHashSet(int expected, float f)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddNull()Add a null key.static intarraySize(int expected, float f)Returns the least power of two smaller than or equal to 230 and larger than or equal toMath.ceil( expected / f ).booleancontainsNull()Is there a null key.static intmaxFill(int n, float f)Returns the maximum number of entries that can be filled before rehashing.static longnextPowerOfTwo(long x)Return the least power of two greater than or equal to the specified value.abstract voidoptimize()Decide whether to convert to dense mode.protected intrealSize()
-
-
-
Field Detail
-
DEFAULT_INITIAL_SIZE
public static final int DEFAULT_INITIAL_SIZE
The initial default size of a hash table.- See Also:
- Constant Field Values
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTOR
The default load factor of a hash table.- See Also:
- Constant Field Values
-
DENSE_THRESHOLD
public static final int DENSE_THRESHOLD
Decide whether to convert to dense mode if it does not require more memory or could fit within L1 cache.- See Also:
- Constant Field Values
-
f
protected final float f
The acceptable load factor.
-
mask
protected int mask
The mask for wrapping a position counter.
-
n
protected int n
The current table size.
-
maxFill
protected int maxFill
Threshold after which we rehash. It must be the table size timesf.
-
containsNull
protected boolean containsNull
Is this set has a null key.
-
containsZero
protected boolean containsZero
Is this set has a zero key.
-
size
protected int size
Number of entries in the set.
-
isDense
protected boolean isDense
Is now dense mode.
-
used
protected boolean[] used
Used array for dense mode.
-
-
Method Detail
-
addNull
public void addNull()
Add a null key.
-
containsNull
public boolean containsNull()
Is there a null key.
-
realSize
protected int realSize()
-
optimize
public abstract void optimize()
Decide whether to convert to dense mode.
-
nextPowerOfTwo
public static long nextPowerOfTwo(long x)
Return the least power of two greater than or equal to the specified value.Note that this function will return 1 when the argument is 0.
- Parameters:
x- a long integer smaller than or equal to 262.- Returns:
- the least power of two greater than or equal to the specified value.
-
maxFill
public static int maxFill(int n, float f)Returns the maximum number of entries that can be filled before rehashing.- Parameters:
n- the size of the backing array.f- the load factor.- Returns:
- the maximum number of entries before rehashing.
-
arraySize
public static int arraySize(int expected, float f)Returns the least power of two smaller than or equal to 230 and larger than or equal toMath.ceil( expected / f ).- Parameters:
expected- the expected number of elements in a hash table.f- the load factor.- Returns:
- the minimum possible size for a backing array.
- Throws:
IllegalArgumentException- if the necessary size is larger than 230.
-
-