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;}}
public CachedOrds(OrdinalsSegmentReader source, int maxDoc){Offsets = new int[maxDoc + 1];int[] ords = new int[maxDoc]; long totOrds = 0;Int32sRef values = new Int32sRef(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 ThreadStateException("too many ordinals (>= " + nextLength + ") to cache");}ords = ArrayUtil.Grow(ords, (int)nextLength);}Array.Copy(values.Int32s, 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];Array.Copy(ords, 0, this.Ordinals, 0, (int)totOrds);}else{this.Ordinals = ords;}}