/** * Returns a shallow clone of this instance (the underlying ints are * <b>not</b> copied and will be shared by both the returned object and this * object. * * @see #deepCopyOf */ @Override public IntsRef clone() { return new IntsRef(ints, offset, length); }
/** Sole constructor. */ public IntsRefBuilder() { ref = new IntsRef(); }
@Override public IntsRef subtract(IntsRef output, IntsRef inc) { assert output != null; assert inc != null; if (inc == NO_OUTPUT) { // no prefix removed return output; } else if (inc.length == output.length) { // entire output removed return NO_OUTPUT; } else { assert inc.length < output.length: "inc.length=" + inc.length + " vs output.length=" + output.length; assert inc.length > 0; return new IntsRef(output.ints, output.offset + inc.length, output.length-inc.length); } }
@Override public IntsRef add(IntsRef prefix, IntsRef output) { assert prefix != null; assert output != null; if (prefix == NO_OUTPUT) { return output; } else if (output == NO_OUTPUT) { return prefix; } else { assert prefix.length > 0; assert output.length > 0; IntsRef result = new IntsRef(prefix.length + output.length); System.arraycopy(prefix.ints, prefix.offset, result.ints, 0, prefix.length); System.arraycopy(output.ints, output.offset, result.ints, prefix.length, output.length); result.length = prefix.length + output.length; return result; } }
@Override public IntsRef common(IntsRef output1, IntsRef output2) { assert output1 != null; assert output2 != null; int pos1 = output1.offset; int pos2 = output2.offset; int stopAt1 = pos1 + Math.min(output1.length, output2.length); while(pos1 < stopAt1) { if (output1.ints[pos1] != output2.ints[pos2]) { break; } pos1++; pos2++; } if (pos1 == output1.offset) { // no common prefix return NO_OUTPUT; } else if (pos1 == output1.offset + output1.length) { // output1 is a prefix of output2 return output1; } else if (pos2 == output2.offset + output2.length) { // output2 is a prefix of output1 return output2; } else { return new IntsRef(output1.ints, output1.offset, pos1-output1.offset); } }
/** * Creates a new IntsRef that points to a copy of the ints from * <code>other</code> * <p> * The returned IntsRef will have a length of other.length * and an offset of zero. */ public static IntsRef deepCopyOf(IntsRef other) { return new IntsRef(ArrayUtil.copyOfSubArray(other.ints, other.offset, other.offset + other.length), 0, other.length); }
@Override public IntsRef read(DataInput in) throws IOException { final int len = in.readVInt(); if (len == 0) { return NO_OUTPUT; } else { final IntsRef output = new IntsRef(len); for(int idx=0;idx<len;idx++) { output.ints[idx] = in.readVInt(); } output.length = len; return output; } }
private FST<IntsRef> affixFST(TreeMap<String,List<Integer>> affixes) throws IOException { IntSequenceOutputs outputs = IntSequenceOutputs.getSingleton(); Builder<IntsRef> builder = new Builder<>(FST.INPUT_TYPE.BYTE4, outputs); IntsRefBuilder scratch = new IntsRefBuilder(); for (Map.Entry<String,List<Integer>> entry : affixes.entrySet()) { Util.toUTF32(entry.getKey(), scratch); List<Integer> entries = entry.getValue(); IntsRef output = new IntsRef(entries.size()); for (Integer c : entries) { output.ints[output.length++] = c; } builder.add(scratch.get(), output); } return builder.finish(); }
/** * Returns a shallow clone of this instance (the underlying ints are * <b>not</b> copied and will be shared by both the returned object and this * object. * * @see #deepCopyOf */ @Override public IntsRef clone() { return new IntsRef(ints, offset, length); }
/** * Returns a shallow clone of this instance (the underlying ints are * <b>not</b> copied and will be shared by both the returned object and this * object. * * @see #deepCopyOf */ @Override public IntsRef clone() { return new IntsRef(ints, offset, length); }
/** * Returns a shallow clone of this instance (the underlying ints are * <b>not</b> copied and will be shared by both the returned object and this * object. * * @see #deepCopyOf */ @Override public IntsRef clone() { return new IntsRef(ints, offset, length); }
/** * Creates a new IntsRef that points to a copy of the ints from * <code>other</code> * <p> * The returned IntsRef will have a length of other.length * and an offset of zero. */ public static IntsRef deepCopyOf(IntsRef other) { return new IntsRef(Arrays.copyOfRange(other.ints, other.offset, other.offset + other.length), 0, other.length); }
private static IntsRef toIntsRef(String s) { IntsRef ref = new IntsRef(s.length()); // worst case int utf16Len = s.length(); for (int i = 0, cp = 0; i < utf16Len; i += Character.charCount(cp)) { cp = ref.ints[ref.length++] = Character.codePointAt(s, i); } return ref; } }
/** * Creates a new IntsRef that points to a copy of the ints from * <code>other</code> * <p> * The returned IntsRef will have a length of other.length * and an offset of zero. */ public static IntsRef deepCopyOf(IntsRef other) { IntsRef clone = new IntsRef(); clone.copyInts(other); return clone; }
/** * Creates a new IntsRef that points to a copy of the ints from * <code>other</code> * <p> * The returned IntsRef will have a length of other.length * and an offset of zero. */ public static IntsRef deepCopyOf(IntsRef other) { return new IntsRef(ArrayUtil.copyOfSubArray(other.ints, other.offset, other.offset + other.length), 0, other.length); }
public NodBlockWriter() { // ensure that the input buffers has the minimum size required // maxBlockSize is just use as a minimum initial capacity for the buffers nodLenBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); nodBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); termFreqBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); // init of the compressed buffers nodLenCompressedBuffer = new BytesRef(); nodCompressedBuffer = new BytesRef(); termFreqCompressedBuffer = new BytesRef(); }
public NodBlockWriter() { // ensure that the input buffers has the minimum size required // maxBlockSize is just use as a minimum initial capacity for the buffers nodLenBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); nodBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); termFreqBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, nodCompressor.getWindowSize())); // init of the compressed buffers nodLenCompressedBuffer = new BytesRef(); nodCompressedBuffer = new BytesRef(); termFreqCompressedBuffer = new BytesRef(); }
public FSTFieldWriter(FieldInfo fieldInfo, long termsFilePointer) throws IOException { this.fieldInfo = fieldInfo; fstOutputs = PositiveIntOutputs.getSingleton(); fstBuilder = new Builder<>(FST.INPUT_TYPE.BYTE1, fstOutputs); indexStart = out.getFilePointer(); ////System.out.println("VGW: field=" + fieldInfo.name); // Always put empty string in fstBuilder.add(new IntsRef(), termsFilePointer); startTermsFilePointer = termsFilePointer; }
public DocsFreqBlockWriter() { // ensure that the input buffers has the minimum size required docBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, docCompressor.getWindowSize())); nodFreqBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, freqCompressor.getWindowSize())); // determine max size of compressed buffer to avoid overflow int size = docCompressor.maxCompressedSize(maxBlockSize); docCompressedBuffer = new BytesRef(size); size = freqCompressor.maxCompressedSize(maxBlockSize); nodFreqCompressedBuffer = new BytesRef(size); }
public DocsFreqBlockWriter() { // ensure that the input buffers has the minimum size required docBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, docCompressor.getWindowSize())); nodFreqBuffer = new IntsRef(this.getMinimumBufferSize(maxBlockSize, freqCompressor.getWindowSize())); // determine max size of compressed buffer to avoid overflow int size = docCompressor.maxCompressedSize(maxBlockSize); docCompressedBuffer = new BytesRef(size); size = freqCompressor.maxCompressedSize(maxBlockSize); nodFreqCompressedBuffer = new BytesRef(size); }