Class OptimizableHashSet
java.lang.Object
org.apache.flink.table.runtime.util.collections.OptimizableHashSet
- Direct Known Subclasses:
DoubleHashSet,FloatHashSet,IntHashSet,LongHashSet,ObjectHashSet,ShortHashSet
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
FieldsModifier and TypeFieldDescriptionprotected booleanIs this set has a null key.protected booleanIs this set has a zero key.static final intThe initial default size of a hash table.static final floatThe default load factor of a hash table.static final intDecide whether to convert to dense mode if it does not require more memory or could fit within L1 cache.protected final floatThe acceptable load factor.protected booleanIs now dense mode.protected intThe mask for wrapping a position counter.protected intThreshold after which we rehash.protected intThe current table size.protected intNumber of entries in the set.protected boolean[]Used array for dense mode. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNull()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 ).booleanIs 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 Details
-
DEFAULT_INITIAL_SIZE
public static final int DEFAULT_INITIAL_SIZEThe initial default size of a hash table.- See Also:
-
DEFAULT_LOAD_FACTOR
public static final float DEFAULT_LOAD_FACTORThe default load factor of a hash table.- See Also:
-
DENSE_THRESHOLD
public static final int DENSE_THRESHOLDDecide whether to convert to dense mode if it does not require more memory or could fit within L1 cache.- See Also:
-
f
protected final float fThe acceptable load factor. -
mask
protected int maskThe mask for wrapping a position counter. -
n
protected int nThe current table size. -
maxFill
protected int maxFillThreshold after which we rehash. It must be the table size timesf. -
containsNull
protected boolean containsNullIs this set has a null key. -
containsZero
protected boolean containsZeroIs this set has a zero key. -
size
protected int sizeNumber of entries in the set. -
isDense
protected boolean isDenseIs now dense mode. -
used
protected boolean[] usedUsed array for dense mode.
-
-
Constructor Details
-
OptimizableHashSet
public OptimizableHashSet(int expected, float f)
-
-
Method Details
-
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.
-