mirror of
https://github.com/solaeus/nucleo.git
synced 2024-09-19 23:22:09 +00:00
becd35c5de
switch to a algorithm with two matrices (but optimized to have 1 matrix while tracking indices and just a single row if only scoring) that can be proven to always provide the optimal result (fzfs' v2 algorithm does not and can even produce wore results than its v1 algorithm). The algorithm is very similar to skim but still uses fzfs bonus system and is orders of magnitude faster (and falls back to fzfs greedy v1 algorithm which is actually surprisingly close to the optimal algorithm).
33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
use crate::matrix::{MatrixCell, ScoreCell};
|
|
use std::fmt::{Debug, Formatter, Result};
|
|
|
|
// impl<C: Char> MatcherData<'_, C> {
|
|
// pub fn rows(&self) -> impl Iterator<Item = MatrixRow> + ExactSizeIterator + Clone + Sized {
|
|
// let mut cells = &*self.cells;
|
|
// self.row_offs.iter().map(move |&off| {
|
|
// let len = self.haystack.len() - off as usize;
|
|
// let (row, tmp) = cells.split_at(len);
|
|
// cells = tmp;
|
|
// MatrixRow { off, cells: row }
|
|
// })
|
|
// }
|
|
|
|
// pub fn haystack(
|
|
// &self,
|
|
// ) -> impl Iterator<Item = HaystackChar<C>> + ExactSizeIterator + '_ + Clone {
|
|
// haystack(self.haystack, self.bonus, 0)
|
|
// }
|
|
// }
|
|
|
|
impl Debug for ScoreCell {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
|
write!(f, "({}, {}, {})", self.score, self.bonus, self.matched)
|
|
}
|
|
}
|
|
|
|
impl Debug for MatrixCell {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
|
write!(f, "({}, {})", (self.0 & 1) != 0, (self.0 & 2) != 0)
|
|
}
|
|
}
|