Package it.unimi.dsi.sux4j.mph
Class MWHCFunction.Builder<T>
- java.lang.Object
-
- it.unimi.dsi.sux4j.mph.MWHCFunction.Builder<T>
-
- Enclosing class:
- MWHCFunction<T>
public static class MWHCFunction.Builder<T> extends java.lang.Object
A builder class forMWHCFunction
.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
built
Whetherbuild()
has already been called.protected ChunkedHashStore<T>
chunkedHashStore
protected boolean
indirect
protected java.lang.Iterable<? extends T>
keys
protected int
outputWidth
protected int
signatureWidth
protected java.io.File
tempDir
protected it.unimi.dsi.bits.TransformationStrategy<? super T>
transform
protected it.unimi.dsi.fastutil.longs.LongIterable
values
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MWHCFunction<T>
build()
Builds a new function.MWHCFunction.Builder<T>
dictionary(int signatureWidth)
Specifies that the resultingMWHCFunction
should be an approximate dictionary: the output value will be a signature, andMWHCFunction.getLong(Object)
will return 1 or 0 depending on whether the argument was in the key set or not; in this case, you cannot specify values.MWHCFunction.Builder<T>
indirect()
MWHCFunction.Builder<T>
keys(java.lang.Iterable<? extends T> keys)
Specifies the keys of the function; if you have specified ait.unimi.dsi.sux4j.io.ChunkedHashStore
, it can benull
.MWHCFunction.Builder<T>
signed(int signatureWidth)
Specifies that the resultingMWHCFunction
should be signed using a given number of bits per element; in this case, you cannot specify values.MWHCFunction.Builder<T>
store(ChunkedHashStore<T> chunkedHashStore)
Specifies a chunked hash store containing the keys.MWHCFunction.Builder<T>
tempDir(java.io.File tempDir)
Specifies a temporary directory for theit.unimi.dsi.sux4j.io.ChunkedHashStore
.MWHCFunction.Builder<T>
transform(it.unimi.dsi.bits.TransformationStrategy<? super T> transform)
Specifies the transformation strategy for the keys of the function.MWHCFunction.Builder<T>
values(it.unimi.dsi.fastutil.longs.LongIterable values)
Specifies the values assigned to the keys; the output width of the function will be the minimum width needed to represent all values.MWHCFunction.Builder<T>
values(it.unimi.dsi.fastutil.longs.LongIterable values, int outputWidth)
Specifies the values assigned to the keys.
-
-
-
Field Detail
-
keys
protected java.lang.Iterable<? extends T> keys
-
transform
protected it.unimi.dsi.bits.TransformationStrategy<? super T> transform
-
signatureWidth
protected int signatureWidth
-
tempDir
protected java.io.File tempDir
-
chunkedHashStore
protected ChunkedHashStore<T> chunkedHashStore
-
values
protected it.unimi.dsi.fastutil.longs.LongIterable values
-
outputWidth
protected int outputWidth
-
indirect
protected boolean indirect
-
built
protected boolean built
Whetherbuild()
has already been called.
-
-
Method Detail
-
keys
public MWHCFunction.Builder<T> keys(java.lang.Iterable<? extends T> keys)
Specifies the keys of the function; if you have specified ait.unimi.dsi.sux4j.io.ChunkedHashStore
, it can benull
.- Parameters:
keys
- the keys of the function.- Returns:
- this builder.
-
transform
public MWHCFunction.Builder<T> transform(it.unimi.dsi.bits.TransformationStrategy<? super T> transform)
Specifies the transformation strategy for the keys of the function.- Parameters:
transform
- a transformation strategy for the keys of the function.- Returns:
- this builder.
-
signed
public MWHCFunction.Builder<T> signed(int signatureWidth)
Specifies that the resultingMWHCFunction
should be signed using a given number of bits per element; in this case, you cannot specify values.- Parameters:
signatureWidth
- a signature width, or 0 for no signature (a negative value will have the same effect ofdictionary(int)
with the opposite argument).- Returns:
- this builder.
-
dictionary
public MWHCFunction.Builder<T> dictionary(int signatureWidth)
Specifies that the resultingMWHCFunction
should be an approximate dictionary: the output value will be a signature, andMWHCFunction.getLong(Object)
will return 1 or 0 depending on whether the argument was in the key set or not; in this case, you cannot specify values.Note that checking against a signature has the usual probability of a false positive.
- Parameters:
signatureWidth
- a signature width, or 0 for no signature (a negative value will have the same effect ofsigned(int)
with the opposite argument).- Returns:
- this builder.
-
tempDir
public MWHCFunction.Builder<T> tempDir(java.io.File tempDir)
Specifies a temporary directory for theit.unimi.dsi.sux4j.io.ChunkedHashStore
.- Parameters:
tempDir
- a temporary directory for theit.unimi.dsi.sux4j.io.ChunkedHashStore
files, ornull
for the standard temporary directory.- Returns:
- this builder.
-
store
public MWHCFunction.Builder<T> store(ChunkedHashStore<T> chunkedHashStore)
-
values
public MWHCFunction.Builder<T> values(it.unimi.dsi.fastutil.longs.LongIterable values, int outputWidth)
Specifies the values assigned to the keys.Contrarily to
values(LongIterable)
, this method does not require a complete scan of the value to determine the output width.- Parameters:
values
- values to be assigned to each element, in the same order of the keys.outputWidth
- the bit width of the output of the function, which must be enough to represent allvalues
.- Returns:
- this builder.
- See Also:
values(LongIterable)
-
values
public MWHCFunction.Builder<T> values(it.unimi.dsi.fastutil.longs.LongIterable values)
Specifies the values assigned to the keys; the output width of the function will be the minimum width needed to represent all values.Contrarily to
values(LongIterable, int)
, this method requires a complete scan of the value to determine the output width.- Parameters:
values
- values to be assigned to each element, in the same order of the keys.- Returns:
- this builder.
- See Also:
values(LongIterable,int)
-
indirect
public MWHCFunction.Builder<T> indirect()
Specifies that the function construction must be indirect: a provided store contains indices that must be used to access the values.If you specify this option, the provided values must be a
LongList
or aLongBigList
.- Returns:
- this builder.
-
build
public MWHCFunction<T> build() throws java.io.IOException
Builds a new function.- Returns:
- an
MWHCFunction
instance with the specified parameters. - Throws:
java.lang.IllegalStateException
- if called more than once.java.io.IOException
-
-