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);
}
Aggregations