Example usage for org.apache.lucene.store DataOutput writeVInt

List of usage examples for org.apache.lucene.store DataOutput writeVInt

Introduction

In this page you can find the example usage for org.apache.lucene.store DataOutput writeVInt.

Prototype

public final void writeVInt(int i) throws IOException 

Source Link

Document

Writes an int in a variable-length format.

Usage

From source file:com.browseengine.bobo.geosearch.impl.MappedFieldNameFilterConverter.java

License:Apache License

@Override
public void writeToOutput(DataOutput output) throws IOException {
    output.writeVInt(FIELD_FILTER_VERSION);

    if (bitmasks != null) {
        output.writeVInt(bitmasks.size());
        for (Map.Entry<String, Byte> filterEntry : bitmasks.entrySet()) {
            output.writeString(filterEntry.getKey());
            output.writeByte(filterEntry.getValue());
        }// www  . ja v a2s  . co  m
    } else {
        output.writeVInt(0);
    }
}

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

License:Apache License

private static void saveInts(int[] values, int length, DataOutput out) throws IOException {
    assert length > 0;
    if (length == 1) {
        out.writeVInt(values[0]);
    } else {/* w  ww. jav a 2  s. com*/
        boolean allEqual = true;
        for (int i = 1; i < length; ++i) {
            if (values[i] != values[0]) {
                allEqual = false;
                break;
            }
        }
        if (allEqual) {
            out.writeVInt(0);
            out.writeVInt(values[0]);
        } else {
            long max = 0;
            for (int i = 0; i < length; ++i) {
                max |= values[i];
            }
            final int bitsRequired = PackedInts.bitsRequired(max);
            out.writeVInt(bitsRequired);
            final PackedInts.Writer w = PackedInts.getWriterNoHeader(out, PackedInts.Format.PACKED, length,
                    bitsRequired, 1);
            for (int i = 0; i < length; ++i) {
                w.add(values[i]);
            }
            w.finish();
        }
    }
}

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>.
 *//*from   w  w  w.  j a v a2s .com*/
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.LucurePostingsWriter.java

License:Apache License

@Override
public void encodeTerm(long[] longs, DataOutput out, FieldInfo fieldInfo, BlockTermState _state,
        boolean absolute) throws IOException {
    IntBlockTermState state = (IntBlockTermState) _state;
    if (absolute) {
        lastState = emptyState;/*www.  j  ava  2s.c o  m*/
    }
    longs[0] = state.docStartFP - lastState.docStartFP;
    if (fieldHasPositions) {
        longs[1] = state.posStartFP - lastState.posStartFP;
        if (fieldHasPayloads || fieldHasOffsets) {
            longs[2] = state.payStartFP - lastState.payStartFP;
        }
    }
    if (state.singletonDocID != -1) {
        out.writeVInt(state.singletonDocID);
    }
    if (fieldHasPositions) {
        if (state.lastPosBlockOffset != -1) {
            out.writeVLong(state.lastPosBlockOffset);
        }
    }
    if (state.skipOffset != -1) {
        out.writeVLong(state.skipOffset);
    }
    lastState = state;
}

From source file:com.sindicetech.siren.index.codecs.siren10.Siren10PostingsWriter.java

License:Open Source License

@Override
public void encodeTerm(final long[] longs, final DataOutput out, final FieldInfo fieldInfo,
        final BlockTermState _state, final boolean absolute) throws IOException {
    Siren10TermState state = (Siren10TermState) _state;

    if (absolute) {
        lastSkipFP = 0;/* ww w . j a v  a2 s .  c o  m*/
        lastState = state;
    }

    // write block count stat
    // logger.debug("Write blockCount: {}", state.blockCount);
    out.writeVInt(state.blockCount);

    lastState.docIndex.copyFrom(state.docIndex, false);
    lastState.docIndex.write(out, absolute);

    if (state.skipFP != -1) {
        if (absolute) {
            out.writeVLong(state.skipFP);
        } else {
            out.writeVLong(state.skipFP - lastSkipFP);
        }
        lastSkipFP = state.skipFP;
    }
}