Encodes numbers (longs and doubles) as bytes whose order matches the numeric order.
Implementation conforms to the UTF Style Encoding section of "Number Index Entry Encoding".
| int | MAX_ENCODED_BYTES | The encoder assumes the input is either a long or a double and assumes the maximum length based on the largest values for each type. |
| static int |
encodeDouble(boolean descending, double value, byte[] buffer, int offset)
Writes bytes encoding the double to the buffer at the offset, in the order specified by
descending, and returns the number of bytes written.
|
| static int |
encodeLong(boolean descending, long value, byte[] buffer, int offset)
Writes bytes encoding the long to the buffer at the offset, in the order specified by
descending, and returns the number of bytes written.
|
The encoder assumes the input is either a long or a double and assumes the maximum length based on the largest values for each type.
11 bytes are required to render the largest longs. Long.MAX_VALUE encodes as follows:
10 bytes are required to render the largest doubles. Double.MAX_VALUE encodes as follows:
Note that while subnormal values require larger exponents to encode, their reduced precision makes them no larger to encode than Double.MAX_VALUE.
Writes bytes encoding the double to the buffer at the offset, in the order specified by descending, and returns the number of bytes written.
Warning! When descending is true, NaN is encoded as (still) smaller than all other numbers. See TODO in this file.
| descending | when true, produce an encoding that orders numbers in descending order |
|---|---|
| value | the double to encode |
| buffer | buffer for bytes to write the encoded bytes |
| offset | index into buffer of first byte to write |
Writes bytes encoding the long to the buffer at the offset, in the order specified by descending, and returns the number of bytes written.
| descending | when true, produce an encoding that orders numbers in descending order |
|---|---|
| value | the long to encode |
| buffer | buffer for bytes to write the encoded bytes |
| offset | index into buffer of first byte to write |