pt.tumba.ngram.compression
Class ByteSet

java.lang.Object
  extended by pt.tumba.ngram.compression.ByteSet

public final class ByteSet
extends java.lang.Object

A set of bytes. Supports add operations, containment queries, and may be cleared.

Author:
Bruno Martins

Field Summary
private  long _bits1
          Representation of bytes -128..-65.
private  long _bits2
          Representation of bytes -64..-1.
private  long _bits3
          Representation of bytes // 0..63.
private  long _bits4
          Representation of bytes 64..127.
(package private) static ByteSet EMPTY_SET
          An empty set.
 
Constructor Summary
ByteSet()
          Construct a byte set.
 
Method Summary
 void add(byte b)
          Add a byte to this set.
 void add(ByteSet that)
          Adds all the members of specified set to this set.
 void add(int i)
          Adds a byte, specified as an integer, to this set.
static int byteToInteger(byte b)
          Returns integer code for the specified byte.
 void clear()
          Remove all of the bytes from this set.
 boolean contains(byte b)
          Returns true if specified byte is a member of this set.
 boolean contains(int i)
          Returns true if byte specified as an integer is a member of this set.
static byte integerToByte(int i)
          Returns byte coded by the specified integer.
 void remove(byte b)
          Removes a byte from this set.
 void remove(ByteSet that)
          Removes all the members of specified set from this set.
 void remove(int i)
          Removes a byte, specified as an integer, from this set.
 void restrict(ByteSet that)
          Removes all the elements of this set that are not in the specified set.
 int size()
          Returns number of elements in this set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_SET

static final ByteSet EMPTY_SET
An empty set. Unsafe, because nothing prevents the addition of elements. So it's kept to the package. The decision to do it this way was to keep ByteSet itself a final class for the sake of efficiency.


_bits1

private long _bits1
Representation of bytes -128..-65. Longs are a real kick in the butt for 1.4 non-server.


_bits2

private long _bits2
Representation of bytes -64..-1.


_bits3

private long _bits3
Representation of bytes // 0..63.


_bits4

private long _bits4
Representation of bytes 64..127.

Constructor Detail

ByteSet

public ByteSet()
Construct a byte set.

Method Detail

clear

public void clear()
Remove all of the bytes from this set.


add

public void add(int i)
Adds a byte, specified as an integer, to this set.

Parameters:
i - Byte to add to this set.

add

public void add(byte b)
Add a byte to this set.

Parameters:
b - Byte to add to this set.

remove

public void remove(int i)
Removes a byte, specified as an integer, from this set.

Parameters:
i - Integer specification of byte to remove from this set.

remove

public void remove(byte b)
Removes a byte from this set.

Parameters:
b - Byte to remove from this set.

add

public void add(ByteSet that)
Adds all the members of specified set to this set. The result is that this set's value is the union of its previous value with the specified set. The argument set is unchanged.

Parameters:
that - Byte set to add to this set.

remove

public void remove(ByteSet that)
Removes all the members of specified set from this set. The result is that this set's value is the complement of its previous value with the specified set. The argument set is unchanged.

Parameters:
that - Byte set to remove from this set.

restrict

public void restrict(ByteSet that)
Removes all the elements of this set that are not in the specified set. The result is that this set's value is the intersection of its previous value with the specified set. The argument set is unchagned.

Parameters:
that - Byte set to restrict this set to.

contains

public boolean contains(int i)
Returns true if byte specified as an integer is a member of this set. Conversion is done by casting.

Parameters:
i - Integer representation of byte to be tested for membership.
Returns:
true if the specified byte is a member of this set.

contains

public boolean contains(byte b)
Returns true if specified byte is a member of this set.

Parameters:
b - Byte to test for membership in this set.
Returns:
true if the specified byte is a member of this set.

size

public int size()
Returns number of elements in this set.

Returns:
Number of elements in this set.

integerToByte

public static byte integerToByte(int i)
Returns byte coded by the specified integer.

Parameters:
i - Integer to conver to a byte.
Returns:
Byte coded by the specified integer.

byteToInteger

public static int byteToInteger(byte b)
Returns integer code for the specified byte.

Parameters:
b - Byte to code as an integer.
Returns:
Integer code for the specified byte.