int newKeyCount = existing.size() - removedKeyCount;
// Subtract (removedKeyCount * 4) from the new size to account for fewer entries in the first section, which
// stores the position of the actual entries in the summary.
Memory memory = Memory.allocate(newOffHeapSize - (removedKeyCount * 4));
// Copy old entries to our new Memory.
int idxPosition = 0;
int keyPosition = newKeyCount * 4;
outer:
for (int oldSummaryIndex = 0; oldSummaryIndex < existing.size(); oldSummaryIndex++)
{
// to determine if we can skip this entry, go through the starting points for our downsampling rounds
// and see if the entry's index is covered by that round
for (int start : startPoints)
{
if ((oldSummaryIndex - start) % currentSamplingLevel == 0)
continue outer;
}
// write the position of the actual entry in the index summary (4 bytes)
memory.setInt(idxPosition, keyPosition);
idxPosition += TypeSizes.NATIVE.sizeof(keyPosition);
// write the entry itself
byte[] entry = existing.getEntry(oldSummaryIndex);
memory.setBytes(keyPosition, entry, 0, entry.length);
keyPosition += entry.length;
}
return new IndexSummary(partitioner, memory, newKeyCount, existing.getMaxNumberOfEntries(),
minIndexInterval, newSamplingLevel);
}