public class DistinctNumberListextends AbstractLongListResizable 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:
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!");