Java Code Examples for org.apache.lucene.util.ArrayUtil#MAX_ARRAY_LENGTH

The following examples show how to use org.apache.lucene.util.ArrayUtil#MAX_ARRAY_LENGTH . 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: SimpleTextBKDWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void verifyParams(int numDims, int numIndexDims, int maxPointsInLeafNode, double maxMBSortInHeap, long totalPointCount) {
  // We encode dim in a single byte in the splitPackedValues, but we only expose 4 bits for it now, in case we want to use
  // remaining 4 bits for another purpose later
  if (numDims < 1 || numDims > MAX_DIMS) {
    throw new IllegalArgumentException("numDims must be 1 .. " + MAX_DIMS + " (got: " + numDims + ")");
  }
  if (numIndexDims < 1 || numIndexDims > MAX_INDEX_DIMS) {
    throw new IllegalArgumentException("numIndexDims must be 1 .. " + MAX_INDEX_DIMS + " (got: " + numIndexDims + ")");
  }
  if (numIndexDims > numDims) {
    throw new IllegalArgumentException("numIndexDims cannot exceed numDims (" + numDims + ") (got: " + numIndexDims + ")");
  }
  if (maxPointsInLeafNode <= 0) {
    throw new IllegalArgumentException("maxPointsInLeafNode must be > 0; got " + maxPointsInLeafNode);
  }
  if (maxPointsInLeafNode > ArrayUtil.MAX_ARRAY_LENGTH) {
    throw new IllegalArgumentException("maxPointsInLeafNode must be <= ArrayUtil.MAX_ARRAY_LENGTH (= " + ArrayUtil.MAX_ARRAY_LENGTH + "); got " + maxPointsInLeafNode);
  }
  if (maxMBSortInHeap < 0.0) {
    throw new IllegalArgumentException("maxMBSortInHeap must be >= 0.0 (got: " + maxMBSortInHeap + ")");
  }
  if (totalPointCount < 0) {
    throw new IllegalArgumentException("totalPointCount must be >=0 (got: " + totalPointCount + ")");
  }
}
 
Example 2
Source File: BKDWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void verifyParams(int numDims, int numIndexDims, int maxPointsInLeafNode, double maxMBSortInHeap, long totalPointCount) {
  // We encode dim in a single byte in the splitPackedValues, but we only expose 4 bits for it now, in case we want to use
  // remaining 4 bits for another purpose later
  if (numDims < 1 || numDims > MAX_DIMS) {
    throw new IllegalArgumentException("numDims must be 1 .. " + MAX_DIMS + " (got: " + numDims + ")");
  }
  if (numIndexDims < 1 || numIndexDims > MAX_INDEX_DIMS) {
    throw new IllegalArgumentException("numIndexDims must be 1 .. " + MAX_INDEX_DIMS + " (got: " + numIndexDims + ")");
  }
  if (numIndexDims > numDims) {
    throw new IllegalArgumentException("numIndexDims cannot exceed numDims (" + numDims + ") (got: " + numIndexDims + ")");
  }
  if (maxPointsInLeafNode <= 0) {
    throw new IllegalArgumentException("maxPointsInLeafNode must be > 0; got " + maxPointsInLeafNode);
  }
  if (maxPointsInLeafNode > ArrayUtil.MAX_ARRAY_LENGTH) {
    throw new IllegalArgumentException("maxPointsInLeafNode must be <= ArrayUtil.MAX_ARRAY_LENGTH (= " + ArrayUtil.MAX_ARRAY_LENGTH + "); got " + maxPointsInLeafNode);
  }
  if (maxMBSortInHeap < 0.0) {
    throw new IllegalArgumentException("maxMBSortInHeap must be >= 0.0 (got: " + maxMBSortInHeap + ")");
  }
  if (totalPointCount < 0) {
    throw new IllegalArgumentException("totalPointCount must be >=0 (got: " + totalPointCount + ")");
  }
}
 
Example 3
Source File: DirectMonotonicWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
DirectMonotonicWriter(IndexOutput metaOut, IndexOutput dataOut, long numValues, int blockShift) {
  if (blockShift < MIN_BLOCK_SHIFT || blockShift > MAX_BLOCK_SHIFT) {
    throw new IllegalArgumentException("blockShift must be in [" + MIN_BLOCK_SHIFT + "-" + MAX_BLOCK_SHIFT + "], got " + blockShift);
  }
  if (numValues < 0) {
    throw new IllegalArgumentException("numValues can't be negative, got " + numValues);
  }
  final long numBlocks = numValues == 0 ? 0 : ((numValues - 1) >>> blockShift) + 1;
  if (numBlocks > ArrayUtil.MAX_ARRAY_LENGTH) {
    throw new IllegalArgumentException("blockShift is too low for the provided number of values: blockShift=" + blockShift +
        ", numValues=" + numValues + ", MAX_ARRAY_LENGTH=" + ArrayUtil.MAX_ARRAY_LENGTH);
  }
  this.meta = metaOut;
  this.data = dataOut;
  this.numValues = numValues;
  final int blockSize = 1 << blockShift;
  this.buffer = new long[(int) Math.min(numValues, blockSize)];
  this.bufferSize = 0;
  this.baseDataPointer = dataOut.getFilePointer();
}
 
Example 4
Source File: CachedOrdinalsReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CachedOrds} from the {@link BinaryDocValues}.
 * Assumes that the {@link BinaryDocValues} is not {@code null}.
 */
public CachedOrds(OrdinalsSegmentReader source, int maxDoc) throws IOException {
  offsets = new int[maxDoc + 1];
  int[] ords = new int[maxDoc]; // let's assume one ordinal per-document as an initial size

  // this aggregator is limited to Integer.MAX_VALUE total ordinals.
  long totOrds = 0;
  final IntsRef values = new IntsRef(32);
  for (int docID = 0; docID < maxDoc; docID++) {
    offsets[docID] = (int) totOrds;
    source.get(docID, values);
    long nextLength = totOrds + values.length;
    if (nextLength > ords.length) {
      if (nextLength > ArrayUtil.MAX_ARRAY_LENGTH) {
        throw new IllegalStateException("too many ordinals (>= " + nextLength + ") to cache");
      }
      ords = ArrayUtil.grow(ords, (int) nextLength);
    }
    System.arraycopy(values.ints, 0, ords, (int) totOrds, values.length);
    totOrds = nextLength;
  }
  offsets[maxDoc] = (int) totOrds;
  
  // if ords array is bigger by more than 10% of what we really need, shrink it
  if ((double) totOrds / ords.length < 0.9) { 
    this.ordinals = new int[(int) totOrds];
    System.arraycopy(ords, 0, this.ordinals, 0, (int) totOrds);
  } else {
    this.ordinals = ords;
  }
}
 
Example 5
Source File: PriorityQueue.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public PriorityQueue(int maxSize, boolean prepopulate) {
  final int heapSize;
  if (0 == maxSize) {
    // We allocate 1 extra to avoid if statement in top()
    heapSize = 2;
  } else {
    if (maxSize > ArrayUtil.MAX_ARRAY_LENGTH) {
      // Don't wrap heapSize to -1, in this case, which
      // causes a confusing NegativeArraySizeException.
      // Note that very likely this will simply then hit
      // an OOME, but at least that's more indicative to
      // caller that this values is too big.  We don't +1
      // in this case, but it's very unlikely in practice
      // one will actually insert this many objects into
      // the PQ:
      // Throw exception to prevent confusing OOME:
      throw new IllegalArgumentException("maxSize must be <= " + ArrayUtil.MAX_ARRAY_LENGTH + "; got: " + maxSize);
    } else {
      // NOTE: we add +1 because all access to heap is
      // 1-based not 0-based.  heap[0] is unused.
      heapSize = maxSize + 1;
    }
  }
  // T is unbounded type, so this unchecked cast works always:
  @SuppressWarnings("unchecked") final T[] h = (T[]) new Object[heapSize];
  this.heap = h;
  this.maxSize = maxSize;

  if (prepopulate) {
    // If sentinel objects are supported, populate the queue with them
    T sentinel = getSentinelObject();
    if (sentinel != null) {
      heap[1] = sentinel;
      for (int i = 2; i < heap.length; i++) {
        heap[i] = getSentinelObject();
      }
      size = maxSize;
    }
  }
}
 
Example 6
Source File: StreamInput.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a vint via {@link #readVInt()} and applies basic checks to ensure the read array size is sane.
 * This method uses {@link #ensureCanReadBytes(int)} to ensure this stream has enough bytes to read for the read array size.
 */
private int readArraySize() throws IOException {
    final int arraySize = readVInt();
    if (arraySize > ArrayUtil.MAX_ARRAY_LENGTH) {
        throw new IllegalStateException("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: " + arraySize);
    }
    if (arraySize < 0) {
        throw new NegativeArraySizeException("array size must be positive but was: " + arraySize);
    }
    // lets do a sanity check that if we are reading an array size that is bigger that the remaining bytes we can safely
    // throw an exception instead of allocating the array based on the size. A simple corrutpted byte can make a node go OOM
    // if the size is large and for perf reasons we allocate arrays ahead of time
    ensureCanReadBytes(arraySize);
    return arraySize;
}
 
Example 7
Source File: UnboundedSortingTopNCollector.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * @param rowAccounting   sorting is a pipeline breaker so account for the used memory
 * @param inputs          contains output {@link Input}s and orderBy {@link Input}s
 * @param expressions     expressions linked to the inputs
 * @param numOutputs      number of output columns
 * @param comparator      used to sort the rows
 * @param initialCapacity the initial capacity of the backing queue
 * @param limit           the max number of rows the result should contain
 * @param offset          the number of rows to skip (after sort)
 */
public UnboundedSortingTopNCollector(RowAccounting<Object[]> rowAccounting,
                                     Collection<? extends Input<?>> inputs,
                                     Iterable<? extends CollectExpression<Row, ?>> expressions,
                                     int numOutputs,
                                     Comparator<Object[]> comparator,
                                     int initialCapacity,
                                     int limit,
                                     int offset) {
    if (initialCapacity <= 0) {
        throw new IllegalArgumentException("Invalid initial capacity: value must be > 0; got: " + initialCapacity);
    }
    if (limit <= 0) {
        throw new IllegalArgumentException("Invalid LIMIT: value must be > 0; got: " + limit);
    }
    if (offset < 0) {
        throw new IllegalArgumentException("Invalid OFFSET: value must be >= 0; got: " + offset);
    }
    this.rowAccounting = rowAccounting;
    this.inputs = inputs;
    this.expressions = expressions;
    this.numOutputs = numOutputs;
    this.comparator = comparator;
    this.initialCapacity = initialCapacity;
    this.offset = offset;
    this.maxNumberOfRowsInQueue = limit + offset;

    if (maxNumberOfRowsInQueue >= ArrayUtil.MAX_ARRAY_LENGTH || maxNumberOfRowsInQueue < 0) {
        // Throw exception to prevent confusing OOME in PriorityQueue
        // 1) if offset + limit exceeds maximum array length
        // 2) if offset + limit exceeds Integer.MAX_VALUE (then maxSize is negative!)
        throw new IllegalArgumentException(
            "Invalid LIMIT + OFFSET: value must be <= " + (ArrayUtil.MAX_ARRAY_LENGTH - 1) + "; got: " + maxNumberOfRowsInQueue);
    }
}
 
Example 8
Source File: BoundedSortingTopNCollector.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * @param rowAccounting    sorting is a pipeline breaker so account for the used memory
 * @param inputs           contains output {@link Input}s and orderBy {@link Input}s
 * @param expressions      expressions linked to the inputs
 * @param numOutputs       number of output columns
 * @param comparator       used to sort the rows
 * @param limit            the max number of rows the result should contain
 * @param offset           the number of rows to skip (after sort)
 */
public BoundedSortingTopNCollector(RowAccounting<Object[]> rowAccounting,
                                   Collection<? extends Input<?>> inputs,
                                   Iterable<? extends CollectExpression<Row, ?>> expressions,
                                   int numOutputs,
                                   Comparator<Object[]> comparator,
                                   int limit,
                                   int offset) {
    if (limit <= 0) {
        throw new IllegalArgumentException("Invalid LIMIT: value must be > 0; got: " + limit);
    }
    if (offset < 0) {
        throw new IllegalArgumentException("Invalid OFFSET: value must be >= 0; got: " + offset);
    }

    this.rowAccounting = rowAccounting;
    this.inputs = inputs;
    this.expressions = expressions;
    this.numOutputs = numOutputs;
    this.comparator = comparator;
    this.offset = offset;
    this.maxSize = limit + offset;

    if (maxSize >= ArrayUtil.MAX_ARRAY_LENGTH || maxSize < 0) {
        // Throw exception to prevent confusing OOME in PriorityQueue
        // 1) if offset + limit exceeds maximum array length
        // 2) if offset + limit exceeds Integer.MAX_VALUE (then maxSize is negative!)
        throw new IllegalArgumentException(
            "Invalid LIMIT + OFFSET: value must be <= " + (ArrayUtil.MAX_ARRAY_LENGTH - 1) + "; got: " + maxSize);
    }
}
 
Example 9
Source File: SimpleTextBKDWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void checkMaxLeafNodeCount(int numLeaves) {
  if ((1+bytesPerDim) * (long) numLeaves > ArrayUtil.MAX_ARRAY_LENGTH) {
    throw new IllegalStateException("too many nodes; increase maxPointsInLeafNode (currently " + maxPointsInLeafNode + ") and reindex");
  }
}
 
Example 10
Source File: BKDWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void checkMaxLeafNodeCount(int numLeaves) {
  if (bytesPerDim * (long) numLeaves > ArrayUtil.MAX_ARRAY_LENGTH) {
    throw new IllegalStateException("too many nodes; increase maxPointsInLeafNode (currently " + maxPointsInLeafNode + ") and reindex");
  }
}