|
Colt 1.2.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cern.colt.PersistentObject cern.colt.list.AbstractCollection cern.colt.list.AbstractList cern.colt.list.AbstractLongList cern.colt.list.DistinctNumberList
Resizable compressed list holding numbers; based on the fact that a number from a large list with few distinct values need not take more than log(distinctValues) bits; implemented with a MinMaxNumberList. First see the package summary and javadoc tree view to get the broad picture.
This class can, for example, be useful when making large lists of numbers persistent. Also useful when very large lists would otherwise consume too much main memory.
You can add, get and set elements quite similar to java.util.ArrayList.
Applicability: Applicable if data is highly skewed and legal values are known in advance. Robust in the presence of "outliers".
Performance: Operations get(), size() and clear() are O(1), i.e. run in constant time. Operations like add() and set() are O(log(distinctValues.length)).
Upon instantiation a contract is signed that defines the distinct values allowed to be hold in this list. It is not legal to store elements other than specified by the contract. Any attempt to violate the contract will throw an IllegalArgumentException.
Although access methods are only defined on long values you can also store all other primitive data types: boolean, byte, short, int, long, float, double and char. You can do this by explicitly representing them as long values. Use casts for discrete data types. Use the methods of java.lang.Float and java.lang.Double for floating point data types: Recall that with those methods you can convert any floating point value to a long value and back without losing any precision:
Example usage:
DistinctNumberList list = ... instantiation goes here double d1 = 1.234; list.add(Double.doubleToLongBits(d1)); double d2 = Double.longBitsToDouble(list.get(0)); if (d1!=d2) System.out.println("This is impossible!"); DistinctNumberList list2 = ... instantiation goes here float f1 = 1.234f; list2.add((long) Float.floatToIntBits(f1)); float f2 = Float.intBitsToFloat((int)list2.get(0)); if (f1!=f2) System.out.println("This is impossible!");
LongArrayList
,
MinMaxNumberList
,
Float
,
Double
,
Serialized FormField Summary |
Fields inherited from class cern.colt.PersistentObject |
serialVersionUID |
Constructor Summary | |
DistinctNumberList(long[] distinctValues,
int initialCapacity)
Constructs an empty list with the specified initial capacity and the specified distinct values allowed to be hold in this list. |
Method Summary | |
void |
add(long element)
Appends the specified element to the end of this list. |
void |
ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory. |
long |
getQuick(int index)
Returns the element at the specified position in the receiver; WARNING: Does not check preconditions. |
void |
removeFromTo(int from,
int to)
Removes from the receiver all elements whose index is between from , inclusive and to , inclusive. |
void |
setQuick(int index,
long element)
Replaces the element at the specified position in the receiver with the specified element; WARNING: Does not check preconditions. |
void |
trimToSize()
Trims the capacity of the receiver to be the receiver's current size. |
Methods inherited from class cern.colt.list.AbstractLongList |
addAllOfFromTo, beforeInsert, beforeInsertAllOfFromTo, binarySearch, binarySearchFromTo, clone, contains, delete, elements, elements, equals, fillFromToWith, forEach, get, indexOf, indexOfFromTo, lastIndexOf, lastIndexOfFromTo, mergeSortFromTo, mergeSortFromTo, partFromTo, quickSortFromTo, quickSortFromTo, removeAll, replaceFromToWithFrom, replaceFromToWithFromTo, replaceFromWith, retainAll, reverse, set, shuffleFromTo, size, times, toList, toString |
Methods inherited from class cern.colt.list.AbstractList |
addAllOf, beforeInsertAllOf, clear, mergeSort, quickSort, remove, setSize, shuffle, sort, sortFromTo |
Methods inherited from class cern.colt.list.AbstractCollection |
isEmpty |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public DistinctNumberList(long[] distinctValues, int initialCapacity)
distinctValues
- an array sorted ascending containing the distinct values allowed to be hold in this list.initialCapacity
- the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.Method Detail |
public void add(long element)
add
in class AbstractLongList
element
- element to be appended to this list.public void ensureCapacity(int minCapacity)
ensureCapacity
in class AbstractLongList
minCapacity
- the desired minimum capacity.public long getQuick(int index)
index
- index of element to return.public void removeFromTo(int from, int to)
from
, inclusive and to
, inclusive. Shifts any succeeding
elements to the left (reduces their index).
This call shortens the list by (to - from + 1) elements.
removeFromTo
in class AbstractLongList
from
- index of first element to be removed.to
- index of last element to be removed.
IndexOutOfBoundsException
- index is out of range (size()>0 && (from<0 || from>to || to>=size())).public void setQuick(int index, long element)
index
- index of element to replace.element
- element to be stored at the specified position.public void trimToSize()
trimToSize
in class AbstractList
|
Colt 1.2.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |