Skip to content

Commit ea2ace3

Browse files
committed
Revert "wip maybeinf"
This reverts commit 3edf628.
1 parent 3edf628 commit ea2ace3

File tree

1 file changed

+10
-73
lines changed

1 file changed

+10
-73
lines changed

src/lib.rs

Lines changed: 10 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! based on Myers' algorithm.
33
#[cfg(test)]
44
mod tests;
5-
use std::cmp::Ordering;
65
use std::cmp::{max, min};
76
use std::collections::HashMap;
87
#[cfg(test)]
@@ -11,65 +10,14 @@ extern crate quickcheck;
1110
#[macro_use(quickcheck)]
1211
extern crate quickcheck_macros;
1312

14-
#[derive(Debug, Clone, Copy)]
15-
enum MaybeInf {
16-
INF,
17-
MINF,
18-
Value(usize),
19-
}
20-
use MaybeInf::*;
21-
22-
impl PartialEq for MaybeInf {
23-
fn eq(&self, other: &Self) -> bool {
24-
match (*self, *other) {
25-
(MaybeInf::Value(a), MaybeInf::Value(b)) => a.eq(&b),
26-
_ => false,
27-
}
28-
}
29-
}
30-
31-
impl PartialOrd for MaybeInf {
32-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
33-
match (*self, *other) {
34-
(Value(a), Value(b)) => a.partial_cmp(&b),
35-
(INF, INF) | (MINF, MINF) => None,
36-
(MINF, _) | (_, INF) => Some(Ordering::Less),
37-
(INF, _) | (_, MINF) => Some(Ordering::Greater),
38-
}
39-
}
40-
}
41-
use std::ops::{Add, Sub};
42-
impl Add for MaybeInf {
43-
type Output = Self;
44-
fn add(self, rhs: Self) -> Self::Output {
45-
match (self, rhs) {
46-
(Value(a), Value(b)) => Value(a + b),
47-
(INF, MINF) | (MINF, INF) => unreachable!(),
48-
(INF, _) => INF,
49-
(MINF, _) => MINF,
50-
}
51-
}
52-
}
53-
impl Sub for MaybeInf {
54-
type Output = Self;
55-
fn sub(self, rhs: Self) -> Self::Output {
56-
match (self, rhs) {
57-
(Value(a), Value(b)) => Value(a - b),
58-
(INF, INF) | (MINF, MINF) => unreachable!(),
59-
(INF, _) => INF,
60-
(MINF, _) => MINF,
61-
}
62-
}
63-
}
64-
6513
struct Difference<'a, X, Y> {
6614
xv: &'a [X],
6715
yv: &'a [Y],
6816

6917
// working memory for forward path
70-
vf: Vec<MaybeInf>,
18+
vf: Vec<usize>,
7119
// working memory for backward path
72-
vb: Vec<MaybeInf>,
20+
vb: Vec<usize>,
7321
offset_d: i64,
7422
}
7523

@@ -80,8 +28,8 @@ where
8028
fn new(xv: &'a [X], yv: &'a [Y]) -> Self {
8129
let dmax = xv.len() + yv.len() + 1;
8230
let offset_d = yv.len() as i64;
83-
let vf = vec![MINF; dmax];
84-
let vb = vec![INF; dmax];
31+
let vf = vec![0usize; dmax];
32+
let vb = vec![!0usize; dmax];
8533
Self {
8634
xv,
8735
yv,
@@ -108,8 +56,8 @@ where
10856
move |k: i64| -> usize { (k + offset) as usize }
10957
};
11058

111-
self.vf[ktoi(kmidf)] = Value(xl);
112-
self.vb[ktoi(kmidb)] = Value(xr);
59+
self.vf[ktoi(kmidf)] = xl;
60+
self.vb[ktoi(kmidb)] = xr;
11361

11462
let mut kminf = kmidf;
11563
let mut kmaxf = kmidf;
@@ -125,15 +73,15 @@ where
12573
if kminf > kmin {
12674
kminf -= 1;
12775
if let Some(x) = self.vf.get_mut(ktoi(kminf - 1)) {
128-
*x = MINF
76+
*x = 0
12977
}
13078
} else {
13179
kminf += 1;
13280
}
13381
if kmaxf < kmax {
13482
kmaxf += 1;
13583
if let Some(x) = self.vf.get_mut(ktoi(kmaxf + 1)) {
136-
*x = MINF;
84+
*x = 0;
13785
}
13886
} else {
13987
kmaxf -= 1
@@ -143,22 +91,11 @@ where
14391
for k in (kminf..=kmaxf).step_by(2) {
14492
let ik = ktoi(k);
14593
let x = if d == 0 {
146-
Value(xl)
94+
xl
14795
} else {
14896
let lo = self.vf.get(ktoi(k - 1)).cloned();
14997
let hi = self.vf.get(ktoi(k + 1)).cloned();
150-
match (lo, hi) {
151-
(None, None) => unreachable!(),
152-
(Some(x), None) => x,
153-
(None, Some(x)) => x,
154-
(Some(lo), Some(hi)) => {
155-
if hi + Value(1) > lo {
156-
hi + Value(1)
157-
} else {
158-
lo
159-
}
160-
}
161-
}
98+
max(lo.map(|x| x + 1), hi).unwrap()
16299
};
163100
let y = gety(x, k);
164101
let mut u = x;

0 commit comments

Comments
 (0)