Class LongLong2LongOpenCustomBigHashMap
- java.lang.Object
-
- io.trino.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 interfaceLongLong2LongOpenCustomBigHashMap.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 booleancontainsNullKeyWhether this map contains the key zero.protected longdefRetValueThe default return value forget(),put()andremove().protected floatfThe acceptable load factor.protected LongBigArraykey1The array of keys.protected LongBigArraykey2protected longmaskThe mask for wrapping a position counter.protected longmaxFillThreshold after which we rehash.protected longminNWe never resize below this threshold, which is the construction-time {#n}.protected longnThe current table size.protected longnullKey1The two-part value denoting unmapped keys (or null keys).protected longnullKey2protected longsizeNumber of entries in the set (including the key zero, if present).protected LongLong2LongOpenCustomBigHashMap.HashStrategystrategyThe hash strategy of this custom map.protected LongBigArrayvalueThe array of values.
-
Constructor Summary
Constructors Constructor Description LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)Creates a new hash map and zero based null keys.LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)Creates a new hash map.LongLong2LongOpenCustomBigHashMap(long expected, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)Creates a new hash map withHash.DEFAULT_LOAD_FACTORas load factor and zero based null keys.LongLong2LongOpenCustomBigHashMap(long expected, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)Creates a new hash map withHash.DEFAULT_LOAD_FACTORas load factor.LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZEentries,Hash.DEFAULT_LOAD_FACTORas load factor, and zero based null keys.LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZEentries andHash.DEFAULT_LOAD_FACTORas load factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddTo(long k1, long k2, long incr)Adds an increment to value currently associated with a key.voidclear()longcomputeIfAbsent(long k1, long k2, LongBinaryOperator mappingFunction)booleancontainsKey(long k1, long k2)booleancontainsValue(long v)longdefaultReturnValue()voiddefaultReturnValue(long rv)longget(long k1, long k2)longgetOrDefault(long k1, long k2, long defaultValue)booleanisEmpty()longmerge(long k1, long k2, long v, BiFunction<? super Long,? super Long,? extends Long> remappingFunction)longput(long k1, long k2, long v)longputIfAbsent(long k1, long k2, long v)protected voidrehash(long newN)Rehashes the map.longremove(long k1, long k2)booleanremove(long k1, long k2, long v)longreplace(long k1, long k2, long v)booleanreplace(long k1, long k2, long oldValue, long v)protected voidshiftKeys(long pos)Shifts left entries with the specified hash code, starting at the specified position, and empties the resulting free entry.longsize()longsizeOf()Returns the size of this hash map in bytes.LongLong2LongOpenCustomBigHashMap.HashStrategystrategy()Returns the hashing strategy.booleantrim()Rehashes the map, making the table as small as possible.booleantrim(long n)Rehashes this map if the table is too large.
-
-
-
Field Detail
-
key1
protected LongBigArray key1
The array of keys.
-
key2
protected LongBigArray key2
-
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().
-
nullKey1
protected final long nullKey1
The two-part value denoting unmapped keys (or null keys). These values may be passed back via the HashStrategy callback during equality checks, even though no keys with these values have been added.
-
nullKey2
protected final long nullKey2
-
-
Constructor Detail
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)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.nullKey1- first half of the representation for unmapped keys.nullKey2- second half of the representation for unmapped keys.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(long expected, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)Creates a new hash map withHash.DEFAULT_LOAD_FACTORas load factor.- Parameters:
expected- the expected number of elements in the hash map.strategy- the strategy.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(long expected, float f, LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)Creates a new hash map and zero based null keys.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_FACTORas load factor and zero based null keys.- Parameters:
expected- the expected number of elements in the hash map.strategy- the strategy.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy, long nullKey1, long nullKey2)
Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZEentries andHash.DEFAULT_LOAD_FACTORas load factor.- Parameters:
strategy- the strategy.nullKey1- first half of the representation for unmapped keys.nullKey2- second half of the representation for unmapped keys.
-
LongLong2LongOpenCustomBigHashMap
public LongLong2LongOpenCustomBigHashMap(LongLong2LongOpenCustomBigHashMap.HashStrategy strategy)
Creates a new hash map with initial expectedBigArrays.SEGMENT_SIZEentries,Hash.DEFAULT_LOAD_FACTORas load factor, and zero based null keys.- 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
-
-