flush
This commit is contained in:
1 parent
f874a15317
commit
9843797733
2 files changed
+12
-42
No files matched your search
@@ -108,44 +108,10 @@ pub fn lcs_gen_ms(str1: &str, str2: &str) -> Result<Vec<MonotonicSequence>, belp
|
|||||||
Ok(db)
|
Ok(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[allow(non_camel_case_types)]
|
#[allow(unused)]
|
||||||
// #[derive(Debug)]
|
pub fn lcs_traceback_vec(str1: &str, str2: &str, dp: Vec<Vec<u32>>) {
|
||||||
// pub enum belper {
|
todo!()
|
||||||
// DBE(DBError),
|
}
|
||||||
// None,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn lcs_gen_dbai(str1: &str, str2: &str) -> Result<Vec<DB2>, belper> {
|
|
||||||
// let c1: Vec<char> = str1.chars().collect();
|
|
||||||
// let c1len = c1.len();
|
|
||||||
// let c2: Vec<char> = str2.chars().collect();
|
|
||||||
// let c2len = c2.len();
|
|
||||||
// let mut db: Vec<DB2> = vec![DB2::with_len(c2len as u32 + 1); c1len + 1];
|
|
||||||
// if c1len * c2len == 0 {
|
|
||||||
// // for i in &db {
|
|
||||||
// // println!("{i:?}")
|
|
||||||
// // }
|
|
||||||
// return Ok(db);
|
|
||||||
// }
|
|
||||||
// for i in 1..=c1len {
|
|
||||||
// for j in 1..=c2len {
|
|
||||||
// if c1[i - 1] == c2[j - 1] {
|
|
||||||
// let val = db[i - 1].get(j as u32 - 1).ok_or(belper::None)? + 1;
|
|
||||||
// db[i].push(val).map_err(|c| belper::DBE(c))?;
|
|
||||||
// } else {
|
|
||||||
// let val = db[i]
|
|
||||||
// .get(j as u32 - 1)
|
|
||||||
// .ok_or(belper::None)?
|
|
||||||
// .max(db[i - 1].get(j as _).ok_or(belper::None)?);
|
|
||||||
// db[i].push(val).map_err(|c| belper::DBE(c))?;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // for i in &db {
|
|
||||||
// // println!("{i:?}")
|
|
||||||
// // }
|
|
||||||
// Ok(db)
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|||||||
@@ -211,11 +211,11 @@ impl MonotonicSequence {
|
|||||||
*ind += 1;
|
*ind += 1;
|
||||||
// if ind is self.length now then we need to pop
|
// if ind is self.length now then we need to pop
|
||||||
if *ind >= self.length {
|
if *ind >= self.length {
|
||||||
let re_moved = self.jumps.pop(); // its just moved (+ 1) also its removed
|
let _re_moved = self.jumps.pop(); // its just moved (+ 1) also its removed
|
||||||
// get it
|
// get it
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
if let Some(ind_and_val) = re_moved {
|
if let Some(ind_and_val) = _re_moved {
|
||||||
debug_assert_eq!(ind_and_val, (self.length, max))
|
debug_assert_eq!(ind_and_val, (self.length, max))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,9 +286,12 @@ impl MonotonicSequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate(&self) -> bool {
|
pub fn validate(&self) -> bool {
|
||||||
|
// self.jumps.is_sorted() no
|
||||||
self.jumps.windows(2).all(|c| {
|
self.jumps.windows(2).all(|c| {
|
||||||
let [(lind, lv), (tind, tv)] = *c else {
|
let [(lind, lv), (tind, tv)] = *c else {
|
||||||
unreachable!("windows is 2")
|
// unreachable!("windows is 2")
|
||||||
|
//1 or 0 items // also never reachable because of .all()
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
lind < tind && lv < tv
|
lind < tind && lv < tv
|
||||||
}) && self.jumps.iter().all(|&(ind, _)| ind < self.length)
|
}) && self.jumps.iter().all(|&(ind, _)| ind < self.length)
|
||||||
@@ -442,6 +445,7 @@ impl MonotonicSequence {
|
|||||||
self.length = len;
|
self.length = len;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn range2(&self, item: u32) -> Option<Range<usize>> {
|
pub fn range2(&self, item: u32) -> Option<Range<usize>> {
|
||||||
if self.is_empty() {
|
if self.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
Reference in new issue
Block a user