Yet Another Variation of Myers for generic containers (for example std::Vec)
This is an implementation of a quasi-Myers algorithm to determine the differences between two generic containers. Its usage is quite simple, for example:
```rust
let mut a: Vec
// Create the diff (vector of moves)
let moves = crate::yavom::myers(&a, &b);
The return value *moves* is a vector of *Move* objects. You can apply moves to the array as follows:
rust
moves.iter().foreach(|m| { crate::yavom::applymove(m, &mut a); });
// now a's contents are the same as b's
You can serialize / deserialize *Move* objects as you deem necessary. To do so please consider the following definitions (found in *diff.h*):
rust
pub enum OP {
INSERT,
DELETE,
_DELETE,
}
pub struct Point(pub i64, pub i64);
pub struct Move
The *Vec<K>* field stores the values to be inserted. For example:
rust
let ops = myersunfilled(&a, &b);
let mut patch = vec![];
for o in ops {
let Move(op, s, t, _) = o;
match op {
yavomrs::yavom::OP::INSERT => {
let from = s.1 as usize;
let to = (s.1 + count) as usize;
let insertposition = s.1;
let values = &new[from..to];
// TODO Serialize INSERT of values at insertposition
}
yavomrs::yavom::OP::DELETE => {
let count = t.0 - s.0;
let deleteposition = s.1;
// TODO Serialize DELETE of count values starting from deleteposition
}
yavomrs::yavom::OP::DELETE => {
let Point(count, start) = s;
// TODO Serialize DELETE of count values starting from start
}
}
}
If you are interested in knowning how many moves will be necessary but do not want to generate complete moves (with complete insert data), you can
use the *myers_unfilled* function:
rust
let mut moves = crate::yavom::myersunfilled(&a, &b);
eprintln!("{} moves", moves.len());
Subsequently you can fill the insertion data:
rust
crate::yavom::myersfill(&b, &mut moves);
```
This code is Copyright (C) 2022 Amos Brocco (contact@amosbrocco.ch)
BSD 3-Clause License