Java Code Examples for org.apache.lucene.util.ArrayUtil#growExact()

The following examples show how to use org.apache.lucene.util.ArrayUtil#growExact() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressingTermVectorsWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
void addPosition(int position, int startOffset, int length, int payloadLength) {
  if (hasPositions) {
    if (posStart + totalPositions == positionsBuf.length) {
      positionsBuf = ArrayUtil.grow(positionsBuf);
    }
    positionsBuf[posStart + totalPositions] = position;
  }
  if (hasOffsets) {
    if (offStart + totalPositions == startOffsetsBuf.length) {
      final int newLength = ArrayUtil.oversize(offStart + totalPositions, 4);
      startOffsetsBuf = ArrayUtil.growExact(startOffsetsBuf, newLength);
      lengthsBuf = ArrayUtil.growExact(lengthsBuf, newLength);
    }
    startOffsetsBuf[offStart + totalPositions] = startOffset;
    lengthsBuf[offStart + totalPositions] = length;
  }
  if (hasPayloads) {
    if (payStart + totalPositions == payloadLengthsBuf.length) {
      payloadLengthsBuf = ArrayUtil.grow(payloadLengthsBuf);
    }
    payloadLengthsBuf[payStart + totalPositions] = payloadLength;
  }
  ++totalPositions;
}
 
Example 2
Source File: WordDelimiterFilter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void buffer() {
  if (bufferedLen == buffered.length) {
    int newSize = ArrayUtil.oversize(bufferedLen+1, 8);
    buffered = ArrayUtil.growExact(buffered, newSize);
    startOff = ArrayUtil.growExact(startOff, newSize);
    posInc = ArrayUtil.growExact(posInc, newSize);
  }
  startOff[bufferedLen] = offsetAttribute.startOffset();
  posInc[bufferedLen] = posIncAttribute.getPositionIncrement();
  buffered[bufferedLen] = captureState();
  bufferedLen++;
}
 
Example 3
Source File: CompressingStoredFieldsWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void finishDocument() throws IOException {
  if (numBufferedDocs == this.numStoredFields.length) {
    final int newLength = ArrayUtil.oversize(numBufferedDocs + 1, 4);
    this.numStoredFields = ArrayUtil.growExact(this.numStoredFields, newLength);
    endOffsets = ArrayUtil.growExact(endOffsets, newLength);
  }
  this.numStoredFields[numBufferedDocs] = numStoredFieldsInDoc;
  numStoredFieldsInDoc = 0;
  endOffsets[numBufferedDocs] = Math.toIntExact(bufferedDocs.size());
  ++numBufferedDocs;
  if (triggerFlush()) {
    flush();
  }
}
 
Example 4
Source File: MaxScoreCache.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void ensureCacheSize(int size) {
  if (maxScoreCache.length < size) {
    int oldLength = maxScoreCache.length;
    maxScoreCache = ArrayUtil.grow(maxScoreCache, size);
    maxScoreCacheUpTo = ArrayUtil.growExact(maxScoreCacheUpTo, maxScoreCache.length);
    Arrays.fill(maxScoreCacheUpTo, oldLength, maxScoreCacheUpTo.length, -1);
  }
}
 
Example 5
Source File: MonotonicLongValues.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
void grow(int newBlockCount) {
  super.grow(newBlockCount);
  ramBytesUsed -= RamUsageEstimator.sizeOf(averages);
  averages = ArrayUtil.growExact(averages, newBlockCount);
  ramBytesUsed += RamUsageEstimator.sizeOf(averages);
}
 
Example 6
Source File: DeltaPackedLongValues.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
void grow(int newBlockCount) {
  super.grow(newBlockCount);
  ramBytesUsed -= RamUsageEstimator.sizeOf(mins);
  mins = ArrayUtil.growExact(mins, newBlockCount);
  ramBytesUsed += RamUsageEstimator.sizeOf(mins);
}
 
Example 7
Source File: PathHierarchyAggregatorFactory.java    From elasticsearch-aggregation-pathhierarchy with MIT License 5 votes vote down vote up
final void growExact() {
    if (values.length < count) {
        final int oldLen = values.length;
        values = ArrayUtil.growExact(values, count);
        for (int i = oldLen; i < count; ++i) {
            values[i] = new BytesRefBuilder();
        }
    }
}
 
Example 8
Source File: LegacyFieldsIndexReader.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
LegacyFieldsIndexReader(IndexInput fieldsIndexIn, SegmentInfo si) throws IOException {
  maxDoc = si.maxDoc();
  int[] docBases = new int[16];
  long[] startPointers = new long[16];
  int[] avgChunkDocs = new int[16];
  long[] avgChunkSizes = new long[16];
  PackedInts.Reader[] docBasesDeltas = new PackedInts.Reader[16];
  PackedInts.Reader[] startPointersDeltas = new PackedInts.Reader[16];

  final int packedIntsVersion = fieldsIndexIn.readVInt();

  int blockCount = 0;

  for (;;) {
    final int numChunks = fieldsIndexIn.readVInt();
    if (numChunks == 0) {
      break;
    }
    if (blockCount == docBases.length) {
      final int newSize = ArrayUtil.oversize(blockCount + 1, 8);
      docBases = ArrayUtil.growExact(docBases, newSize);
      startPointers = ArrayUtil.growExact(startPointers, newSize);
      avgChunkDocs = ArrayUtil.growExact(avgChunkDocs, newSize);
      avgChunkSizes = ArrayUtil.growExact(avgChunkSizes, newSize);
      docBasesDeltas = ArrayUtil.growExact(docBasesDeltas, newSize);
      startPointersDeltas = ArrayUtil.growExact(startPointersDeltas, newSize);
    }

    // doc bases
    docBases[blockCount] = fieldsIndexIn.readVInt();
    avgChunkDocs[blockCount] = fieldsIndexIn.readVInt();
    final int bitsPerDocBase = fieldsIndexIn.readVInt();
    if (bitsPerDocBase > 32) {
      throw new CorruptIndexException("Corrupted bitsPerDocBase: " + bitsPerDocBase, fieldsIndexIn);
    }
    docBasesDeltas[blockCount] = PackedInts.getReaderNoHeader(fieldsIndexIn, PackedInts.Format.PACKED, packedIntsVersion, numChunks, bitsPerDocBase);

    // start pointers
    startPointers[blockCount] = fieldsIndexIn.readVLong();
    avgChunkSizes[blockCount] = fieldsIndexIn.readVLong();
    final int bitsPerStartPointer = fieldsIndexIn.readVInt();
    if (bitsPerStartPointer > 64) {
      throw new CorruptIndexException("Corrupted bitsPerStartPointer: " + bitsPerStartPointer, fieldsIndexIn);
    }
    startPointersDeltas[blockCount] = PackedInts.getReaderNoHeader(fieldsIndexIn, PackedInts.Format.PACKED, packedIntsVersion, numChunks, bitsPerStartPointer);

    ++blockCount;
  }

  this.docBases = ArrayUtil.copyOfSubArray(docBases, 0, blockCount);
  this.startPointers = ArrayUtil.copyOfSubArray(startPointers, 0, blockCount);
  this.avgChunkDocs = ArrayUtil.copyOfSubArray(avgChunkDocs, 0, blockCount);
  this.avgChunkSizes = ArrayUtil.copyOfSubArray(avgChunkSizes, 0, blockCount);
  this.docBasesDeltas = ArrayUtil.copyOfSubArray(docBasesDeltas, 0, blockCount);
  this.startPointersDeltas = ArrayUtil.copyOfSubArray(startPointersDeltas, 0, blockCount);
}
 
Example 9
Source File: CachingCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
protected void grow(int newLen) {
  docs = ArrayUtil.growExact(docs, newLen);
}
 
Example 10
Source File: CachingCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected void grow(int newLen) {
  super.grow(newLen);
  scores = ArrayUtil.growExact(scores, newLen);
}
 
Example 11
Source File: PackedLongValues.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
void grow(int newBlockCount) {
  ramBytesUsed -= RamUsageEstimator.shallowSizeOf(values);
  values = ArrayUtil.growExact(values, newBlockCount);
  ramBytesUsed += RamUsageEstimator.shallowSizeOf(values);
}