com.tivoli.twg.libs
Class LongSortSet

java.lang.Object
  extended bycom.tivoli.twg.libs.LongSortSet
All Implemented Interfaces:
java.io.Serializable

public class LongSortSet
extends java.lang.Object
implements java.io.Serializable

Container for a set of object references, each of which has an associated long value. The set is sorted by the associated long values (ascending order). This set is optimized for searches and insertion/deletion operations. The class also supports optimized bulk insertion of values (which should be used instead of large numbers of single inserts). Note: the long values used for sorting do NOT have to be unique, although the objects associated with duplicate values will be ordered arbitrarily relative to each other.

See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
LongSortSet()
          Construtor for creating an initially empty set.
LongSortSet(int init_size)
          Constructor for creating an empty set with a given initial space allocation.
LongSortSet(long[] init_sort_values, int start_sort_index, java.lang.Object[] init_objects, int start_obj_index, int length)
          Constructor for creating a set initialized with a given range within an array of integers.
LongSortSet(LongSortSet init_set)
          Constructor for creating a set initialized by another set
 
Method Summary
 java.lang.Object[] AccessObjects()
          Access internal array containing objects in set (read-only)
 long[] AccessValues()
          Access internal array containing sort values in set (read-only)
 boolean equals(LongSortSet s1)
          Compare the value of the LongSortSet with another LongSortSet
 int Find(long val)
          Return index of any value/object pair with given value, or -1 if not in set
 int Find(long val, java.lang.Object obj)
          Return index of given value/object pair in set, or -1 if not in set Note: match requires that both values are equal
 java.lang.Object[] FindAll(long val)
          Return list of all objects which match given value in set
 java.lang.Object GetObject(int n)
          Return nth object element of set
 java.lang.Object[] GetObjects()
          Return array containing copy of all objects in set.
 long GetValue(int n)
          Return nth value element of set
 long[] GetValues()
          Return array containing copy of all sort values in set.
 void InsertArray(long[] val, int valstart, java.lang.Object[] obj, int objstart, int length)
          Insert an array of values into set.
 void InsertSet(LongSortSet insset)
          Insert LongSortSet into set.
 void InsertValue(long val, java.lang.Object obj)
          Insert a single value and object into the set.
 int Length()
          Return length of set
 void MergeArray(long[] val, int valstart, java.lang.Object[] obj, int objstart, int len)
          Merge sorted value/object pair arrays into our values
 boolean RemoveArray(long[] val, int valstart, java.lang.Object[] obj, int objstart, int length)
          Remove an array of value/object pairs from set.
 void RemoveSet(LongSortSet remset)
          Remove LongSortSet into set.
 void RemoveSortedArray(long[] val, int valstart, java.lang.Object[] obj, int objstart, int len)
          Remove sorted array of value/object pairs from current set
 boolean RemoveValue(long val)
          Remove all value/object pair from set with given value.
 boolean RemoveValue(long val, java.lang.Object obj)
          Remove value/object pair from set, if present.
 void reset()
          Empty the contents of the set.
 void setEqual(LongSortSet s1)
          Set set contents equal to given set
static void Sort(long[] valset, int valstart, java.lang.Object[] objset, int objstart, int length)
          Sort a given array of sort values and corresponding objects, using quicksort.
 void sortValues()
          Sort values, if needed.
static boolean TestIfSorted(long[] valset, int start, int length)
          Test if a range in an array is already sorted
 java.lang.String toString()
          String representation method (for debug)
 void unsortedInsertValue(long val, java.lang.Object obj)
          Unsorted insert : quick way to add value without causing incremental sort.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

LongSortSet

public LongSortSet()
Construtor for creating an initially empty set.


LongSortSet

public LongSortSet(int init_size)
Constructor for creating an empty set with a given initial space allocation.

Parameters:
init_size - - initial set space allocation (array size)

LongSortSet

public LongSortSet(long[] init_sort_values,
                   int start_sort_index,
                   java.lang.Object[] init_objects,
                   int start_obj_index,
                   int length)
Constructor for creating a set initialized with a given range within an array of integers.

Parameters:
init_sort_values - - array containing initial sort values
start_sort_index - - index of start of sort values
init_objects - - array containing objects to be sorted
start_obj_index - - index of start of object to be sorted
length - - number of values

LongSortSet

public LongSortSet(LongSortSet init_set)
Constructor for creating a set initialized by another set

Parameters:
init_set - - set to use for initialization
Method Detail

InsertValue

public void InsertValue(long val,
                        java.lang.Object obj)
Insert a single value and object into the set. Use InsertArray() for inserting multiple values.

Parameters:
val - - value to be inserted
obj - - object associated with value

unsortedInsertValue

public void unsortedInsertValue(long val,
                                java.lang.Object obj)
Unsorted insert : quick way to add value without causing incremental sort. No other method calls should be made (other than additional unsortedInsertValue() calls) until sortValues() is called.

Parameters:
val - - value to be inserted
obj - - object associated with value

sortValues

public void sortValues()
Sort values, if needed. Only necessary if values inserted using unsortedInsertValue().


InsertArray

public void InsertArray(long[] val,
                        int valstart,
                        java.lang.Object[] obj,
                        int objstart,
                        int length)
Insert an array of values into set.

Parameters:
val - - array of values
valstart - - index of start of range of values
obj - - array of objects
objstart - - index of start of range of objects
length - - length of range of values to be inserted

InsertSet

public void InsertSet(LongSortSet insset)
Insert LongSortSet into set.

Parameters:
insset - - LongSortSet to be inserted

RemoveValue

public boolean RemoveValue(long val,
                           java.lang.Object obj)
Remove value/object pair from set, if present. Use RemoveArray() for removing multiple values/object pairs. Both value and object reference provided must match the values previously inserted into the set.

Parameters:
val - - sort value of record to be removed
obj - - object reference of object to be removed
Returns:
true if found and removed, false if not found

RemoveValue

public boolean RemoveValue(long val)
Remove all value/object pair from set with given value.

Parameters:
val - - sort value of record to be removed
Returns:
true if found and removed, false if not found

RemoveArray

public boolean RemoveArray(long[] val,
                           int valstart,
                           java.lang.Object[] obj,
                           int objstart,
                           int length)
Remove an array of value/object pairs from set.

Parameters:
val - - array of values
valstart - - index of start of range of values
obj - - array of objects
objstart - - index of start of range of objects
length - - length of range of values and objects to be removed
Returns:
true any value/object pairs removed, false if none removed

RemoveSet

public void RemoveSet(LongSortSet remset)
Remove LongSortSet into set.

Parameters:
remset - - LongSortSet to be removed

Find

public final int Find(long val,
                      java.lang.Object obj)
Return index of given value/object pair in set, or -1 if not in set Note: match requires that both values are equal

Parameters:
val - - value to be found in set
obj - - object reference to be found
Returns:
index of matching value, or -1 if not found

Find

public final int Find(long val)
Return index of any value/object pair with given value, or -1 if not in set

Parameters:
val - - value to be found in set
Returns:
index of matching value, or -1 if not found

FindAll

public final java.lang.Object[] FindAll(long val)
Return list of all objects which match given value in set

Parameters:
val - - value to be found in set
Returns:
array of object references with matching values

Length

public final int Length()
Return length of set

Returns:
number of elements in set

GetValue

public final long GetValue(int n)
                    throws java.lang.ArrayIndexOutOfBoundsException
Return nth value element of set

Parameters:
n - - index (base 0) of element to be returned
Returns:
sort value at given index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if invalid index

GetObject

public final java.lang.Object GetObject(int n)
                                 throws java.lang.ArrayIndexOutOfBoundsException
Return nth object element of set

Parameters:
n - - index (base 0) of element to be returned
Returns:
object reference at given index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if invalid index

GetValues

public final long[] GetValues()
Return array containing copy of all sort values in set.

Returns:
allocated array containing all sort values in set

GetObjects

public final java.lang.Object[] GetObjects()
Return array containing copy of all objects in set.

Returns:
allocated array containing all objects in set

AccessValues

public final long[] AccessValues()
Access internal array containing sort values in set (read-only)

Returns:
reference to internal array for set (may be longer than actual amount of data : use Length() to find actual length

AccessObjects

public final java.lang.Object[] AccessObjects()
Access internal array containing objects in set (read-only)

Returns:
reference to internal array for set (may be longer than actual amount of data : use Length() to find actual length

Sort

public static final void Sort(long[] valset,
                              int valstart,
                              java.lang.Object[] objset,
                              int objstart,
                              int length)
Sort a given array of sort values and corresponding objects, using quicksort. The object array will be reordered such that the values in both the sort value array and object array maintain their correlation.

Parameters:
valset - - Array to be sorted
valstart - - index of start of data to be sorted
objset - - Array of objects associated with valset values
objstart - - index of start of objects in objset
length - - length of data to be sorted

TestIfSorted

public static final boolean TestIfSorted(long[] valset,
                                         int start,
                                         int length)
Test if a range in an array is already sorted

Parameters:
valset - - array containing values
start - - start of range to test
length - - length of range to test
Returns:
true if already sorted, false if not

MergeArray

public void MergeArray(long[] val,
                       int valstart,
                       java.lang.Object[] obj,
                       int objstart,
                       int len)
Merge sorted value/object pair arrays into our values

Parameters:
val - - array of sort values
valstart - - start index of sort values in array
obj - - array of objects
objstart - - start index of objects in array
len - - length of range in both arrays

RemoveSortedArray

public void RemoveSortedArray(long[] val,
                              int valstart,
                              java.lang.Object[] obj,
                              int objstart,
                              int len)
Remove sorted array of value/object pairs from current set

Parameters:
val - - array of values to be removed
valstart - - index of start of range of values
obj - - array of objects to be removed
objstart - - index of start of range of objects
len - - length of range in both arrays

equals

public boolean equals(LongSortSet s1)
Compare the value of the LongSortSet with another LongSortSet

Parameters:
s1 - - set to be compared with
Returns:
true if sets are equal, false if not

reset

public void reset()
Empty the contents of the set.


setEqual

public void setEqual(LongSortSet s1)
Set set contents equal to given set

Parameters:
s1 - - set to be copied

toString

public java.lang.String toString()
String representation method (for debug)

Returns:
string representation