T
- The type of the serialized form.public final class KeyCompressor<T> extends Object
T[this.size()]
is more
straightforward, but incurs linear run time for compression.DynamicOps.compressMaps()
Constructor and Description |
---|
KeyCompressor(DynamicOps<T> ops,
Stream<T> keyStream)
Constructs a new key compressor for the given key stream.
|
Modifier and Type | Method and Description |
---|---|
int |
compress(String key)
Returns the key index associated with the key the given string represents.
|
int |
compress(T key)
Returns the key index associated with the given key.
|
T |
decompress(int key)
Returns the key associated with the given key index, or
null if the key index does not
correspond to a key. |
int |
size()
The size of the key set represented by this key compressor.
|
public KeyCompressor(DynamicOps<T> ops, Stream<T> keyStream)
The key stream is consumed in the constructor. It should be finite, or else this constructor will run forever.
ops
- The DynamicOps
instance defining the serialized form.keyStream
- A stream of keys this key compressor compresses.public T decompress(int key)
null
if the key index does not
correspond to a key.
Caution: This is one of the few methods in DFU that may return null
.
key
- The key index.null
if the key index is invalid.public int compress(String key)
-1
is returned.key
- The string representation of a key.-1
if the key does not exist.compress(Object)
public int compress(T key)
-1
is returned.key
- The key.-1
if the key is invalid.public int size()