use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.
the class VfsAwareMapIndexStorage method saveHashedIds.
private void saveHashedIds(@NotNull TIntHashSet hashMaskSet, int largestId, @NotNull GlobalSearchScope scope) {
File newFileWithCaches = getSavedProjectFileValueIds(largestId, scope);
assert newFileWithCaches != null;
DataOutputStream stream = null;
boolean savedSuccessfully = false;
try {
stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFileWithCaches)));
DataInputOutputUtil.writeINT(stream, hashMaskSet.size());
final DataOutputStream finalStream = stream;
savedSuccessfully = hashMaskSet.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
try {
DataInputOutputUtil.writeINT(finalStream, value);
return true;
} catch (IOException ex) {
return false;
}
}
});
} catch (IOException ignored) {
} finally {
if (stream != null) {
try {
stream.close();
if (savedSuccessfully)
myLastScannedId = largestId;
} catch (IOException ignored) {
}
}
}
}
use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.
the class ChangeBufferingList method getRandomAccessContainer.
private RandomAccessIntContainer getRandomAccessContainer() {
int[] currentChanges = changes;
if (currentChanges == null)
return randomAccessContainer;
synchronized (currentChanges) {
currentChanges = changes;
if (currentChanges == null)
return randomAccessContainer;
boolean copyChanges = true;
RandomAccessIntContainer idSet;
if (randomAccessContainer == null) {
int someElementsNumberEstimation = length;
if (someElementsNumberEstimation < MAX_FILES) {
if (!hasRemovals) {
if (mayHaveDupes) {
removingDupesAndSort();
}
idSet = new SortedIdSet(currentChanges, 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 if (checkSet != null) {
idSet = (RandomAccessIntContainer) randomAccessContainer.clone();
} else {
idSet = randomAccessContainer;
}
assert idSet != null;
if (copyChanges) {
for (int i = 0, len = length; i < len; ++i) {
int id = currentChanges[i];
if (id > 0) {
idSet.add(id);
} else {
idSet.remove(-id);
}
}
}
if (checkSet != null) {
DebugAssertions.assertTrue(checkSet.size() == idSet.size());
final RandomAccessIntContainer finalIdSet = idSet;
checkSet.forEach(new TIntProcedure() {
@Override
public boolean execute(int value) {
DebugAssertions.assertTrue(finalIdSet.contains(value));
return true;
}
});
}
length = 0;
hasRemovals = false;
mayHaveDupes = false;
randomAccessContainer = idSet;
changes = null;
return randomAccessContainer;
}
}
use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.
the class ChangeTrackingValueContainer method getMergedData.
// need 'synchronized' to ensure atomic initialization of merged data
// because several threads that acquired read lock may simultaneously execute the method
private ValueContainerImpl<Value> getMergedData() {
ValueContainerImpl<Value> merged = myMerged;
if (merged != null) {
return merged;
}
synchronized (myInitializer.getLock()) {
merged = myMerged;
if (merged != null) {
return merged;
}
FileId2ValueMapping<Value> fileId2ValueMapping = null;
final ValueContainer<Value> fromDisk = myInitializer.compute();
final ValueContainerImpl<Value> newMerged;
if (fromDisk instanceof ValueContainerImpl) {
newMerged = ((ValueContainerImpl<Value>) fromDisk).copy();
} else {
newMerged = ((ChangeTrackingValueContainer<Value>) fromDisk).getMergedData().copy();
}
if ((myAdded != null || myInvalidated != null) && (newMerged.size() > ValueContainerImpl.NUMBER_OF_VALUES_THRESHOLD || (myAdded != null && myAdded.size() > ValueContainerImpl.NUMBER_OF_VALUES_THRESHOLD))) {
// Calculate file ids that have Value mapped to avoid O(NumberOfValuesInMerged) during removal
fileId2ValueMapping = new FileId2ValueMapping<Value>(newMerged);
}
final FileId2ValueMapping<Value> finalFileId2ValueMapping = fileId2ValueMapping;
if (myInvalidated != null) {
myInvalidated.forEach(new TIntProcedure() {
@Override
public boolean execute(int inputId) {
if (finalFileId2ValueMapping != null)
finalFileId2ValueMapping.removeFileId(inputId);
else
newMerged.removeAssociatedValue(inputId);
return true;
}
});
}
if (myAdded != null) {
if (fileId2ValueMapping != null) {
// there is no sense for value per file validation because we have fileId -> value mapping and we are enforcing it here
fileId2ValueMapping.disableOneValuePerFileValidation();
}
myAdded.forEach(new ValueContainer.ContainerAction<Value>() {
@Override
public boolean perform(final int inputId, final Value value) {
// enforcing "one-value-per-file for particular key" invariant
if (finalFileId2ValueMapping != null)
finalFileId2ValueMapping.removeFileId(inputId);
else
newMerged.removeAssociatedValue(inputId);
newMerged.addValue(inputId, value);
if (finalFileId2ValueMapping != null)
finalFileId2ValueMapping.associateFileIdToValue(inputId, value);
return true;
}
});
}
setNeedsCompacting(((UpdatableValueContainer) fromDisk).needsCompacting());
myMerged = newMerged;
return newMerged;
}
}
use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.
the class ByteArrayList method toString.
// stringification
/**
* Returns a String representation of the list, front to back.
*
* @return a {@code String} value
*/
public String toString() {
final StringBuffer buf = new StringBuffer("{");
forEach(new TIntProcedure() {
@Override
public boolean execute(int val) {
buf.append(val);
buf.append(", ");
return true;
}
});
buf.append("}");
return buf.toString();
}
use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.
the class SourceLineCounterUtil method collectSrcLinesForUntouchedFiles.
public static void collectSrcLinesForUntouchedFiles(final List<Integer> uncoveredLines, byte[] content, final boolean excludeLines) {
final ClassReader reader = new ClassReader(content);
final SourceLineCounter collector = new SourceLineCounter(null, excludeLines, null);
reader.accept(collector, 0);
final TIntObjectHashMap lines = collector.getSourceLines();
lines.forEachKey(new TIntProcedure() {
public boolean execute(int line) {
line--;
uncoveredLines.add(line);
return true;
}
});
}
Aggregations