Fix crashing when source or target array empty
This commit is contained in:
parent
cfaa94f08e
commit
a88dee4c4b
@ -80,6 +80,7 @@ enum LevenshteinTransformations {
|
||||
operations[0][targetIndex] = .insert
|
||||
}
|
||||
|
||||
if sourceCount > 0 && targetCount > 0 {
|
||||
for sourceIndex in 1...sourceCount {
|
||||
for targetIndex in 1...targetCount {
|
||||
if source[sourceIndex - 1] == target[targetIndex - 1] {
|
||||
@ -91,7 +92,8 @@ enum LevenshteinTransformations {
|
||||
editDistances[sourceIndex - 1][targetIndex],
|
||||
editDistances[sourceIndex][targetIndex - 1]
|
||||
)
|
||||
if editDistances[sourceIndex][targetIndex] == editDistances[sourceIndex - 1][targetIndex - 1] + 1 {
|
||||
if editDistances[sourceIndex][targetIndex]
|
||||
== editDistances[sourceIndex - 1][targetIndex - 1] + 1 {
|
||||
operations[sourceIndex][targetIndex] = .replace
|
||||
} else if editDistances[sourceIndex][targetIndex]
|
||||
== editDistances[sourceIndex - 1][targetIndex] + 1 {
|
||||
@ -103,6 +105,7 @@ enum LevenshteinTransformations {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The transformation function for arrays with identifiable elements.
|
||||
/// - Parameters:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user