Skip to content

Commit e4d6cfd

Browse files
neurlangYour Name
authored and
Your Name
committed
explain the algo more
1 parent a5787a8 commit e4d6cfd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

matrix.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package levenshtein
33

44
// 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)
56
type Number interface {
67
int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64 | int | uint | float32 | float64
78
}
@@ -14,7 +15,8 @@ func One[T Number](uint) *T {
1415
}
1516

1617
// 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.
1820
func Distance[T any](d []T) *T {
1921
if len(d) == 0 {
2022
return nil
@@ -26,6 +28,7 @@ func Distance[T any](d []T) *T {
2628
// the substitution cost between two comparable slices.
2729
// The substitution cost is none if the slice elements are the same, and One if
2830
// the slice elements are not equal.
31+
// You can implement something like this to customize the substitution cost used by the slices algorithm.
2932
func OneSlice[C comparable, T Number](a, b []C) func(uint, uint) *T {
3033
return func(x, y uint) *T {
3134
if a[x] == b[y] {
@@ -41,6 +44,7 @@ func OneSlice[C comparable, T Number](a, b []C) func(uint, uint) *T {
4144
// the substitution cost between two comparable elements.
4245
// The substitution cost is none if the slice elements are the same, and One if
4346
// 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.
4448
func OneElements[C comparable, T Number](a *C, b *C) *T {
4549
if *a == *b {
4650
return (*T)(nil)
@@ -54,6 +58,7 @@ func OneElements[C comparable, T Number](a *C, b *C) *T {
5458
// the substitution cost between two strings.
5559
// The substitution cost is none if the string bytes are the same, and One if
5660
// the string bytes are not equal.
61+
// You can implement something like this to customize the substitution cost used by the strings algorithm.
5762
func OneString[T Number](a, b string) func(uint, uint) *T {
5863
return func(x, y uint) *T {
5964
if a[x] == b[y] {
@@ -65,7 +70,7 @@ func OneString[T Number](a, b string) func(uint, uint) *T {
6570
}
6671
}
6772

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.
6974
func Kernel[T Number](d []T, i uint, j uint, n uint, cost *T, delCost *T, insCost *T) {
7075

7176
// Calculate deletion, insertion, and substitution costs

0 commit comments

Comments
 (0)