Package it.unimi.dsi.sux4j.mph
Class TwoStepsGOV3Function<T>
java.lang.Object
it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction<K>
it.unimi.dsi.sux4j.mph.AbstractHashFunction<T>
it.unimi.dsi.sux4j.mph.TwoStepsGOV3Function<T>
- All Implemented Interfaces:
Function<T,
,Long> Object2LongFunction<T>
,Size64
,Serializable
,Function<T,
,Long> ToLongFunction<T>
public class TwoStepsGOV3Function<T>
extends AbstractHashFunction<T>
implements Serializable, Size64
A function stored using two GOV3Functions—one for
frequent values, and one for infrequent values. This naive idea turns out to be very effective in reducing the function
size when the distribution of values is skewed (e.g., as it happens in a
TwoStepsLcpMonotoneMinimalPerfectHashFunction
).
To create an instance, we perform a pre-scan of the values to be assigned. If possible, we finds the best possible
r such that the 2r − 1 most frequent values can be stored in a GOV3Function
and suitably remapped when read. The function uses 2r − 1 as an escape symbol for all other
values, which are stored in a separate function.
Warning: during the construction phase, a filter
will be set on the BucketedHashStore
used to store the keys. If you are passing a store,
you will have to reset it to its previous state.
- Since:
- 4.0
- Author:
- Sebastiano Vigna
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
The escape value returned byfirstFunction
to suggest thatsecondFunction
should be queried instead, provided that there is a first function.protected final GOV3Function<T>
The first function, ornull
.protected final long
The number of keys.protected final double
The mean of the rank distribution.protected final long[]
A mapping from values of the first function to actual values, provided that there is a first function.protected final GOV3Function<T>
The second function.protected long
The seed to be used when converting keys to signatures.static final long
protected final TransformationStrategy<? super T>
The transformation strategy to turn objects of typeT
into bit vectors.protected final int
The width of the output of this function, in bits.Fields inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defRetValue
-
Constructor Summary
ModifierConstructorDescriptionprotected
TwoStepsGOV3Function
(Iterable<? extends T> keys, TransformationStrategy<? super T> transform, LongBigList values, File tempDir, BucketedHashStore<T> bucketedHashStore) Creates a new two-step function for the given keys and values. -
Method Summary
Methods inherited from class it.unimi.dsi.sux4j.mph.AbstractHashFunction
containsKey, size
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defaultReturnValue, defaultReturnValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface it.unimi.dsi.fastutil.objects.Object2LongFunction
andThen, andThenByte, andThenChar, andThenDouble, andThenFloat, andThenInt, andThenLong, andThenObject, andThenReference, andThenShort, applyAsLong, composeByte, composeChar, composeDouble, composeFloat, composeInt, composeLong, composeObject, composeReference, composeShort, get, getOrDefault, getOrDefault, put, put, remove, removeLong
-
Field Details
-
serialVersionUID
public static final long serialVersionUID- See Also:
-
n
protected final long nThe number of keys. -
transform
The transformation strategy to turn objects of typeT
into bit vectors. -
firstFunction
The first function, ornull
. The special output valueescape
denotes thatsecondFunction
should be queried instead. -
secondFunction
The second function. All queries for whichfirstFunction
returnsescape
(or simply all queries, iffirstFunction
isnull
) will be rerouted here. -
remap
protected final long[] remapA mapping from values of the first function to actual values, provided that there is a first function. -
escape
protected final int escapeThe escape value returned byfirstFunction
to suggest thatsecondFunction
should be queried instead, provided that there is a first function. -
seed
protected long seedThe seed to be used when converting keys to signatures. -
width
protected final int widthThe width of the output of this function, in bits. -
rankMean
protected final double rankMeanThe mean of the rank distribution.
-
-
Constructor Details
-
TwoStepsGOV3Function
protected TwoStepsGOV3Function(Iterable<? extends T> keys, TransformationStrategy<? super T> transform, LongBigList values, File tempDir, BucketedHashStore<T> bucketedHashStore) throws IOException Creates a new two-step function for the given keys and values.- Parameters:
keys
- the keys in the domain of the function.transform
- a transformation strategy for the keys.values
- values to be assigned to each key, in the same order of the iterator returned bykeys
; ifnull
, the assigned value will the ordinal number of each key.tempDir
- a temporary directory for the store files, ornull
for the standard temporary directory.bucketedHashStore
- a bucketed hash store containing the keys associated with their rank, ornull
; the store can be unchecked, but in this casekeys
andtransform
must be non-null
.- Throws:
IOException
-
-
Method Details
-
getLong
- Specified by:
getLong
in interfaceObject2LongFunction<T>
-
getLongBySignature
public long getLongBySignature(long[] signature) -
size64
public long size64()- Specified by:
size64
in interfaceSize64
- Overrides:
size64
in classAbstractHashFunction<T>
-
numBits
public long numBits()Returns the number of bits used by this structure.- Returns:
- the number of bits used by this structure.
-
main
-