Search in sources :

Example 6 with TIntIntHashMap

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 7 with TIntIntHashMap

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));
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap) TIntHashSet(gnu.trove.TIntHashSet)

Example 8 with TIntIntHashMap

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);
    }
}
Also used : SkipSlowTestLocally(com.intellij.testFramework.SkipSlowTestLocally) TIntIntHashMap(gnu.trove.TIntIntHashMap) java.io(java.io) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) Set(java.util.Set) THashSet(gnu.trove.THashSet) Random(java.util.Random) FileUtil(com.intellij.openapi.util.io.FileUtil) NotNull(org.jetbrains.annotations.NotNull) Random(java.util.Random) TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 9 with TIntIntHashMap

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;
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 10 with TIntIntHashMap

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;
}
Also used : AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ProjectData(com.intellij.rt.coverage.data.ProjectData) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FilePath(com.intellij.openapi.vcs.FilePath) LineData(com.intellij.rt.coverage.data.LineData) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) SoftReference(com.intellij.reference.SoftReference) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LineTokenizer(com.intellij.openapi.util.text.LineTokenizer) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) LocalHistory(com.intellij.history.LocalHistory) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LineCoverage(com.intellij.rt.coverage.data.LineCoverage) Computable(com.intellij.openapi.util.Computable) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) ClassData(com.intellij.rt.coverage.data.ClassData) VcsContextFactory(com.intellij.openapi.vcs.actions.VcsContextFactory) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) VcsUtil(com.intellij.vcsUtil.VcsUtil) TIntIntHashMap(gnu.trove.TIntIntHashMap) Key(com.intellij.openapi.util.Key) FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) File(java.io.File) Diff(com.intellij.util.diff.Diff) Alarm(com.intellij.util.Alarm) LineData(com.intellij.rt.coverage.data.LineData) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) TIntIntHashMap(gnu.trove.TIntIntHashMap)

Aggregations

TIntIntHashMap (gnu.trove.TIntIntHashMap)14 NotNull (org.jetbrains.annotations.NotNull)4 Document (com.intellij.openapi.editor.Document)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Editor (com.intellij.openapi.editor.Editor)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Module (com.intellij.openapi.module.Module)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiFile (com.intellij.psi.PsiFile)2 ClassData (com.intellij.rt.coverage.data.ClassData)2 LineData (com.intellij.rt.coverage.data.LineData)2 ProjectData (com.intellij.rt.coverage.data.ProjectData)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2