public class SerializationUtil extends Object
ISchemaVersion
implementations. The structure of
a serialized HLL's metadata should be opaque to the rest of the
library.Modifier and Type | Field and Description |
---|---|
static ISchemaVersion |
DEFAULT_SCHEMA_VERSION
The default schema version for serializing HLLs.
|
static ISchemaVersion[] |
REGISTERED_SCHEMA_VERSIONS
List of registered schema versions, indexed by their version numbers.
|
static ISchemaVersion |
VERSION_ONE
Schema version one (v1).
|
Constructor and Description |
---|
SerializationUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
explicitCutoff(byte cutoffByte)
Extracts the explicit cutoff value from the cutoff byte of a serialized
HLL.
|
static ISchemaVersion |
getSchemaVersion(byte[] bytes)
Get the appropriate
schema version for the specified
serialized HLL. |
static ISchemaVersion |
getSchemaVersion(int schemaVersionNumber) |
static byte |
packCutoffByte(int explicitCutoff,
boolean sparseEnabled)
Generates a byte that encodes the log-base-2 of the explicit cutoff
or sentinel values for 'explicit-disabled' or 'auto', as well as the
boolean indicating whether to use
HLLType.SPARSE
in the promotion hierarchy. |
static byte |
packParametersByte(int registerWidth,
int registerCountLog2)
Generates a byte that encodes the parameters of a
HLLType.FULL or HLLType.SPARSE
HLL.
The top 3 bits are used to encode registerWidth - 1
(range of registerWidth is thus 1-9) and the bottom 5
bits are used to encode registerCountLog2
(range of registerCountLog2 is thus 0-31). |
static byte |
packVersionByte(int schemaVersion,
int typeOrdinal)
Generates a byte that encodes the schema version and the type ordinal
of the HLL.
|
static int |
registerCountLog2(byte parametersByte)
Extracts the log2(registerCount) from the parameters byte of a
serialized
HLLType.FULL HLL. |
static int |
registerWidth(byte parametersByte)
Extracts the register width from the parameters byte of a serialized
HLLType.FULL HLL. |
static int |
schemaVersion(byte versionByte)
Extracts the schema version from the version byte of a serialized
HLL.
|
static boolean |
sparseEnabled(byte cutoffByte)
Extracts the 'sparse-enabled' boolean from the cutoff byte of a serialized
HLL.
|
static int |
typeOrdinal(byte versionByte)
Extracts the type ordinal from the version byte of a serialized HLL.
|
public static ISchemaVersion VERSION_ONE
public static ISchemaVersion DEFAULT_SCHEMA_VERSION
public static ISchemaVersion[] REGISTERED_SCHEMA_VERSIONS
null
, then no such schema version is registered.
Similarly, registering a new schema version simply entails assigning an
ISchemaVersion
instance to the appropriate index of this array.
By default, only SchemaVersionOne
is registered. Note that version
zero will always be reserved for internal (e.g. proprietary, legacy) schema
specifications/implementations and will never be assigned to in by this
library.public static ISchemaVersion getSchemaVersion(int schemaVersionNumber)
schemaVersionNumber
- the version number of the ISchemaVersion
desired. This must be a registered schema version number.ISchemaVersion
for the given number. This will never
be null
.public static ISchemaVersion getSchemaVersion(byte[] bytes)
schema version
for the specified
serialized HLL.bytes
- the serialized HLL whose schema version is desired.null
.public static byte packVersionByte(int schemaVersion, int typeOrdinal)
schemaVersion
- the schema version to encode.typeOrdinal
- the type ordinal of the HLL to encode.public static byte packCutoffByte(int explicitCutoff, boolean sparseEnabled)
HLLType.SPARSE
in the promotion hierarchy.
The top bit is always padding, the second highest bit indicates the
'sparse-enabled' boolean, and the lowest six bits encode the explicit
cutoff value.explicitCutoff
- the explicit cutoff value to encode.
0
.
63
.
0 <= n < 31
,
this value should be n + 1
.
sparseEnabled
- whether HLLType.SPARSE
should be used in the promotion hierarchy to improve HLL
storage.public static byte packParametersByte(int registerWidth, int registerCountLog2)
HLLType.FULL
or HLLType.SPARSE
HLL.
The top 3 bits are used to encode registerWidth - 1
(range of registerWidth
is thus 1-9) and the bottom 5
bits are used to encode registerCountLog2
(range of registerCountLog2
is thus 0-31).registerWidth
- the register width (must be at least 1 and at
most 9)registerCountLog2
- the log-base-2 of the register count (must
be at least 0 and at most 31)public static boolean sparseEnabled(byte cutoffByte)
cutoffByte
- the cutoff byte of the serialized HLLpublic static int explicitCutoff(byte cutoffByte)
cutoffByte
- the cutoff byte of the serialized HLLpublic static int schemaVersion(byte versionByte)
versionByte
- the version byte of the serialized HLLpublic static int typeOrdinal(byte versionByte)
versionByte
- the version byte of the serialized HLLpublic static int registerWidth(byte parametersByte)
HLLType.FULL
HLL.parametersByte
- the parameters byte of the serialized HLLpackParametersByte(int, int)
public static int registerCountLog2(byte parametersByte)
HLLType.FULL
HLL.parametersByte
- the parameters byte of the serialized HLLpackParametersByte(int, int)
Copyright © 2017. All rights reserved.