Debian Codegraph @

src/align.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#;
3
4 const DELETION_COSTrust-analyzer cargo git-delta 0.19.2 align/DELETION_COST.: usize = 2;
5 const INSERTION_COSTrust-analyzer cargo git-delta 0.19.2 align/INSERTION_COST.: usize = 2;
6 // extra cost for starting a new group of changed tokens
7 const INITIAL_MISMATCH_PENALTYrust-analyzer cargo git-delta 0.19.2 align/INITIAL_MISMATCH_PENALTY.: usize = 1;
8
9 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
10 pub enum Operationrust-analyzer cargo git-delta 0.19.2 align/Operation# {
11 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#,
12 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#,
13 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#,
14 }
15
16 use Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#::*;
17
18 /// Needleman-Wunsch / Wagner-Fischer table for computation of edit distance and associated
19 /// alignment.
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
21 struct Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
22 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: usize,
23 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#,
24 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: usize,
25 }
26
27 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
28 pub struct Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#<'a> {
29 pub xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'a str>,
30 pub yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'a str>,
31 tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Cellrust-analyzer cargo git-delta 0.19.2 align/Cell#>,
32 dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.: [usize; 2],
33 }
34
35 impl<'a> Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#<'a> {
36 /// Fill table for Levenshtein distance / alignment computation
37 pub fn newrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]new().(x: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'a str>, y: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&'a str>) -> Selfrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`] {
38 // TODO: Something downstream of the alignment algorithm requires that the first token in
39 // both x and y is "", so this is explicitly inserted in `tokenize()`.
40 let dim = [y.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, x.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1];
41 let table = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
42 Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
43 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: 0,
44 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#,
45 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: 0
46 };
47 dim[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). dim[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
48 ];
49 let mut alignment = Selfrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`] { xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x., yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y., tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table., dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim. };
50 alignment.fillrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]fill().();
51 alignment
52 }
53
54 /// Fill table for Levenshtein distance / alignment computation
55 pub fn fillrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]fill().(&mut self) {
56 // x is written along the top of the table; y is written down the left side of the
57 // table. Also, we insert a 0 in cell (0, 0) of the table, so x and y are shifted by one
58 // position. Therefore, the element corresponding to (x[i], y[j]) is in column (i + 1) and
59 // row (j + 1); the index of this element is given by index(i, j).
60 for i in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
61 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
62 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: 0,
63 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#,
64 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().DELETION_COSTrust-analyzer cargo git-delta 0.19.2 align/DELETION_COST. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().INITIAL_MISMATCH_PENALTYrust-analyzer cargo git-delta 0.19.2 align/INITIAL_MISMATCH_PENALTY.,
65 };
66 }
67 for j in 1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
68 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
69 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: 0,
70 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#,
71 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().INSERTION_COSTrust-analyzer cargo git-delta 0.19.2 align/INSERTION_COST. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().INITIAL_MISMATCH_PENALTYrust-analyzer cargo git-delta 0.19.2 align/INITIAL_MISMATCH_PENALTY.,
72 };
73 }
74
75 for (i, x_i) in self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
76 for (j, y_j) in self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
77 let (left, diag, up) =
78 (self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(i, j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1), self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(i, j), self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, j));
79 // The order of the candidates matters if two of them have the
80 // same cost as in that case we choose the first one. Consider
81 // insertions and deletions before matches in order to group
82 // changes together. Insertions are preferred to deletions in
83 // order to highlight moved tokens as a deletion followed by an
84 // insertion (as the edit sequence is read backwards we need to
85 // choose the insertion first)
86 let candidates = [
87 Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
88 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: up,
89 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#,
90 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: self.mismatch_costrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]mismatch_cost().(up, INSERTION_COSTrust-analyzer cargo git-delta 0.19.2 align/INSERTION_COST.),
91 },
92 Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
93 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: left,
94 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#,
95 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: self.mismatch_costrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]mismatch_cost().(left, DELETION_COSTrust-analyzer cargo git-delta 0.19.2 align/DELETION_COST.),
96 },
97 Cellrust-analyzer cargo git-delta 0.19.2 align/Cell# {
98 parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.: diag,
99 operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.: NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#,
100 costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.: if x_i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().y_j {
101 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().diag]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.
102 } else {
103 usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.
104 },
105 },
106 ];
107 let index = self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1);
108 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = candidates
109 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
110 .min_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#min_by_key().(|cell| cell.costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.)
111 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
112 .clonerust-analyzer cargo git-delta 0.19.2 align/impl#[Cell][Clone]clone().();
113 }
114 }
115 }
116
117 fn mismatch_costrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]mismatch_cost().(&self, parent: usize, basic_cost: usize) -> usize {
118 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().parent]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.
119 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().basic_cost
120 +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().if self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().parent]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation. rust-analyzer cargo git-delta 0.19.2 align/impl#[Operation][`PartialEq<Self>`]eq().==rust-analyzer cargo git-delta 0.19.2 align/impl#[Operation][`PartialEq<Self>`]eq(). rust-analyzer cargo git-delta 0.19.2 align/impl#[Operation][`PartialEq<Self>`]eq().NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp# {
121 INITIAL_MISMATCH_PENALTYrust-analyzer cargo git-delta 0.19.2 align/INITIAL_MISMATCH_PENALTY.
122 } else {
123 0
124 }
125 }
126
127 /// Read edit operations from the table.
128 pub fn operationsrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]operations().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#> {
129 let mut ops = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]with_capacity().(maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()));
130 let mut cell = &self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().())]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
131 loop {
132 ops.push_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_front().(cell.operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation.);
133 if cell.parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
134 break;
135 }
136 cell = &self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().cell.parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
137 }
138 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`Vec<T, A>`][`From<VecDeque<T, A>>`]from().(ops)
139 }
140
141 pub fn coalesced_operationsrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]coalesced_operations().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#, usize)> {
142 run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().(self.operationsrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]operations().())
143 }
144
145 // Row-major storage of 2D array.
146 fn indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(&self, i: usize, j: usize) -> usize {
147 j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().i
148 }
149 }
150
151 fn run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().<T>(sequence: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<T>) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(T, usize)>
152 where
153 T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#,
154 T: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#,
155 {
156 let mut encoded = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(sequence.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
157
158 if sequence.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
159 return encoded;
160 }
161
162 let end = sequence.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().();
163 let (mut i, mut j) = (0, 1);
164 let mut curr = &sequence[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
165 loop {
166 if j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().end || sequence[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().j]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().curr {
167 encoded.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().curr, j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().i));
168 if j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().end {
169 return encoded;
170 } else {
171 curr = &sequence[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().j]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
172 i = j;
173 }
174 }
175 j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
176 }
177 }
178
179 #[cfg(test)]
180 mod testsrust-analyzer cargo git-delta 0.19.2 align/tests/ {
181 use superrust-analyzer cargo git-delta 0.19.2 align/::*;
182
183 use unicode_segmentationrust-analyzer cargo unicode-segmentation 1.12.0 crate/::UnicodeSegmentationrust-analyzer cargo unicode-segmentation 1.12.0 UnicodeSegmentation#;
184
185 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
186 fn test_run_length_encoderust-analyzer cargo git-delta 0.19.2 align/tests/test_run_length_encode().() {
187 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().::<usize>(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
188 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0]), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 1)]);
189 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["0", "0"]), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![("0", 2)]);
190 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
191 run_length_encoderust-analyzer cargo git-delta 0.19.2 align/run_length_encode().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0, 0, 1, 2, 2, 2, 3, 4, 4, 4]),
192 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![(0, 2), (1, 1), (2, 3), (3, 1), (4, 3)]
193 );
194 }
195
196 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
197 fn test_0rust-analyzer cargo git-delta 0.19.2 align/tests/test_0().() {
198 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
199 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "aaa",
200 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "aba",
201 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 5,
202 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (2, 4),
203 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#],
204 }
205 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
206 }
207
208 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
209 fn test_0_nonasciirust-analyzer cargo git-delta 0.19.2 align/tests/test_0_nonascii().() {
210 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
211 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "ááb",
212 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "áaa",
213 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 9,
214 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (4, 5),
215 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#],
216 }
217 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
218 }
219
220 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
221 fn test_1rust-analyzer cargo git-delta 0.19.2 align/tests/test_1().() {
222 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
223 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "kitten",
224 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "sitting",
225 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 13,
226 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (5, 9),
227 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
228 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // K -
229 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - S
230 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // I I
231 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // T T
232 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // T T
233 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // E -
234 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - I
235 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // N N
236 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - G
237 ],
238 }
239 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
240 }
241
242 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
243 fn test_2rust-analyzer cargo git-delta 0.19.2 align/tests/test_2().() {
244 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
245 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "saturday",
246 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "sunday",
247 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 10,
248 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (4, 9),
249 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
250 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // S S
251 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // A -
252 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // T -
253 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // U U
254 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // R -
255 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - N
256 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // D D
257 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // A A
258 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // Y Y
259 ],
260 }
261 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
262 }
263
264 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
265 fn test_3rust-analyzer cargo git-delta 0.19.2 align/tests/test_3().() {
266 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
267 // Prefer [Deletion NoOp Insertion] over [Insertion NoOp Deletion]
268 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "ab",
269 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "ba",
270 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 6,
271 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (2, 3),
272 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
273 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // a -
274 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // b b
275 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - a
276 ],
277 }
278 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
279 }
280
281 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
282 fn test_4rust-analyzer cargo git-delta 0.19.2 align/tests/test_4().() {
283 // Deletions are grouped together.
284 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
285 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "AABB",
286 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "AB",
287 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 5,
288 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (2, 4),
289 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
290 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // A A
291 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // A -
292 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // B -
293 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // B B
294 ],
295 }
296 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
297 }
298
299 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
300 fn test_5rust-analyzer cargo git-delta 0.19.2 align/tests/test_5().() {
301 // Insertions are grouped together.
302 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
303 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "AB",
304 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "AABB",
305 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 5,
306 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (2, 4),
307 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
308 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // A A
309 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - A
310 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - B
311 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // B B
312 ],
313 }
314 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
315 }
316
317 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
318 fn test_6rust-analyzer cargo git-delta 0.19.2 align/tests/test_6().() {
319 // Insertion and Deletion are grouped together.
320 TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase# {
321 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: "AAABBB",
322 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: "ACB",
323 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: 11,
324 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (5, 7),
325 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
326 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // A A
327 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // A -
328 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // A -
329 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // B -
330 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion#, // B -
331 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion#, // - C
332 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp#, // B B
333 ],
334 }
335 .runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().();
336 }
337
338 struct TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#<'a> {
339 beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.: &'a str,
340 afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.: &'a str,
341 distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.: usize,
342 partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.: (usize, usize),
343 operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#>,
344 }
345
346 impl<'a> TestCaserust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#<'a> {
347 pub fn runrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]run().(&self) {
348 self.assert_string_distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]assert_string_distance_parts().();
349 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(operationsrust-analyzer cargo git-delta 0.19.2 align/tests/operations().(self.beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before., self.afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.), self.operationsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#operations.);
350 }
351
352 fn assert_string_distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]assert_string_distance_parts().(&self) {
353 self.assert_string_levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]assert_string_levenshtein_distance().();
354 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(string_distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/string_distance_parts().(self.beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before., self.afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.), self.partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.);
355 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(string_distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/string_distance_parts().(self.afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after., self.beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.), self.partsrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#parts.);
356 }
357
358 fn assert_string_levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`TestCase<'a>`]assert_string_levenshtein_distance().(&self) {
359 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
360 string_levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/string_levenshtein_distance().(self.beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before., self.afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after.),
361 self.distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.
362 );
363 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
364 string_levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/string_levenshtein_distance().(self.afterrust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#after., self.beforerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#before.),
365 self.distancerust-analyzer cargo git-delta 0.19.2 align/tests/TestCase#distance.
366 );
367 }
368 }
369
370 fn string_distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/string_distance_parts().(x: &str, y: &str) -> (usize, usize) {
371 let (x, y) = (
372 x.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
373 y.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
374 );
375 Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#::newrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]new().(x, y).distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]distance_parts().()
376 }
377
378 fn string_levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/string_levenshtein_distance().(x: &str, y: &str) -> usize {
379 let (x, y) = (
380 x.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
381 y.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
382 );
383 Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#::newrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]new().(x, y).levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]levenshtein_distance().()
384 }
385
386 fn operationsrust-analyzer cargo git-delta 0.19.2 align/tests/operations().<'a>(x: &'a str, y: &'a str) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Operationrust-analyzer cargo git-delta 0.19.2 align/Operation#> {
387 let (x, y) = (
388 x.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
389 y.graphemesrust-analyzer cargo unicode-segmentation 1.12.0 impl#[str][UnicodeSegmentation]graphemes().(true).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>(),
390 );
391 Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#::newrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]new().(x, y).operationsrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]operations().()
392 }
393
394 impl<'a> Alignmentrust-analyzer cargo git-delta 0.19.2 align/Alignment#<'a> {
395 pub fn distance_partsrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]distance_parts().(&self) -> (usize, usize) {
396 let (mut numer, mut denom) = (0, 0);
397 for op in self.operationsrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]operations().() {
398 if op rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp# {
399 numer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
400 }
401 denom rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
402 }
403 (numer, denom)
404 }
405
406 /// Compute levenshtein distance from the filled table.
407 pub fn levenshtein_distancerust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]levenshtein_distance().(&self) -> usize {
408 self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().())]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.
409 }
410
411 #[allow(dead_code)]
412 fn format_cellrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]format_cell().(&self, cell: &Cellrust-analyzer cargo git-delta 0.19.2 align/Cell#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
413 let parent = &self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().cell.parentrust-analyzer cargo git-delta 0.19.2 align/Cell#parent.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
414 let op = match cell.operationrust-analyzer cargo git-delta 0.19.2 align/Cell#operation. {
415 Deletionrust-analyzer cargo git-delta 0.19.2 align/Operation#Deletion# => "-",
416 Insertionrust-analyzer cargo git-delta 0.19.2 align/Operation#Insertion# => "+",
417 NoOprust-analyzer cargo git-delta 0.19.2 align/Operation#NoOp# => ".",
418 };
419 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}{}", parent.costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost., op, cell.costrust-analyzer cargo git-delta 0.19.2 align/Cell#cost.)
420 }
421
422 #[allow(dead_code)]
423 fn printrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]print().(&self) {
424 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("x: {:?}", self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x.);
425 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("y: {:?}", self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y.);
426 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
427 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!(" ");
428 for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
429 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{} ", if j >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0 { self.xrust-analyzer cargo git-delta 0.19.2 align/Alignment#x.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().j -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). } else { " " })
430 }
431 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
432
433 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
434 for j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.dimrust-analyzer cargo git-delta 0.19.2 align/Alignment#dim.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). {
435 if j rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
436 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{} ", if i >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0 { self.yrust-analyzer cargo git-delta 0.19.2 align/Alignment#y.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). } else { " " })
437 }
438 let cell = &self.tablerust-analyzer cargo git-delta 0.19.2 align/Alignment#table.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.indexrust-analyzer cargo git-delta 0.19.2 align/impl#[`Alignment<'a>`]index().(j, i)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
439 printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{} ", self.format_cellrust-analyzer cargo git-delta 0.19.2 align/tests/impl#[`Alignment<'a>`]format_cell().(cell));
440 }
441 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
442 }
443 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!();
444 }
445 }
446 }