RandomAccessIntContainer () { if (changes == null) return randomAccessContainer; boolean copyChanges = true; RandomAccessIntContainer idSet; if (randomAccessContainer == null) { int someElementsNumberEstimation = length; // todo we can check these lengths instead of only relying upon reaching MAX_FILES //int lengthOfBitSet = IdBitSet.sizeInBytes(minMax[1], minMax[0]); //int lengthOfIntSet = 4 * length; if (someElementsNumberEstimation < MAX_FILES) { if (!hasRemovals) { if (mayHaveDupes) { removingDupesAndSort(); } idSet = new SortedIdSet(changes, length); copyChanges = false; } else { idSet = new SortedIdSet(Math.max(someElementsNumberEstimation, 3)); } } else if (!hasRemovals) { idSet = new IdBitSet(changes, length, 0); copyChanges = false; } else { idSet = new IdBitSet(calcMinMax(changes, length), 0); } } else { idSet = randomAccessContainer; } assert idSet != null; if (copyChanges) { for(int i = 0, len = length; i < len; ++i) { int id = changes[i]; if (id > 0) { idSet.add(id); } else { idSet.remove(-id); } } } length = 0; hasRemovals = false; mayHaveDupes = false; randomAccessContainer = idSet; changes = null; return randomAccessContainer; }