Package it.unimi.dsi.bits
Class PrefixCoderTransformationStrategy
- java.lang.Object
-
- it.unimi.dsi.bits.PrefixCoderTransformationStrategy
-
- All Implemented Interfaces:
TransformationStrategy<java.lang.CharSequence>
,java.io.Serializable
- Direct Known Subclasses:
HuTuckerTransformationStrategy
public class PrefixCoderTransformationStrategy extends java.lang.Object implements TransformationStrategy<java.lang.CharSequence>
A transformation strategy mapping strings using a prefix-free encoder.The actual encoding must be provided via a map from characters to symbols, and a set of codewords. The default return value of the map will be used for unknown characters.
This strategy creates a new
LongArrayBitVector
each timetoBitVector(CharSequence)
is invoked.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap
char2symbol
protected BitVector[]
codeWord
protected boolean
prefixFree
-
Constructor Summary
Constructors Modifier Constructor Description protected
PrefixCoderTransformationStrategy(BitVector[] codeWord, it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap char2symbol, boolean prefixFree)
protected
PrefixCoderTransformationStrategy(PrefixCoderTransformationStrategy transformationStrategy)
PrefixCoderTransformationStrategy(PrefixCoder coder, it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap char2symbol, boolean prefixFree)
Create a new transformation strategy based on a prefix-free coder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrefixCoderTransformationStrategy
copy()
Returns a copy of this transformation strategy.long
length(java.lang.CharSequence s)
Returns the length of the bit vector that would be computed byTransformationStrategy.toBitVector(Object)
.long
numBits()
The (approximate) number of bits occupied by this transformation.LongArrayBitVector
toBitVector(java.lang.CharSequence s)
Returns a bit vector representation of the given object.
-
-
-
Field Detail
-
codeWord
protected final BitVector[] codeWord
-
char2symbol
protected final it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap char2symbol
-
prefixFree
protected final boolean prefixFree
-
-
Constructor Detail
-
PrefixCoderTransformationStrategy
public PrefixCoderTransformationStrategy(PrefixCoder coder, it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap char2symbol, boolean prefixFree)
Create a new transformation strategy based on a prefix-free coder.- Parameters:
coder
- a prefix-free coder.char2symbol
- a map from character to symbols (the default returned value will be used for unknown symbols).prefixFree
- whether it is required that the resulting bit vectors are prefix-free: in this case, symbol 0 will be appended to each string, and will not be allowed to appear in any string.
-
PrefixCoderTransformationStrategy
protected PrefixCoderTransformationStrategy(PrefixCoderTransformationStrategy transformationStrategy)
-
PrefixCoderTransformationStrategy
protected PrefixCoderTransformationStrategy(BitVector[] codeWord, it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap char2symbol, boolean prefixFree)
-
-
Method Detail
-
toBitVector
public LongArrayBitVector toBitVector(java.lang.CharSequence s)
Description copied from interface:TransformationStrategy
Returns a bit vector representation of the given object.- Specified by:
toBitVector
in interfaceTransformationStrategy<java.lang.CharSequence>
- Parameters:
s
- the object to be turned into a bit-vector representation.- Returns:
- a bit-vector representation of
object
.
-
length
public long length(java.lang.CharSequence s)
Description copied from interface:TransformationStrategy
Returns the length of the bit vector that would be computed byTransformationStrategy.toBitVector(Object)
.The raison d'être of this method is that it is often easy to know the length of the representation without actually computing the representation.
- Specified by:
length
in interfaceTransformationStrategy<java.lang.CharSequence>
- Parameters:
s
- the object whose representation length is to be known.- Returns:
- the length of the bit-vector representation of
object
(the one that would be returned byTransformationStrategy.toBitVector(Object)
).
-
numBits
public long numBits()
Description copied from interface:TransformationStrategy
The (approximate) number of bits occupied by this transformation.- Specified by:
numBits
in interfaceTransformationStrategy<java.lang.CharSequence>
- Returns:
- the (approximate) number of bits occupied by this transformation.
-
copy
public PrefixCoderTransformationStrategy copy()
Description copied from interface:TransformationStrategy
Returns a copy of this transformation strategy.- Specified by:
copy
in interfaceTransformationStrategy<java.lang.CharSequence>
- Returns:
- a copy of this transformation strategy.
-
-