use of com.intellij.util.io.storage.RecordIdIterator in project intellij-community by JetBrains.
the class CompactRecordsTable method createRecordIdIterator.
@Override
public RecordIdIterator createRecordIdIterator() throws IOException {
final BitSet extraRecordsIds = buildIdSetOfExtraRecords();
final RecordIdIterator iterator = super.createRecordIdIterator();
return new RecordIdIterator() {
int nextId = scanToNextId();
private int scanToNextId() {
while (iterator.hasNextId()) {
int next = iterator.nextId();
if (!extraRecordsIds.get(next))
return next;
}
return -1;
}
@Override
public boolean hasNextId() {
return nextId != -1;
}
@Override
public int nextId() {
assert hasNextId();
int result = nextId;
nextId = scanToNextId();
return result;
}
@Override
public boolean validId() {
assert hasNextId();
return getSize(nextId) != -1;
}
};
}
use of com.intellij.util.io.storage.RecordIdIterator in project intellij-community by JetBrains.
the class CompactRecordsTable method buildIdSetOfExtraRecords.
@NotNull
private BitSet buildIdSetOfExtraRecords() throws IOException {
final BitSet extraRecords = new BitSet();
final RecordIdIterator iterator = super.createRecordIdIterator();
while (iterator.hasNextId()) {
int recordId = iterator.nextId();
final int sizeAndCapacityOfRecordAbsoluteOffset = getOffset(recordId, SIZE_AND_CAPACITY_OFFSET);
final int sizeAndCapacityValue = myStorage.getInt(sizeAndCapacityOfRecordAbsoluteOffset);
final int addressOfRecordAbsoluteOffset = getOffset(recordId, ADDRESS_OFFSET);
final int existingAddressValue = myStorage.getInt(addressOfRecordAbsoluteOffset);
if (sizeAndCapacityValue < 0) {
extraRecords.set(-sizeAndCapacityValue);
}
if (existingAddressValue < 0) {
extraRecords.set(-existingAddressValue);
}
}
return extraRecords;
}
use of com.intellij.util.io.storage.RecordIdIterator in project intellij-community by JetBrains.
the class CompactStorageTest method testCompactAndIterators.
public void testCompactAndIterators() throws IOException {
TIntArrayList recordsList = new TIntArrayList();
// 1000 records after deletion greater than 3M limit for init time compaction
final int recordCount = 2000;
for (int i = 0; i < recordCount; ++i) recordsList.add(createTestRecord());
final int physicalRecordCount = myStorage.getLiveRecordsCount();
for (int i = 0; i < recordCount / 2; ++i) myStorage.deleteRecord(recordsList.getQuick(i));
int logicalRecordCount = countLiveLogicalRecords();
assertEquals(recordCount / 2, logicalRecordCount);
// compact is triggered
Disposer.dispose(myStorage);
myStorage = createStorage(getFileName());
assertEquals(myStorage.getLiveRecordsCount(), physicalRecordCount / 2);
logicalRecordCount = 0;
RecordIdIterator recordIdIterator = myStorage.createRecordIdIterator();
while (recordIdIterator.hasNextId()) {
boolean validId = recordIdIterator.validId();
int nextId = recordIdIterator.nextId();
if (!validId)
continue;
++logicalRecordCount;
checkTestRecord(nextId);
}
assertEquals(recordCount / 2, logicalRecordCount);
}
use of com.intellij.util.io.storage.RecordIdIterator in project intellij-community by JetBrains.
the class CompactStorageTest method countLiveLogicalRecords.
protected int countLiveLogicalRecords() throws IOException {
RecordIdIterator recordIdIterator = myStorage.createRecordIdIterator();
int logicalRecordCount = 0;
while (recordIdIterator.hasNextId()) {
boolean validId = recordIdIterator.validId();
recordIdIterator.nextId();
if (!validId)
continue;
++logicalRecordCount;
}
return logicalRecordCount;
}
Aggregations