sort of a gui

This commit is contained in:
senstella
2025-10-09 00:41:58 +09:00
parent 02ef2098b3
commit 61216c1044
8 changed files with 594 additions and 531 deletions

View File

@@ -1,4 +1,4 @@
use seal::pair::{AlignmentSet, InMemoryAlignmentMatrix, SmithWaterman, Step};
use seal::pair::{AlignmentSet, MemoryMappedAlignmentMatrix, SmithWaterman, Step};
pub fn match_lines(code: &str, start: &str, end: &str) -> Option<(usize, usize)> {
let code_chars: Vec<char> = code.chars().collect();
@@ -11,7 +11,7 @@ pub fn match_lines(code: &str, start: &str, end: &str) -> Option<(usize, usize)>
if start.ends_with(end) {
let pattern_chars: Vec<char> = start.chars().collect();
let set: AlignmentSet<InMemoryAlignmentMatrix> =
let set: AlignmentSet<MemoryMappedAlignmentMatrix> =
AlignmentSet::new(code_chars.len(), pattern_chars.len(), strategy, |x, y| {
code_chars[x] == pattern_chars[y]
})
@@ -39,7 +39,7 @@ pub fn match_lines(code: &str, start: &str, end: &str) -> Option<(usize, usize)>
Some((start_line, end_line))
} else {
let start_chars: Vec<char> = start.chars().collect();
let start_set: AlignmentSet<InMemoryAlignmentMatrix> = AlignmentSet::new(
let start_set: AlignmentSet<MemoryMappedAlignmentMatrix> = AlignmentSet::new(
code_chars.len(),
start_chars.len(),
strategy.clone(),
@@ -61,27 +61,31 @@ pub fn match_lines(code: &str, start: &str, end: &str) -> Option<(usize, usize)>
let end_chars: Vec<char> = end.chars().collect();
let remaining_code: Vec<char> = code_chars[start_char_pos..].to_vec();
let end_set: AlignmentSet<InMemoryAlignmentMatrix> =
let end_set: AlignmentSet<MemoryMappedAlignmentMatrix> =
AlignmentSet::new(remaining_code.len(), end_chars.len(), strategy, |x, y| {
remaining_code[x] == end_chars[y]
})
.ok()?;
let end_alignment = end_set.local_alignments().next().unwrap();
let end_char_pos_relative = end_alignment
.steps()
.filter_map(|step| {
if let Step::Align { x, .. } = step {
Some(x)
} else {
None
}
let end_char_pos_relative = end_set
.local_alignments()
.filter_map(|end_alignment| {
end_alignment
.steps()
.filter_map(|step| {
if let Step::Align { x, .. } = step {
Some(x)
} else {
None
}
})
.last()
})
.last()?;
.min()?;
let end_char_pos = start_char_pos + end_char_pos_relative;
let start_line = code[..start_char_pos].lines().count().saturating_sub(1);
let start_line = code[..=start_char_pos].lines().count().saturating_sub(1);
let end_line = code[..=end_char_pos].lines().count().saturating_sub(1);
Some((start_line, end_line))