DistinctNumberList
cern.colt.list

Class DistinctNumberList

  • All Implemented Interfaces:
    Serializable, Cloneable


    public class DistinctNumberListextends AbstractLongList
    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!"); 
    See Also:
    LongArrayList, MinMaxNumberList, Float, Double, Serialized Form
    • Constructor Detail

      • DistinctNumberList

        public 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.
        Parameters:
        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

      • add

        public void add(long element)
        Appends the specified element to the end of this list.
        Overrides:
        add in class AbstractLongList
        Parameters:
        element - element to be appended to this list.
      • ensureCapacity

        public void ensureCapacity(int minCapacity)
        Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver.
        Specified by:
        ensureCapacity in class AbstractLongList
        Parameters:
        minCapacity - the desired minimum capacity.
      • getQuick

        public long getQuick(int index)
        Returns the element at the specified position in the receiver; WARNING: Does not check preconditions. Provided with invalid parameters this method may return invalid elements without throwing any exception! You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): index >= 0 && index < size().
        Parameters:
        index - index of element to return.
      • removeFromTo

        public void removeFromTo(int from,                int to)
        Removes from the receiver all elements whose index is between 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.
        Overrides:
        removeFromTo in class AbstractLongList
        Parameters:
        from - index of first element to be removed.
        to - index of last element to be removed.
        Throws:
        IndexOutOfBoundsException - index is out of range (size()>0 && (from<0 || from>to || to>=size())).
      • setQuick

        public 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. Provided with invalid parameters this method may access invalid indexes without throwing any exception! You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): index >= 0 && index < size().
        Parameters:
        index - index of element to replace.
        element - element to be stored at the specified position.
      • trimToSize

        public void trimToSize()
        Trims the capacity of the receiver to be the receiver's current size. An application can use this operation to minimize the storage of the receiver.
        Overrides:
        trimToSize in class AbstractList

SCaVis 2.2 © jWork.ORG