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 integer values in byte arrays to save memory.

Author:
Workgroup DBIS, University of Konstanz 2005-08, 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 byte[] create(int[] vals)
          Creates and returns a compressed array from the specified integer array.
static byte[] create(int[] vals, int vs)
          Creates and returns a compressed array from the specified integer array.
static int len(byte[] array, int val)
          Returns integer length.
static byte[] newNum(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 byte[] simpleNum(int val)
          Creates a new number array.
static int size(byte[] array)
          Returns the length of the specified array, stored in the first four bytes.
 
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

simpleNum

public static byte[] simpleNum(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

create

public static byte[] create(int[] vals)
Creates and returns a compressed array from the specified integer array. The first value in the specified array denotes the number of entries.

Parameters:
vals - values to be written
Returns:
new array

create

public static byte[] create(int[] vals,
                            int vs)
Creates and returns a compressed array from the specified integer array. The number of entries specifies vs. NO SIZEINFO IS WRITTEN!!

Parameters:
vals - values to be written
vs - number of entries in vals
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