1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Distance function bindings for WebAssembly.
use *;
use crate;
/// Calculate the Levenshtein distance between two strings.
///
/// The Levenshtein distance is the minimum number of single-character edits
/// (insertions, deletions, or substitutions) required to change one string
/// into another.
///
/// # Arguments
///
/// * `source` - The source string
/// * `target` - The target string
///
/// # Returns
///
/// The edit distance between the two strings.
///
/// # Example (JavaScript)
///
/// ```javascript
/// import { levenshtein } from 'liblevenshtein';
/// console.log(levenshtein("kitten", "sitting")); // 3
/// ```
/// Calculate the Levenshtein distance with early termination.
///
/// Returns the distance only if it's less than or equal to the threshold,
/// otherwise returns `null`. This is more efficient when you only care
/// about matches within a certain distance.
///
/// # Arguments
///
/// * `source` - The source string
/// * `target` - The target string
/// * `threshold` - Maximum distance to compute
///
/// # Returns
///
/// The distance if <= threshold, otherwise `null`.
/// Calculate the Damerau-Levenshtein distance between two strings.
///
/// The Damerau-Levenshtein distance extends Levenshtein by also allowing
/// transpositions (swapping two adjacent characters) as a single edit.
///
/// # Arguments
///
/// * `source` - The source string
/// * `target` - The target string
///
/// # Returns
///
/// The edit distance between the two strings.
///
/// # Example (JavaScript)
///
/// ```javascript
/// import { damerau_levenshtein } from 'liblevenshtein';
/// console.log(damerau_levenshtein("ab", "ba")); // 1 (transposition)
/// ```
/// Calculate the Damerau-Levenshtein distance with early termination.
///
/// # Arguments
///
/// * `source` - The source string
/// * `target` - The target string
/// * `threshold` - Maximum distance to compute
///
/// # Returns
///
/// The distance if <= threshold, otherwise `null`.
/// Calculate edit distances for multiple pairs in batch.
///
/// More efficient than calling `levenshtein` multiple times when you have
/// many pairs to compare.
///
/// # Arguments
///
/// * `pairs` - Array of [source, target] string pairs as a flat array
/// (e.g., ["a", "b", "c", "d"] for pairs (a,b) and (c,d))
///
/// # Returns
///
/// Array of distances corresponding to each pair.