Search in sources :

Example 1 with IntIntPair

use of primal.primitive.adt.pair.IntIntPair in project suite by stupidsing.

the class SparseMatrix method transpose.

public SparseMatrix transpose() {
    var pq = new PriorityQueue<>(IntIntPair.class, height, Comparator.comparingInt(IntIntPair::snd));
    var matrix1 = forInt(width_).map(i -> new Spans()).toList();
    var js = new int[height];
    IntSink enqRow = r -> {
        var j = js[r];
        if (j < matrix.get(r).size)
            pq.add(IntIntPair.of(r, j));
    };
    for (var r = 0; r < height; r++) enqRow.f(r);
    while (!pq.isEmpty()) {
        var pair = pq.extractMin();
        var r = pair.t0;
        var j = js[r]++;
        var spans = matrix.get(r);
        matrix1.get(spans.columns[j]).add(r, spans.values[j]);
        enqRow.f(r);
    }
    return new SparseMatrix(width_, height, matrix1);
}
Also used : IntIntPair(primal.primitive.adt.pair.IntIntPair) Arrays(java.util.Arrays) List(java.util.List) IntSink(primal.primitive.IntPrim.IntSink) Comparator(java.util.Comparator) PriorityQueue(suite.adt.PriorityQueue) Streamlet_.forInt(suite.util.Streamlet_.forInt) IntSink(primal.primitive.IntPrim.IntSink) PriorityQueue(suite.adt.PriorityQueue)

Aggregations

Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 IntSink (primal.primitive.IntPrim.IntSink)1 IntIntPair (primal.primitive.adt.pair.IntIntPair)1 PriorityQueue (suite.adt.PriorityQueue)1 Streamlet_.forInt (suite.util.Streamlet_.forInt)1