public final class Num
extends java.lang.Object
This class provides operations to compress and decompress 4-byte integer values in byte arrays in order to save memory.
The first two bits of a Num array indicate the range of the
compressed number:
00: the number (0x00-0x3F) is encoded in the remaining 6 bits of
the current byte01: the number (0x40-0x3FFF) is encoded in 14 bits of the current
and the following byte10: the number (0x4000-0x3FFFFFFF) is encoded in 30 bits of the
current and the following three bytes11: the number (0x40000000-0xFFFFFFFF) is encoded in 32 bits of
the following four bytes| Modifier and Type | Method and Description |
|---|---|
static byte[] |
add(byte[] array,
int value)
Compresses and adds a value to the specified array and
returns the resulting array.
|
static int |
get(byte[] array,
int pos)
Decompresses and returns a value from the specified byte array.
|
static int |
length(byte[] array,
int pos)
Returns the compressed length of the value at the specified position.
|
static int |
length(int v)
Returns the compressed length of the specified value.
|
static byte[] |
newNum(int value)
Creates a new number array, in which the first four bytes contain
the number of occupied bytes.
|
static byte[] |
num(int value)
Creates a compressed representation of the specified value.
|
static void |
set(byte[] array,
int value,
int pos)
Compresses and stores an integer value to the specified byte array.
|
static int |
size(byte[] array)
Returns the length value of the specified array, stored in the first
four bytes.
|
static void |
size(byte[] array,
int length)
Stores the specified length value in the first bytes of the
specified array.
|
public static byte[] newNum(int value)
value - initial value to be compressed and storedpublic static byte[] num(int value)
value - value to be compressedpublic static byte[] add(byte[] array,
int value)
array - input arrayvalue - value to be addedpublic static int get(byte[] array,
int pos)
array - arraypos - position where the value is foundpublic static void set(byte[] array,
int value,
int pos)
array - arrayvalue - value to be storedpos - position where the value is to be storedpublic static int size(byte[] array)
array - input arraypublic static void size(byte[] array,
int length)
array - input arraylength - length to be storedpublic static int length(byte[] array,
int pos)
array - arraypos - position where the value is foundpublic static int length(int v)
v - integer value