Introduce the maximum_proximity helper function

This commit is contained in:
Kerollmops 2021-02-23 15:53:24 +01:00
parent 6008f528d0
commit 6d135beb21
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -524,6 +524,16 @@ pub fn maximum_typo(operation: &Operation) -> usize {
}
}
/// Returns the maximum proximity that this Operation allows.
pub fn maximum_proximity(operation: &Operation) -> usize {
use Operation::{Or, And, Query, Consecutive};
match operation {
Or(_, ops) => ops.iter().map(maximum_proximity).max().unwrap_or(0),
And(ops) => ops.len().saturating_sub(1) * 8,
Query(_) | Consecutive(_) => 0,
}
}
#[cfg(test)]
mod test {
use fst::Set;