Example usage for org.apache.lucene.util.packed PackedInts getEncoder

List of usage examples for org.apache.lucene.util.packed PackedInts getEncoder

Introduction

In this page you can find the example usage for org.apache.lucene.util.packed PackedInts getEncoder.

Prototype

public static Encoder getEncoder(Format format, int version, int bitsPerValue) 

Source Link

Document

Get an Encoder .

Usage

From source file:com.lucure.core.codec.ForUtil.java

License:Apache License

/**
 * Create a new {@link ForUtil} instance and save state into <code>out</code>.
 *//*w  w  w  .  j a v a  2s .c o m*/
ForUtil(float acceptableOverheadRatio, DataOutput out) throws IOException {
    out.writeVInt(PackedInts.VERSION_CURRENT);
    encodedSizes = new int[33];
    encoders = new PackedInts.Encoder[33];
    decoders = new PackedInts.Decoder[33];
    iterations = new int[33];

    for (int bpv = 1; bpv <= 32; ++bpv) {
        final FormatAndBits formatAndBits = PackedInts.fastestFormatAndBits(BLOCK_SIZE, bpv,
                acceptableOverheadRatio);
        assert formatAndBits.format.isSupported(formatAndBits.bitsPerValue);
        assert formatAndBits.bitsPerValue <= 32;
        encodedSizes[bpv] = encodedSize(formatAndBits.format, PackedInts.VERSION_CURRENT,
                formatAndBits.bitsPerValue);
        encoders[bpv] = PackedInts.getEncoder(formatAndBits.format, PackedInts.VERSION_CURRENT,
                formatAndBits.bitsPerValue);
        decoders[bpv] = PackedInts.getDecoder(formatAndBits.format, PackedInts.VERSION_CURRENT,
                formatAndBits.bitsPerValue);
        iterations[bpv] = computeIterations(decoders[bpv]);

        out.writeVInt(formatAndBits.format.getId() << 5 | (formatAndBits.bitsPerValue - 1));
    }
}

From source file:com.lucure.core.codec.ForUtil.java

License:Apache License

/**
 * Restore a {@link ForUtil} from a {@link DataInput}.
 *//*from   w  w  w .ja  va 2 s.com*/
ForUtil(DataInput in) throws IOException {
    int packedIntsVersion = in.readVInt();
    PackedInts.checkVersion(packedIntsVersion);
    encodedSizes = new int[33];
    encoders = new PackedInts.Encoder[33];
    decoders = new PackedInts.Decoder[33];
    iterations = new int[33];

    for (int bpv = 1; bpv <= 32; ++bpv) {
        final int code = in.readVInt();
        final int formatId = code >>> 5;
        final int bitsPerValue = (code & 31) + 1;

        final PackedInts.Format format = PackedInts.Format.byId(formatId);
        assert format.isSupported(bitsPerValue);
        encodedSizes[bpv] = encodedSize(format, packedIntsVersion, bitsPerValue);
        encoders[bpv] = PackedInts.getEncoder(format, packedIntsVersion, bitsPerValue);
        decoders[bpv] = PackedInts.getDecoder(format, packedIntsVersion, bitsPerValue);
        iterations[bpv] = computeIterations(decoders[bpv]);
    }
}