private /*@NotNull?*/ RandomAccessIntContainer getRandomAccessContainer() {
    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;
      //TODO RC: IdBitSet is very memory-hungry even for small ids count, if the _range_ of ids is big.
      //         IdBitSet size is ~(max(id)-min(id))/8, e.g. ~1.25Mb for a set of 2 ids: {1, 10_000_000}.
      //         On the other hand, SortedIdSet becomes CPU-hungry for large N -- which means there are
      //         scenarios there _neither_ of options is good. E.e. if length > 20k, but ids range is large,
      //         and we opted to use SortedIdSet because it is less memory-hungry -- but it could still be
      //         very CPU hungry instead

      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(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;
  }
private /*@NotNull?*/ RandomAccessIntContainer getRandomAccessContainer()