Search in sources :

Example 1 with Long2ObjectRBTreeMap

use of it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap in project presto by prestodb.

the class KHyperLogLog method newInstance.

public static KHyperLogLog newInstance(Slice serialized) {
    requireNonNull(serialized, "serialized is null");
    SliceInput input = serialized.getInput();
    checkArgument(input.readByte() == VERSION_BYTE, "Unexpected version");
    Long2ObjectRBTreeMap<HyperLogLog> minhash = new Long2ObjectRBTreeMap<>();
    int maxSize = input.readInt();
    int hllBuckets = input.readInt();
    int minhashSize = input.readInt();
    int totalHllSize = input.readInt();
    int[] hllSizes = new int[minhashSize];
    long[] keys = new long[minhashSize];
    input.readBytes(wrappedIntArray(hllSizes));
    input.readBytes(wrappedLongArray(keys));
    Slice allSerializedHlls = input.readSlice(totalHllSize);
    int hllLength;
    int index = 0;
    for (int i = 0; i < minhashSize; i++) {
        Slice serializedHll;
        hllLength = hllSizes[i];
        serializedHll = allSerializedHlls.slice(index, hllLength);
        index += hllLength;
        minhash.put(keys[i], HyperLogLog.newInstance(serializedHll));
    }
    return new KHyperLogLog(maxSize, hllBuckets, minhash);
}
Also used : Long2ObjectRBTreeMap(it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap) Slice(io.airlift.slice.Slice) SliceInput(io.airlift.slice.SliceInput) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Aggregations

HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)1 Slice (io.airlift.slice.Slice)1 SliceInput (io.airlift.slice.SliceInput)1 Long2ObjectRBTreeMap (it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap)1