Here I sort insertions in reverse order according to their positions. This means that the sequence grows starting from back (rightmost insertions are applied first).
This prevents frame shifts, compared to when applying left-to-right or, worse, in some unspecified order. But the correctness of this needs to be double-checked.
The Ord trait sorts instances ofIns by pos first and then by seq in case of equality. It is important to preserve order of fields in the struct. Otherwise, we may implement Ord trait explicitly.
Here I sort insertions in reverse order according to their positions. This means that the sequence grows starting from back (rightmost insertions are applied first).
This prevents frame shifts, compared to when applying left-to-right or, worse, in some unspecified order. But the correctness of this needs to be double-checked.
The
Ord
trait sorts instances ofIns
bypos
first and then byseq
in case of equality. It is important to preserve order of fields in the struct. Otherwise, we may implementOrd
trait explicitly.