Search in sources :

Example 1 with IntSink

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

Example 2 with IntSink

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());
}
Also used : FixieFun6(primal.adt.Fixie_.FixieFun6) LibcJna(suite.ansi.LibcJna) IRopeList(suite.persistent.PerRope.IRopeList) Termios(suite.ansi.Termios) Fail.fail(primal.statics.Fail.fail) Native(com.sun.jna.Native) Predicate(java.util.function.Predicate) Coord(suite.primitive.Coord) Math.min(java.lang.Math.min) IntSink(primal.primitive.IntPrim.IntSink) IntsBuilder(primal.primitive.adt.Ints.IntsBuilder) Sink(primal.fp.Funs.Sink) Streamlet_.forInt(suite.util.Streamlet_.forInt) ReadString(primal.Verbs.ReadString) IntMutable(primal.primitive.adt.IntMutable) Keyboard(suite.ansi.Keyboard) VK(suite.ansi.Keyboard.VK) Math.max(java.lang.Math.max) NewChr(primal.primitive.ChrVerbs.NewChr) FixieFun3(primal.adt.Fixie_.FixieFun3) IntSink(primal.primitive.IntPrim.IntSink) IntsBuilder(primal.primitive.adt.Ints.IntsBuilder)

Aggregations

IntSink (primal.primitive.IntPrim.IntSink)2 Streamlet_.forInt (suite.util.Streamlet_.forInt)2 Native (com.sun.jna.Native)1 Math.max (java.lang.Math.max)1 Math.min (java.lang.Math.min)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 ReadString (primal.Verbs.ReadString)1 FixieFun3 (primal.adt.Fixie_.FixieFun3)1 FixieFun6 (primal.adt.Fixie_.FixieFun6)1 Sink (primal.fp.Funs.Sink)1 NewChr (primal.primitive.ChrVerbs.NewChr)1 IntMutable (primal.primitive.adt.IntMutable)1 IntsBuilder (primal.primitive.adt.Ints.IntsBuilder)1 IntIntPair (primal.primitive.adt.pair.IntIntPair)1 Fail.fail (primal.statics.Fail.fail)1 PriorityQueue (suite.adt.PriorityQueue)1 Keyboard (suite.ansi.Keyboard)1