public CachedOrds(OrdinalsSegmentReader source, int maxDoc) throws IOException {offsets = new int[maxDoc + 1];int[] ords = new int[maxDoc]; 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 ((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;}}