Class LongLong2LongOpenCustomBigHashMap
- java.lang.Object
-
- io.prestosql.util.LongLong2LongOpenCustomBigHashMap
-
- All Implemented Interfaces:
it.unimi.dsi.fastutil.Hash
public class LongLong2LongOpenCustomBigHashMap extends Object implements it.unimi.dsi.fastutil.Hash
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LongLong2LongOpenCustomBigHashMap.HashStrategy
-
Nested classes/interfaces inherited from interface it.unimi.dsi.fastutil.Hash
it.unimi.dsi.fastutil.Hash.Strategy<K extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
containsNullKey
Whether this map contains the key zero.protected long
defRetValue
The default return value forget()
,put()
andremove()
.protected float
f
The acceptable load factor.protected LongBigArray
key
The array of keys.protected long
mask
The mask for wrapping a position counter.protected long
maxFill
Threshold after which we rehash.protected long
minN
We never resize below this threshold, which is the construction-time {#n}.protected long
n
The current table size.protected long
size
Number of entries in the set (including the key zero, if present).protected LongLong2LongOpenCustomBigHashMap.HashStrategy
strategy
The hash strategy of this custom map.protected LongBigArray
value
The array of values.
-
Constructor Summary
Constructors Constructor Description LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map.LongLong2LongOpenCustomBigHashMap(long expected, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map withHash.DEFAULT_LOAD_FACTOR
as load factor.LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZE
entries andHash.DEFAULT_LOAD_FACTOR
as load factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addTo(long k1, long k2, long incr)
Adds an increment to value currently associated with a key.void
clear()
long
computeIfAbsent(long k1, long k2, LongBinaryOperator mappingFunction)
boolean
containsKey(long k1, long k2)
boolean
containsValue(long v)
long
defaultReturnValue()
void
defaultReturnValue(long rv)
long
get(long k1, long k2)
long
getOrDefault(long k1, long k2, long defaultValue)
boolean
isEmpty()
long
merge(long k1, long k2, long v, BiFunction<? super Long,? super Long,? extends Long> remappingFunction)
long
put(long k1, long k2, long v)
long
putIfAbsent(long k1, long k2, long v)
protected void
rehash(long newN)
Rehashes the map.long
remove(long k1, long k2)
boolean
remove(long k1, long k2, long v)
long
replace(long k1, long k2, long v)
boolean
replace(long k1, long k2, long oldValue, long v)
protected void
shiftKeys(long pos)
Shifts left entries with the specified hash code, starting at the specified position, and empties the resulting free entry.long
size()
long
sizeOf()
Returns the size of this hash map in bytes.LongLong2LongOpenCustomBigHashMap.HashStrategy
strategy()
Returns the hashing strategy.boolean
trim()
Rehashes the map, making the table as small as possible.boolean
trim(long n)
Rehashes this map if the table is too large.
-
-
-
Field Detail
-
key
protected LongBigArray key
The array of keys.
-
value
protected LongBigArray value
The array of values.
-
mask
protected long mask
The mask for wrapping a position counter.
-
containsNullKey
protected boolean containsNullKey
Whether this map contains the key zero.
-
strategy
protected final LongLong2LongOpenCustomBigHashMap.HashStrategy strategy
The hash strategy of this custom map.
-
n
protected long n
The current table size.
-
maxFill
protected long maxFill
Threshold after which we rehash. It must be the table size timesf
.
-
minN
protected final long minN
We never resize below this threshold, which is the construction-time {#n}.
-
size
protected long size
Number of entries in the set (including the key zero, if present).
-
f
protected final float f
The acceptable load factor.
-
defRetValue
protected long defRetValue
The default return value forget()
,put()
andremove()
.
-
-
Constructor Detail
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map.The actual table size will be the least power of two greater than
expected
/f
.- Parameters:
expected
- the expected number of elements in the hash map.f
- the load factor.strategy
- the strategy.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(long expected, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map withHash.DEFAULT_LOAD_FACTOR
as load factor.- Parameters:
expected
- the expected number of elements in the hash map.strategy
- the strategy.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZE
entries andHash.DEFAULT_LOAD_FACTOR
as load factor.- Parameters:
strategy
- the strategy.
-
-
Method Detail
-
defaultReturnValue
public void defaultReturnValue(long rv)
-
defaultReturnValue
public long defaultReturnValue()
-
sizeOf
public long sizeOf()
Returns the size of this hash map in bytes.
-
strategy
public LongLong2LongOpenCustomBigHashMap.HashStrategy strategy()
Returns the hashing strategy.- Returns:
- the hashing strategy of this custom hash map.
-
put
public long put(long k1, long k2, long v)
-
addTo
public long addTo(long k1, long k2, long incr)
Adds an increment to value currently associated with a key.Note that this method respects the default return value semantics: when called with a key that does not currently appears in the map, the key will be associated with the default return value plus the given increment.
- Parameters:
k1
- the first half of key.k2
- the second half of key.incr
- the increment.- Returns:
- the old value, or the default return value if no value was present for the given key.
-
shiftKeys
protected final void shiftKeys(long pos)
Shifts left entries with the specified hash code, starting at the specified position, and empties the resulting free entry.- Parameters:
pos
- a starting position.
-
remove
public long remove(long k1, long k2)
-
get
public long get(long k1, long k2)
-
containsKey
public boolean containsKey(long k1, long k2)
-
containsValue
public boolean containsValue(long v)
-
getOrDefault
public long getOrDefault(long k1, long k2, long defaultValue)
-
putIfAbsent
public long putIfAbsent(long k1, long k2, long v)
-
remove
public boolean remove(long k1, long k2, long v)
-
replace
public boolean replace(long k1, long k2, long oldValue, long v)
-
replace
public long replace(long k1, long k2, long v)
-
computeIfAbsent
public long computeIfAbsent(long k1, long k2, LongBinaryOperator mappingFunction)
-
merge
public long merge(long k1, long k2, long v, BiFunction<? super Long,? super Long,? extends Long> remappingFunction)
-
clear
public void clear()
-
size
public long size()
-
isEmpty
public boolean isEmpty()
-
trim
public boolean trim()
Rehashes the map, making the table as small as possible.This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size.
If the table size is already the minimum possible, this method does nothing.
- Returns:
- true if there was enough memory to trim the map.
- See Also:
trim(long)
-
trim
public boolean trim(long n)
Rehashes this map if the table is too large.Let N be the smallest table size that can hold
max(n,
entries, still satisfying the load factor. If the current table size is smaller than or equal to N, this method does nothing. Otherwise, it rehashes this map in a table of size N.size()
)This method is useful when reusing maps. Clearing a map leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical size to avoid keeping around a very large table just because of a few large transient maps.
- Parameters:
n
- the threshold for the trimming.- Returns:
- true if there was enough memory to trim the map.
- See Also:
trim()
-
rehash
protected void rehash(long newN)
Rehashes the map.This method implements the basic rehashing strategy, and may be overridden by subclasses implementing different rehashing strategies (e.g., disk-based rehashing). However, you should not override this method unless you understand the internal workings of this class.
- Parameters:
newN
- the new size
-
-