org.basex.util
Class Num

java.lang.Object
  extended by org.basex.util.Num

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:

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newNum

public static byte[] newNum(int value)
Creates a new number array, in which the first four bytes contain the number of occupied bytes.

Parameters:
value - initial value to be compressed and stored
Returns:
new number array

num

public static byte[] num(int value)
Creates a compressed representation of the specified value.

Parameters:
value - value to be compressed
Returns:
new number array

add

public static byte[] add(byte[] array,
                         int value)
Compresses and adds a value to the specified array and returns the resulting array.

Parameters:
array - input array
value - value to be added
Returns:
resulting array (may be the same as input array)

get

public static int get(byte[] array,
                      int pos)
Decompresses and returns a value from the specified byte array.

Parameters:
array - array
pos - position where the value is found
Returns:
decompressed value

set

public static void set(byte[] array,
                       int value,
                       int pos)
Compresses and stores an integer value to the specified byte array.

Parameters:
array - array
value - value to be stored
pos - position where the value is to be stored

size

public static int size(byte[] array)
Returns the length value of the specified array, stored in the first four bytes.

Parameters:
array - input array
Returns:
array length

size

public static void size(byte[] array,
                        int length)
Stores the specified length value in the first bytes of the specified array.

Parameters:
array - input array
length - length to be stored

length

public static int length(byte[] array,
                         int pos)
Returns the compressed length of the value at the specified position.

Parameters:
array - array
pos - position where the value is found
Returns:
value length

length

public static int length(int v)
Returns the compressed length of the specified value.

Parameters:
v - integer value
Returns:
value length