baobab.util
Class CompressibleSortedSet<T>

java.lang.Object
  extended by baobab.util.CompressibleSortedSet<T>
Type Parameters:
T - the type of objects that this object may store. When the type <T> implements the interface baobab.util.Joinable<T>, if the CompressibleSortedSet already contains an element that is equal to an added element, they are joined. In the same way, when an element is removed, it is in fact splitted from an equivalent object which is already present in the CompressibleSortedSet, and if the resulting object is empty, then it is removed.
Direct Known Subclasses:
FreezableCompressibleSortedSet

public class CompressibleSortedSet<T>
extends java.lang.Object

The CompressibleSortedSet class represents a sorted set of codable objects.

In general, insertions and removals are not processed one by one, but accumulated and then processed in batch mode, from time to time or when the set is resolved.

The intern organization of this set allows automatic partial compression of its data. To be able to use this class it is necessary to have an element comparator (java.util.Comparator<T>) and an element coder (baobab.util.Coder<T>).

Author:
Marilia Dias Vieira Braga

Field Summary
static double BLOCK_SPLIT_BALANCE
           
static int MAXIMUM_NUMBER_OF_ELEMENTS_BY_COMPRESSIBLE_BLOCK
          The default value for the maximum number of elements by compressible block
static int MAXIMUM_NUMBER_OF_UNCOMPRESSED_BLOCKS_FOR_AUTOMATIC_COMPRESSION
          The default value for the maximum number uncompressed blocks
static int MAXIMUM_PENDING_INSERTION_DELETION_LIST_FOR_COMPRESSED_BLOCK
          The default value for the maximum number of uncompressed elements in the pending (insertion / deletion) lists of each compressed block
 
Constructor Summary
CompressibleSortedSet(Coder<T> coder)
          CompressibleSortedSet constructor
CompressibleSortedSet(Coder<T> coder, int x, int y, int z)
          CompressibleSortedSet constructor
CompressibleSortedSet(java.util.Comparator<T> comparator, Coder<T> coder)
          CompressibleSortedSet constructor
CompressibleSortedSet(java.util.Comparator<T> comparator, Coder<T> coder, int x, int y, int z, double balance)
          CompressibleSortedSet constructor
 
Method Summary
 int addElement(T element)
          Add an element to this set (in general, additions are not processed one by one, but accumulated and then processed in batch mode, from time to time or when the set is resolved).
 void clear()
          Removes all elements in this set
 void clear(boolean bk)
          Removes all elements in this set
 java.util.Iterator<T> descendingIterator()
          Gets a descending iterator of this set.
 T firstElement()
          Gets the first element in this set
 int flushLastDecompressionResult()
          Gets the number of elements that have been added/removed to this set after the last internal (partial) decompression and batch processing.
 boolean isEmpty()
          Tests whether this set is empty
 boolean isResolved()
          Tests whether this set is resolved (does not have pending insertions/removals).
 java.util.Iterator<T> iterator()
          Gets a ascending iterator of this set.
 T lastElement()
          Gets the last element in this set
 int notResolvedSize()
          Gets the not resolved size (number of elements) of this set.
 int removeElement(T element)
          Remove an element from this set (in general, removals are not processed one by one, but accumulated and then processed in batch mode, from time to time or when the set is resolved).
 int resolve()
          Resolves all pending insertions/removals of this set (WARNING: this method can cause a high overhead because usually it forces several internal decompressions and recompressions).
 int resolvedSize()
          Gets the resolved size (number of elements) of this set.
 T searchElement(T element)
          Search an element in this set (WARNING: frequent use of this method can cause a high overhead because usually it forces an internal partial decompression)
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAXIMUM_NUMBER_OF_ELEMENTS_BY_COMPRESSIBLE_BLOCK

public static final int MAXIMUM_NUMBER_OF_ELEMENTS_BY_COMPRESSIBLE_BLOCK
The default value for the maximum number of elements by compressible block

See Also:
Constant Field Values

MAXIMUM_NUMBER_OF_UNCOMPRESSED_BLOCKS_FOR_AUTOMATIC_COMPRESSION

public static final int MAXIMUM_NUMBER_OF_UNCOMPRESSED_BLOCKS_FOR_AUTOMATIC_COMPRESSION
The default value for the maximum number uncompressed blocks

See Also:
Constant Field Values

MAXIMUM_PENDING_INSERTION_DELETION_LIST_FOR_COMPRESSED_BLOCK

public static final int MAXIMUM_PENDING_INSERTION_DELETION_LIST_FOR_COMPRESSED_BLOCK
The default value for the maximum number of uncompressed elements in the pending (insertion / deletion) lists of each compressed block

See Also:
Constant Field Values

BLOCK_SPLIT_BALANCE

public static final double BLOCK_SPLIT_BALANCE
See Also:
Constant Field Values
Constructor Detail

CompressibleSortedSet

public CompressibleSortedSet(java.util.Comparator<T> comparator,
                             Coder<T> coder,
                             int x,
                             int y,
                             int z,
                             double balance)
CompressibleSortedSet constructor

Parameters:
comparator - a comparator of Element
coder - a coder of Element
x - the maximum number of elements by compressible block
y - the maximum number of uncompressed blocks to start automatic compression
z - the maximum number of uncompressed elements in the pending (insertion ou deletion) lists for each compressed block

CompressibleSortedSet

public CompressibleSortedSet(Coder<T> coder,
                             int x,
                             int y,
                             int z)
CompressibleSortedSet constructor

Parameters:
coder - a coder of Element
x - the maximum number of elements by compressible block
y - the maximum number of uncompressed blocks to start automatic compression
z - the maximum number of uncompressed elements in the pending (insertion ou deletion) lists for each compressed block

CompressibleSortedSet

public CompressibleSortedSet(java.util.Comparator<T> comparator,
                             Coder<T> coder)
CompressibleSortedSet constructor

Parameters:
comparator - a comparator of Element
coder - a coder of Element

CompressibleSortedSet

public CompressibleSortedSet(Coder<T> coder)
CompressibleSortedSet constructor

Parameters:
coder - a coder of Element
Method Detail

isResolved

public boolean isResolved()
Tests whether this set is resolved (does not have pending insertions/removals).

Returns:
true/false

flushLastDecompressionResult

public int flushLastDecompressionResult()
Gets the number of elements that have been added/removed to this set after the last internal (partial) decompression and batch processing. A procedure of internal (partial) decompression and batch processing is done automatically when searching or after a certain number of additions/removals.

Returns:
the number of elements that have been added/removed after the last internal (partial) decompression

isEmpty

public boolean isEmpty()
Tests whether this set is empty

Returns:
true/false

notResolvedSize

public int notResolvedSize()
Gets the not resolved size (number of elements) of this set. The set is not resolved when it has pending insertions or removals.

Returns:
the size (number of elements) of this set

resolvedSize

public int resolvedSize()
Gets the resolved size (number of elements) of this set. The set is automatically resolved when it has pending insertions or removals (WARNING: this method can cause a high overhead because usually it forces several internal decompressions and recompressions).

Returns:
the size (number of elements) of this set

resolve

public int resolve()
Resolves all pending insertions/removals of this set (WARNING: this method can cause a high overhead because usually it forces several internal decompressions and recompressions).

Returns:
the number of added/removed elements

iterator

public java.util.Iterator<T> iterator()
Gets a ascending iterator of this set. Iterating the set resolves all pending insertions and removals.

Returns:
a iterator of this set in ascending order

descendingIterator

public java.util.Iterator<T> descendingIterator()
Gets a descending iterator of this set. Iterating the set resolves all pending insertions and removals.

Returns:
a iterator of this set in descending order

addElement

public int addElement(T element)
Add an element to this set (in general, additions are not processed one by one, but accumulated and then processed in batch mode, from time to time or when the set is resolved).

When this addition is processed, if element is Joinable, and an object equivalent to element is already present in this set, element is joined to the object.

Parameters:
element - the element to be added
Returns:
the result of adding (zero can mean that the addition was put in the pending list; if a decompression was forced and a batch of insertions/removals is processed, result can be more than one, or negative)

removeElement

public int removeElement(T element)
Remove an element from this set (in general, removals are not processed one by one, but accumulated and then processed in batch mode, from time to time or when the set is resolved).

When this removal is processed, if element is Joinable, and an object equivalent to element is present in this set, element is splitted from this object; if the resulting object is empty, it is removed from the set.

Parameters:
element - the element to be removed
Returns:
the result of the removal (zero can mean that the removal was just put in the pending list; if a decompression was forced and a batch of insertions/removals is processed, result can be less than -1, or positive)

firstElement

public T firstElement()
Gets the first element in this set

Returns:
the first element in this set

lastElement

public T lastElement()
Gets the last element in this set

Returns:
the last element in this set

searchElement

public T searchElement(T element)
Search an element in this set (WARNING: frequent use of this method can cause a high overhead because usually it forces an internal partial decompression)

Parameters:
element - the element to be searched
Returns:
the element in this set which is equal to the searched element (or null, if it was not found)

clear

public void clear()
Removes all elements in this set


clear

public void clear(boolean bk)
Removes all elements in this set


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object