RandomAccessIntContainer () { return new UpgradableRandomAccessIntContainer<>( INVERTED_INDEX_SIZE_THRESHOLD, () -> { return new IntHashSetAsRAIntContainer(Hash.DEFAULT_INITIAL_SIZE, Hash.DEFAULT_LOAD_FACTOR); }, (container) -> { // calculate needed capacity so there are less memory allocations int maxId = 0; for (IntIdsIterator it = container.intIterator(); it.hasNext(); ) { int id = it.next(); if (maxId < id) maxId = id; } return new BitSetAsRAIntContainer(maxId + 1); } ); }