Search in sources :

Example 1 with Lccs

use of suite.lcs.Lccs in project suite by stupidsing.

the class TextUtil method diff.

public List<Pair<Bytes, Bytes>> diff(Bytes bytesx, Bytes bytesy) {
    Lccs lccs = new Lccs();
    Pair<Segment, Segment> diff = lccs.lccs(bytesx, bytesy);
    Segment sx = diff.t0, sy = diff.t1;
    int x0 = 0, x1 = sx.start, x2 = sx.end, xx = bytesx.size();
    int y0 = 0, y1 = sy.start, y2 = sy.end, yx = bytesy.size();
    Bytes common = bytesx.range(x1, x2);
    if (!sx.isEmpty() && !sy.isEmpty()) {
        List<Pair<Bytes, Bytes>> patch = new ArrayList<>();
        patch.addAll(diff(bytesx.range(x0, x1), bytesy.range(y0, y1)));
        patch.add(Pair.of(common, common));
        patch.addAll(diff(bytesx.range(x2, xx), bytesy.range(y2, yx)));
        return patch;
    } else if (!bytesx.isEmpty() || !bytesy.isEmpty())
        return List.of(Pair.of(bytesx, bytesy));
    else
        return List.of();
}
Also used : Bytes(suite.primitive.Bytes) Lccs(suite.lcs.Lccs) ArrayList(java.util.ArrayList) Pair(suite.adt.pair.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 Pair (suite.adt.pair.Pair)1 Lccs (suite.lcs.Lccs)1 Bytes (suite.primitive.Bytes)1