Skip to content

Commit

Permalink
fix tiny bug (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 29, 2023
1 parent 288c07d commit e3c25d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"fmt"

"github.com/JunNishimura/Goit/internal/diff"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +22,12 @@ var diffCmd = &cobra.Command{
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("diff called")
d := diff.NewDiff([]rune(args[0]), []rune(args[1]))

d.Compose()

fmt.Println(d.EditDistance)

return nil
},
}
Expand Down
7 changes: 4 additions & 3 deletions internal/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Diff struct {
lenTextLong int
lenTextShort int
isReversed bool
editDistance int
EditDistance int
}

func NewDiff(text1, text2 []rune) *Diff {
Expand Down Expand Up @@ -42,9 +42,10 @@ func (d *Diff) Compose() {
for k := delta + p; k > delta; k-- {
fp[k+offset] = d.snake(k, max(fp[k+offset-1]+1, fp[k+offset+1]))
}
fp[delta+offset] = d.snake(delta+offset, max(fp[delta+offset-1]+1, fp[delta+offset+1]))
fp[delta+offset] = d.snake(delta, max(fp[delta+offset-1]+1, fp[delta+offset+1]))
if fp[delta+offset] == d.lenTextLong {
d.editDistance = p
d.EditDistance = p
break
}
}
}
Expand Down

0 comments on commit e3c25d5

Please sign in to comment.