org.basex.util
Class Num

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

public final class Num
extends Object

This class provides operations to compress and decompress integer values in byte arrays to save memory.

Author:
Workgroup DBIS, University of Konstanz 2005-10, ISC License, Christian Gruen

Method Summary
static byte[] add(byte[] array, int val)
          Compresses and writes an integer value to the specified array and returns the array.
static int len(byte[] array, int val)
          Returns integer length.
static int len(int v)
          Returns the compressed length of the specified value.
static byte[] newNum(int val)
          Creates a new number array.
static byte[] num(int val)
          Creates a new number array.
static int read(byte[] array, int pos)
          Reads and decompresses an integer value from the specified byte array.
static int size(byte[] array)
          Returns the length of the specified array, stored in the first four bytes.
static void size(byte[] array, int len)
          Writes the specified length in the first bytes of the specified array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newNum

public static byte[] newNum(int val)
Creates a new number array.

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

num

public static byte[] num(int val)
Creates a new number array.

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

add

public static byte[] add(byte[] array,
                         int val)
Compresses and writes an integer value to the specified array and returns the array.

Parameters:
array - array
val - value to be written
Returns:
new array

read

public static int read(byte[] array,
                       int pos)
Reads and decompresses an integer value from the specified byte array.

Parameters:
array - array
pos - position to parse
Returns:
decompressed value

size

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

Parameters:
array - array to be evaluated
Returns:
array length

len

public static int len(byte[] array,
                      int val)
Returns integer length.

Parameters:
array - array
val - integer value
Returns:
value length

size

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

Parameters:
array - array
len - new length

len

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

Parameters:
v - integer value
Returns:
value length