use of primal.primitive.IntPrim.IntSink 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);
}
use of primal.primitive.IntPrim.IntSink in project suite by stupidsing.
the class DevMain method text.
private Text text(IRopeList<Character> text) {
var starts = new IntsBuilder();
var ends = new IntsBuilder();
var p0 = IntMutable.of(-1);
var size = text.size;
IntSink lf = px -> {
starts.append(p0.value() + 1);
ends.append(px);
p0.update(px);
};
for (var p = 0; p < size; p++) {
var ch = text.get.apply(p);
if (ch == '\n' || wrapSize < p - p0.value())
lf.f(p);
}
if (1 < size - p0.value())
lf.f(size);
return new Text(text, starts.toInts().toArray(), ends.toInts().toArray());
}
Aggregations