2
2
package levenshtein
3
3
4
4
// Number is the magnitude of the Levenshtein distance constraint
5
+ // (the type such as integer which can be used to express the difference between characters or the two compared slices elements)
5
6
type Number interface {
6
7
int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64 | int | uint | float32 | float64
7
8
}
@@ -14,7 +15,8 @@ func One[T Number](uint) *T {
14
15
}
15
16
16
17
// Distance returns the edit distance from the edit matrix (the last element),
17
- // or nil if the matrix is of size 0
18
+ // or nil if the matrix is of size 0. Used to figure out the Edit distance
19
+ // (how many minimum edits needed) from the matrix solved by Matrix.
18
20
func Distance [T any ](d []T ) * T {
19
21
if len (d ) == 0 {
20
22
return nil
@@ -26,6 +28,7 @@ func Distance[T any](d []T) *T {
26
28
// the substitution cost between two comparable slices.
27
29
// The substitution cost is none if the slice elements are the same, and One if
28
30
// the slice elements are not equal.
31
+ // You can implement something like this to customize the substitution cost used by the slices algorithm.
29
32
func OneSlice [C comparable , T Number ](a , b []C ) func (uint , uint ) * T {
30
33
return func (x , y uint ) * T {
31
34
if a [x ] == b [y ] {
@@ -41,6 +44,7 @@ func OneSlice[C comparable, T Number](a, b []C) func(uint, uint) *T {
41
44
// the substitution cost between two comparable elements.
42
45
// The substitution cost is none if the slice elements are the same, and One if
43
46
// the slice elements are not equal.
47
+ // You can implement something like this to customize the substitution cost used by the elements of slices algorithm.
44
48
func OneElements [C comparable , T Number ](a * C , b * C ) * T {
45
49
if * a == * b {
46
50
return (* T )(nil )
@@ -54,6 +58,7 @@ func OneElements[C comparable, T Number](a *C, b *C) *T {
54
58
// the substitution cost between two strings.
55
59
// The substitution cost is none if the string bytes are the same, and One if
56
60
// the string bytes are not equal.
61
+ // You can implement something like this to customize the substitution cost used by the strings algorithm.
57
62
func OneString [T Number ](a , b string ) func (uint , uint ) * T {
58
63
return func (x , y uint ) * T {
59
64
if a [x ] == b [y ] {
@@ -65,7 +70,7 @@ func OneString[T Number](a, b string) func(uint, uint) *T {
65
70
}
66
71
}
67
72
68
- // Kernel is the default Levenshtein algorithm kernel
73
+ // Kernel is the default Levenshtein algorithm kernel. You can customize the kernel to modify any costs or the algorithm calculation itself.
69
74
func Kernel [T Number ](d []T , i uint , j uint , n uint , cost * T , delCost * T , insCost * T ) {
70
75
71
76
// Calculate deletion, insertion, and substitution costs
0 commit comments