use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.
the class TracingData method main.
public static void main(String[] args) throws IOException {
PersistentHashMap<Integer, Integer> lkeys = createOrOpenMap();
List<Integer> mapping = (List<Integer>) lkeys.getAllKeysWithExistingMapping();
System.out.println(mapping.size());
final TIntIntHashMap map = new TIntIntHashMap(mapping.size());
for (Integer i : mapping) map.put(i, lkeys.get(i));
Collections.sort(mapping, (o1, o2) -> map.get(o2) - map.get(o1));
for (int i = 0; i < 500; ++i) {
//System.out.println(mapping.get(i) + ",");
System.out.println(mapping.get(i) + ":" + map.get(mapping.get(i)));
}
lkeys.close();
}
use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.
the class AbstractDataGetter method runLoadCommitsData.
private void runLoadCommitsData(@NotNull Iterable<Integer> hashes) {
long taskNumber = myCurrentTaskIndex++;
TIntIntHashMap commits = getCommitsMap(hashes);
TIntHashSet toLoad = new TIntHashSet();
for (int id : commits.keys()) {
cacheCommit(id, taskNumber);
toLoad.add(id);
}
myLoader.queue(new TaskDescriptor(toLoad));
}
use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.
the class PersistentMapPerformanceTest method testIntToIntMapPerformance.
public void testIntToIntMapPerformance() throws IOException {
File file = FileUtil.createTempFile("persistent", "map");
FileUtil.createParentDirs(file);
int size = 10000000;
TIntIntHashMap checkMap = new TIntIntHashMap(size);
Random r = new Random(1);
while (size != checkMap.size()) {
if (checkMap.size() == 0) {
checkMap.put(r.nextInt(), 0);
checkMap.put(r.nextInt(), 0);
checkMap.put(0, Math.abs(r.nextInt()));
} else {
checkMap.put(r.nextInt(), Math.abs(r.nextInt()));
}
}
long started = System.currentTimeMillis();
PersistentHashMap<Integer, Integer> map = null;
try {
map = new PersistentHashMap<Integer, Integer>(file, EnumeratorIntegerDescriptor.INSTANCE, EnumeratorIntegerDescriptor.INSTANCE) {
@Override
protected boolean wantNonnegativeIntegralValues() {
return true;
}
};
final PersistentHashMap<Integer, Integer> mapFinal = map;
boolean result = checkMap.forEachEntry((a, b) -> {
try {
mapFinal.put(a, b);
} catch (IOException e) {
e.printStackTrace();
assertTrue(false);
return false;
}
return true;
});
assertTrue(result);
map.close();
System.out.println("Done:" + (System.currentTimeMillis() - started));
started = System.currentTimeMillis();
map = new PersistentHashMap<Integer, Integer>(file, EnumeratorIntegerDescriptor.INSTANCE, EnumeratorIntegerDescriptor.INSTANCE) {
@Override
protected boolean wantNonnegativeIntegralValues() {
return true;
}
};
final PersistentHashMap<Integer, Integer> mapFinal2 = map;
result = checkMap.forEachEntry((a, b) -> {
try {
assertTrue(b == mapFinal2.get(a));
} catch (IOException e) {
e.printStackTrace();
assertTrue(false);
return false;
}
return true;
});
assertTrue(result);
System.out.println("Done 2:" + (System.currentTimeMillis() - started));
} finally {
clearMap(file, map);
}
}
use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.
the class UniqueLCS method execute.
public int[][] execute() {
// map: key -> (offset1 + 1)
// match: offset1 -> (offset2 + 1)
TIntIntHashMap map = new TIntIntHashMap(myCount1 + myCount2);
int[] match = new int[myCount1];
for (int i = 0; i < myCount1; i++) {
int index = myStart1 + i;
int val = map.get(myFirst[index]);
if (val == -1)
continue;
if (val == 0) {
map.put(myFirst[index], i + 1);
} else {
map.put(myFirst[index], -1);
}
}
int count = 0;
for (int i = 0; i < myCount2; i++) {
int index = myStart2 + i;
int val = map.get(mySecond[index]);
if (val == 0 || val == -1)
continue;
if (match[val - 1] == 0) {
match[val - 1] = i + 1;
count++;
} else {
match[val - 1] = 0;
map.put(mySecond[index], -1);
count--;
}
}
if (count == 0) {
return null;
}
// Largest increasing subsequence on unique elements
int[] sequence = new int[count];
int[] lastElement = new int[count];
int[] predecessor = new int[myCount1];
int length = 0;
for (int i = 0; i < myCount1; i++) {
if (match[i] == 0)
continue;
int j = binarySearch(sequence, match[i], length);
if (j == length || match[i] < sequence[j]) {
sequence[j] = match[i];
lastElement[j] = i;
predecessor[i] = j > 0 ? lastElement[j - 1] : -1;
if (j == length) {
length++;
}
}
}
int[][] ret = new int[][] { new int[length], new int[length] };
int i = length - 1;
int curr = lastElement[length - 1];
while (curr != -1) {
ret[0][i] = curr;
ret[1][i] = match[curr] - 1;
i--;
curr = predecessor[curr];
}
return ret;
}
use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.
the class SrcFileAnnotator method createRangeHighlighter.
private RangeHighlighter createRangeHighlighter(final long date, final MarkupModel markupModel, final boolean coverageByTestApplicable, final TreeMap<Integer, LineData> executableLines, @Nullable final String className, final int line, final int lineNumberInCurrent, @NotNull final CoverageSuitesBundle coverageSuite, Object[] lines, @NotNull MyEditorBean editorBean) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes attributes = scheme.getAttributes(CoverageLineMarkerRenderer.getAttributesKey(line, executableLines));
TextAttributes textAttributes = null;
if (attributes.getBackgroundColor() != null) {
textAttributes = attributes;
}
Document document = editorBean.getDocument();
Editor editor = editorBean.getEditor();
final int startOffset = document.getLineStartOffset(lineNumberInCurrent);
final int endOffset = document.getLineEndOffset(lineNumberInCurrent);
final RangeHighlighter highlighter = markupModel.addRangeHighlighter(startOffset, endOffset, HighlighterLayer.SELECTION - 1, textAttributes, HighlighterTargetArea.LINES_IN_RANGE);
final Function<Integer, Integer> newToOldConverter = newLine -> {
if (editor == null)
return -1;
final TIntIntHashMap oldLineMapping = getNewToOldLineMapping(date, editorBean);
return oldLineMapping != null ? oldLineMapping.get(newLine.intValue()) : newLine.intValue();
};
final Function<Integer, Integer> oldToNewConverter = newLine -> {
if (editor == null)
return -1;
final TIntIntHashMap newLineMapping = getOldToNewLineMapping(date, editorBean);
return newLineMapping != null ? newLineMapping.get(newLine.intValue()) : newLine.intValue();
};
final LineMarkerRendererWithErrorStripe markerRenderer = coverageSuite.getLineMarkerRenderer(line, className, executableLines, coverageByTestApplicable, coverageSuite, newToOldConverter, oldToNewConverter, CoverageDataManager.getInstance(myProject).isSubCoverageActive());
highlighter.setLineMarkerRenderer(markerRenderer);
final LineData lineData = className != null ? (LineData) lines[line + 1] : null;
if (lineData != null && lineData.getStatus() == LineCoverage.NONE) {
highlighter.setErrorStripeMarkColor(markerRenderer.getErrorStripeColor(editor));
highlighter.setThinErrorStripeMark(true);
highlighter.setGreedyToLeft(true);
highlighter.setGreedyToRight(true);
}
return highlighter;
}
Aggregations