Improve StringMatchCandidate::new interface (#22011)

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2024-12-14 13:35:36 -07:00 committed by GitHub
parent 9daa426e93
commit 25970650a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 92 additions and 184 deletions

View file

@ -18,22 +18,12 @@ pub struct StringMatchCandidate {
pub char_bag: CharBag,
}
impl Match for StringMatch {
fn score(&self) -> f64 {
self.score
}
fn set_positions(&mut self, positions: Vec<usize>) {
self.positions = positions;
}
}
impl StringMatchCandidate {
pub fn new(id: usize, string: String) -> Self {
pub fn new(id: usize, string: &str) -> Self {
Self {
id,
char_bag: CharBag::from(string.as_str()),
string,
string: string.into(),
char_bag: string.into(),
}
}
}
@ -56,6 +46,16 @@ pub struct StringMatch {
pub string: String,
}
impl Match for StringMatch {
fn score(&self) -> f64 {
self.score
}
fn set_positions(&mut self, positions: Vec<usize>) {
self.positions = positions;
}
}
impl StringMatch {
pub fn ranges(&self) -> impl '_ + Iterator<Item = Range<usize>> {
let mut positions = self.positions.iter().peekable();