public abstract class OptimizableHashSet extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
containsNull
Is this set has a null key.
|
protected boolean |
containsZero
Is this set has a zero key.
|
static int |
DEFAULT_INITIAL_SIZE
The initial default size of a hash table.
|
static float |
DEFAULT_LOAD_FACTOR
The default load factor of a hash table.
|
static int |
DENSE_THRESHOLD
Decide whether to convert to dense mode if it does not require more memory or could fit
within L1 cache.
|
protected float |
f
The acceptable load factor.
|
protected boolean |
isDense
Is now dense mode.
|
protected int |
mask
The mask for wrapping a position counter.
|
protected int |
maxFill
Threshold after which we rehash.
|
protected int |
n
The current table size.
|
protected int |
size
Number of entries in the set.
|
protected boolean[] |
used
Used array for dense mode.
|
Constructor and Description |
---|
OptimizableHashSet(int expected,
float f) |
Modifier and Type | Method and Description |
---|---|
void |
addNull()
Add a null key.
|
static int |
arraySize(int expected,
float f)
Returns the least power of two smaller than or equal to 230 and larger than or
equal to
Math.ceil( expected / f ) . |
boolean |
containsNull()
Is there a null key.
|
static int |
maxFill(int n,
float f)
Returns the maximum number of entries that can be filled before rehashing.
|
static long |
nextPowerOfTwo(long x)
Return the least power of two greater than or equal to the specified value.
|
abstract void |
optimize()
Decide whether to convert to dense mode.
|
protected int |
realSize() |
public static final int DEFAULT_INITIAL_SIZE
public static final float DEFAULT_LOAD_FACTOR
public static final int DENSE_THRESHOLD
protected final float f
protected int mask
protected int n
protected int maxFill
f
.protected boolean containsNull
protected boolean containsZero
protected int size
protected boolean isDense
protected boolean[] used
public void addNull()
public boolean containsNull()
protected int realSize()
public abstract void optimize()
public static long nextPowerOfTwo(long x)
Note that this function will return 1 when the argument is 0.
x
- a long integer smaller than or equal to 262.public static int maxFill(int n, float f)
n
- the size of the backing array.f
- the load factor.public static int arraySize(int expected, float f)
Math.ceil( expected / f )
.expected
- the expected number of elements in a hash table.f
- the load factor.IllegalArgumentException
- if the necessary size is larger than 230.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.