use of suite.adt.PriorityQueue in project suite by stupidsing.
the class SparseMatrix method transpose.
public SparseMatrix transpose() {
PriorityQueue<IntIntPair> pq = new PriorityQueue<>(IntIntPair.class, height, (p0, p1) -> Integer.compare(p0.t1, p1.t1));
List<Spans> matrix1 = Ints_.range(width_).map(i -> new Spans()).toList();
int[] js = new int[height];
IntSink enqRow = r -> {
int j = js[r];
if (j < matrix.get(r).size)
pq.insert(IntIntPair.of(r, j));
};
for (int r = 0; r < height; r++) enqRow.sink(r);
while (!pq.isEmpty()) {
IntIntPair pair = pq.extractMin();
int r = pair.t0;
int j = js[r]++;
Spans spans = matrix.get(r);
matrix1.get(spans.columns[j]).add(r, spans.values[j]);
enqRow.sink(r);
}
return new SparseMatrix(width_, height, matrix1);
}
Aggregations