Search in sources :

Example 36 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class SmartIntToIntArrayMap method removeFromMultiMap.

private void removeFromMultiMap(int key, int value) {
    final TIntObjectHashMap<TIntArrayList> map = myMultipleValuesMap;
    if (map == null)
        return;
    TIntArrayList list = map.get(key);
    if (list != null) {
        int offset = list.indexOf(value);
        if (offset != -1) {
            list.remove(offset);
            if (list.isEmpty()) {
                map.remove(key);
            }
        }
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

Example 37 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class ResolverTree method reduceCyclicVariables.

private void reduceCyclicVariables() {
    final Set<PsiTypeVariable> nodes = new HashSet<>();
    final Set<Constraint> candidates = new HashSet<>();
    final Map<PsiTypeVariable, Set<PsiTypeVariable>> ins = new HashMap<>();
    final Map<PsiTypeVariable, Set<PsiTypeVariable>> outs = new HashMap<>();
    for (final Constraint constraint : myConstraints) {
        final PsiType left = constraint.getLeft();
        final PsiType right = constraint.getRight();
        if (left instanceof PsiTypeVariable && right instanceof PsiTypeVariable) {
            final PsiTypeVariable leftVar = (PsiTypeVariable) left;
            final PsiTypeVariable rightVar = (PsiTypeVariable) right;
            candidates.add(constraint);
            nodes.add(leftVar);
            nodes.add(rightVar);
            Set<PsiTypeVariable> in = ins.get(leftVar);
            Set<PsiTypeVariable> out = outs.get(rightVar);
            if (in == null) {
                final Set<PsiTypeVariable> newIn = new HashSet<>();
                newIn.add(rightVar);
                ins.put(leftVar, newIn);
            } else {
                in.add(rightVar);
            }
            if (out == null) {
                final Set<PsiTypeVariable> newOut = new HashSet<>();
                newOut.add(leftVar);
                outs.put(rightVar, newOut);
            } else {
                out.add(leftVar);
            }
        }
    }
    final DFSTBuilder<PsiTypeVariable> dfstBuilder = new DFSTBuilder<>(new Graph<PsiTypeVariable>() {

        @Override
        public Collection<PsiTypeVariable> getNodes() {
            return nodes;
        }

        @Override
        public Iterator<PsiTypeVariable> getIn(final PsiTypeVariable n) {
            final Set<PsiTypeVariable> in = ins.get(n);
            if (in == null) {
                return EmptyIterator.getInstance();
            }
            return in.iterator();
        }

        @Override
        public Iterator<PsiTypeVariable> getOut(final PsiTypeVariable n) {
            final Set<PsiTypeVariable> out = outs.get(n);
            if (out == null) {
                return EmptyIterator.getInstance();
            }
            return out.iterator();
        }
    });
    final TIntArrayList sccs = dfstBuilder.getSCCs();
    final Map<PsiTypeVariable, Integer> index = new HashMap<>();
    sccs.forEach(new TIntProcedure() {

        int myTNumber;

        @Override
        public boolean execute(int size) {
            for (int j = 0; j < size; j++) {
                index.put(dfstBuilder.getNodeByTNumber(myTNumber + j), myTNumber);
            }
            myTNumber += size;
            return true;
        }
    });
    for (final Constraint constraint : candidates) {
        if (index.get(constraint.getLeft()).equals(index.get(constraint.getRight()))) {
            myConstraints.remove(constraint);
        }
    }
    Binding binding = myBindingFactory.create();
    for (final PsiTypeVariable fromVar : index.keySet()) {
        final PsiTypeVariable toVar = dfstBuilder.getNodeByNNumber(index.get(fromVar).intValue());
        if (!fromVar.equals(toVar)) {
            binding = binding.compose(myBindingFactory.create(fromVar, toVar));
            if (binding == null) {
                break;
            }
        }
    }
    if (binding != null && binding.nonEmpty()) {
        myCurrentBinding = myCurrentBinding.compose(binding);
        myConstraints = apply(binding);
    }
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) Constraint(com.intellij.refactoring.typeCook.deductive.builder.Constraint) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntArrayList(gnu.trove.TIntArrayList) Constraint(com.intellij.refactoring.typeCook.deductive.builder.Constraint) EmptyIterator(com.intellij.util.containers.EmptyIterator) DFSTBuilder(com.intellij.util.graph.DFSTBuilder)

Example 38 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class LineOffsets method create.

@NotNull
public static LineOffsets create(@NotNull CharSequence text) {
    TIntArrayList ends = new TIntArrayList();
    int index = 0;
    while (true) {
        int lineEnd = StringUtil.indexOf(text, '\n', index);
        if (lineEnd != -1) {
            ends.add(lineEnd);
            index = lineEnd + 1;
        } else {
            ends.add(text.length());
            break;
        }
    }
    return new LineOffsets(ends.toNativeArray(), text.length());
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class RichControlFlow method reducible.

// Tarjan. Testing flow graph reducibility.
// Journal of Computer and System Sciences 9.3 (1974): 355-365.
public boolean reducible() {
    if (dfsTree.back.isEmpty()) {
        return true;
    }
    int size = controlFlow.transitions.length;
    boolean[] loopEnters = dfsTree.loopEnters;
    TIntHashSet[] cycleIncomings = new TIntHashSet[size];
    // really this may be array, since dfs already ensures no duplicates
    TIntArrayList[] nonCycleIncomings = new TIntArrayList[size];
    int[] collapsedTo = new int[size];
    int[] queue = new int[size];
    int top;
    for (int i = 0; i < size; i++) {
        if (loopEnters[i]) {
            cycleIncomings[i] = new TIntHashSet();
        }
        nonCycleIncomings[i] = new TIntArrayList();
        collapsedTo[i] = i;
    }
    // from whom back connections
    for (Edge edge : dfsTree.back) {
        cycleIncomings[edge.to].add(edge.from);
    }
    // from whom ordinary connections
    for (Edge edge : dfsTree.nonBack) {
        nonCycleIncomings[edge.to].add(edge.from);
    }
    for (int w = size - 1; w >= 0; w--) {
        top = 0;
        // NB - it is modified later!
        TIntHashSet p = cycleIncomings[w];
        if (p == null) {
            continue;
        }
        TIntIterator iter = p.iterator();
        while (iter.hasNext()) {
            queue[top++] = iter.next();
        }
        while (top > 0) {
            int x = queue[--top];
            TIntArrayList incoming = nonCycleIncomings[x];
            for (int i = 0; i < incoming.size(); i++) {
                int y1 = collapsedTo[incoming.getQuick(i)];
                if (!dfsTree.isDescendant(y1, w)) {
                    return false;
                }
                if (y1 != w && p.add(y1)) {
                    queue[top++] = y1;
                }
            }
        }
        iter = p.iterator();
        while (iter.hasNext()) {
            collapsedTo[iter.next()] = w;
        }
    }
    return true;
}
Also used : TIntIterator(gnu.trove.TIntIterator) Edge(com.intellij.codeInspection.bytecodeAnalysis.asm.ControlFlowGraph.Edge) TIntHashSet(gnu.trove.TIntHashSet) TIntArrayList(gnu.trove.TIntArrayList)

Example 40 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class StubIndexImpl method getContainingIds.

@NotNull
@Override
public <Key> IdIterator getContainingIds(@NotNull StubIndexKey<Key, ?> indexKey, @NotNull Key dataKey, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
    final TIntArrayList result = new TIntArrayList();
    doProcessStubs(indexKey, dataKey, project, scope, new StubIdListContainerAction(null, project) {

        @Override
        protected boolean process(int id, StubIdList value) {
            result.add(id);
            return true;
        }
    });
    return new IdIterator() {

        int cursor;

        @Override
        public boolean hasNext() {
            return cursor < result.size();
        }

        @Override
        public int next() {
            return result.get(cursor++);
        }

        @Override
        public int size() {
            return result.size();
        }
    };
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TIntArrayList (gnu.trove.TIntArrayList)104 NotNull (org.jetbrains.annotations.NotNull)34 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Nullable (org.jetbrains.annotations.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)3 StringSearcher (com.intellij.util.text.StringSearcher)3 TIntHashSet (gnu.trove.TIntHashSet)3 TIntProcedure (gnu.trove.TIntProcedure)3 IOException (java.io.IOException)3 IDevice (com.android.ddmlib.IDevice)2 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 ElementToWorkOn (com.intellij.refactoring.introduceField.ElementToWorkOn)2 IntroduceParameterProcessor (com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2