Function triple_accel::levenshtein::levenshtein_simd_k_with_opts [−][src]
pub fn levenshtein_simd_k_with_opts(
a: &[u8],
b: &[u8],
k: u32,
trace_on: bool,
costs: EditCosts
) -> Option<(u32, Option<Vec<Edit>>)>
Expand description
Returns the Levenshtein distance, bounded by a cost threshold k
, between two strings and optionally,
the edit traceback, using SIMD acceleration, with extra options.
This will return None
if the Levenshtein distance between a
and b
is greater than the
threshold k
.
This should be much faster than levenshtein_naive_with_opts
and
levenshtein_naive_k_with_opts
.
Internally, this will automatically use AVX or SSE vectors with 8-bit, 16-bit, or 32-bit elements
to represent anti-diagonals in the dynamic programming matrix for calculating Levenshtein distance.
If AVX2 or SSE4.1 is not supported, then this will automatically fall back to
levenshtein_naive_k_with_opts
.
Arguments
a
- first string (slice)b
- second string (slice)k
- maximum number of cost allowed betweena
andb
trace_on
- whether to return the traceback, the sequence of edits betweena
andb
costs
-EditCosts
struct for the cost of each edit operation
Example
let dist = levenshtein_simd_k_with_opts(b"abc", b"ab", 1, true, LEVENSHTEIN_COSTS); assert!(dist.unwrap() == (1, Some(vec![Edit{edit: EditType::Match, count: 2}, Edit{edit: EditType::BGap, count: 1}])));