@Override public void collect(int doc) throws IOException { if (values != null) { int ord = (int) ordinals.getOrd(doc); long parentIdx = parentIdsIndex.get(ord); if (parentIdx < 0) { final BytesRef bytes = values.getValueByOrd(ord); final int hash = values.currentValueHash(); parentIdx = parentIds.add(bytes, hash); if (parentIdx < 0) { parentIdx = -parentIdx - 1; scores.increment(parentIdx, scorer.score()); occurrences.increment(parentIdx, 1); } else { scores = bigArrays.grow(scores, parentIdx + 1); scores.set(parentIdx, scorer.score()); occurrences = bigArrays.grow(occurrences, parentIdx + 1); occurrences.set(parentIdx, 1); } parentIdsIndex.set(ord, parentIdx); } else { scores.increment(parentIdx, scorer.score()); occurrences.increment(parentIdx, 1); } } }
public void testIntArrayGrowth() { final int totalLen = randomIntBetween(1, 1000000); final int startLen = randomIntBetween(1, randomBoolean() ? 1000 : totalLen); IntArray array = bigArrays.newIntArray(startLen, randomBoolean()); int[] ref = new int[totalLen]; for (int i = 0; i < totalLen; ++i) { ref[i] = randomInt(); array = bigArrays.grow(array, i + 1); array.set(i, ref[i]); } for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i)); } array.close(); }