Examples of ISchemaVersion


Examples of net.agkn.hll.serialization.ISchemaVersion

     * Tests {@link LongSetSlab#toBytes(int, ISchemaVersion)} and
     * {@link LongSetSlab#fromBytes(int, byte[], ISchemaVersion)}.
     */
    @Test
    public void toFromBytesTest() {
        final ISchemaVersion schemaVersion = SerializationUtil.DEFAULT_SCHEMA_VERSION;
        final HLLType type = HLLType.EXPLICIT;
        final int padding = schemaVersion.paddingBytes(type);
        final int bytesPerWord = 8;

        {// Should work on an empty set
            final HLL hll = newHLL(128/*arbitrary*/);

 
View Full Code Here

Examples of net.agkn.hll.serialization.ISchemaVersion

        final int log2m = 11/*arbitrary*/;
        final int regwidth = 5/*arbitrary*/;
        final int sparseThreshold = 256/*arbitrary*/;
        final int shortWordLength = 16/*log2m + regwidth = 11 + 5*/;

        final ISchemaVersion schemaVersion = SerializationUtil.DEFAULT_SCHEMA_VERSION;
        final HLLType type = HLLType.SPARSE;
        final int padding = schemaVersion.paddingBytes(type);

        {// Should work on an empty element
            final HLL hll = new HLL(log2m, regwidth, 128/*explicitThreshold, arbitrary, unused*/, sparseThreshold, HLLType.SPARSE);
            final byte[] bytes = hll.toBytes(schemaVersion);

View Full Code Here

Examples of net.agkn.hll.serialization.ISchemaVersion

    @Test
    public void toFromBytesTest() {
        final int log2m = 11/*arbitrary*/;
        final int regwidth = 5;

        final ISchemaVersion schemaVersion = SerializationUtil.DEFAULT_SCHEMA_VERSION;
        final HLLType type = HLLType.FULL;
        final int padding = schemaVersion.paddingBytes(type);
        final int dataByteCount = ProbabilisticTestUtil.getRequiredBytes(regwidth, (1 << log2m)/*aka 2^log2m = m*/);
        final int expectedByteCount = padding + dataByteCount;

        {// Should work on an empty element
            final HLL hll = new HLL(log2m, regwidth, 128/*explicitThreshold, arbitrary, unused*/, 256/*sparseThreshold, arbitrary, unused*/, HLLType.FULL);
View Full Code Here

Examples of net.agkn.hll.serialization.ISchemaVersion

     * @return the deserialized HLL. This will never be <code>null</code>.
     *
     * @see #toBytes(ISchemaVersion)
     */
    public static HLL fromBytes(final byte[] bytes) {
        final ISchemaVersion schemaVersion = SerializationUtil.getSchemaVersion(bytes);
        final IHLLMetadata metadata = schemaVersion.readMetadata(bytes);

        final HLLType type = metadata.HLLType();
        final int regwidth = metadata.registerWidth();
        final int log2m = metadata.registerCountLog2();
        final boolean sparseon = metadata.sparseEnabled();

        final int expthresh;
        if(metadata.explicitAuto()) {
            expthresh = -1;
        } else if(metadata.explicitOff()) {
            expthresh = 0;
        } else {
            // NOTE: take into account that the postgres-compatible constructor
            //       subtracts one before taking a power of two.
            expthresh = metadata.log2ExplicitCutoff() + 1;
        }

        final HLL hll = new HLL(log2m, regwidth, expthresh, sparseon, type);

        // Short-circuit on empty, which needs no other deserialization.
        if(HLLType.EMPTY.equals(type)) {
            return hll;
        }

        final int wordLength;
        switch(type) {
            case EXPLICIT:
                wordLength = Long.SIZE;
                break;
            case SPARSE:
                wordLength = hll.shortWordLength;
                break;
            case FULL:
                wordLength = hll.regwidth;
                break;
            default:
                throw new RuntimeException("Unsupported HLL type " + type);
        }

        final IWordDeserializer deserializer =
                schemaVersion.getDeserializer(type, wordLength, bytes);
        switch(type) {
            case EXPLICIT:
                // NOTE:  This should not exceed expthresh and this will always
                //        be exactly the number of words that were encoded,
                //        because the word length is at least a byte wide.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.