MCPcopy Create free account
hub / github.com/sergi/go-diff / matchBitapScore

Method matchBitapScore

diffmatchpatch/match.go:128–140  ·  view source on GitHub ↗

matchBitapScore computes and returns the score for a match with e errors and x location.

(e, x, loc int, pattern string)

Source from the content-addressed store, hash-verified

126
127// matchBitapScore computes and returns the score for a match with e errors and x location.
128func (dmp *DiffMatchPatch) matchBitapScore(e, x, loc int, pattern string) float64 {
129 accuracy := float64(e) / float64(len(pattern))
130 proximity := math.Abs(float64(loc - x))
131 if dmp.MatchDistance == 0 {
132 // Dodge divide by zero error.
133 if proximity == 0 {
134 return accuracy
135 }
136
137 return 1.0
138 }
139 return accuracy + (proximity / float64(dmp.MatchDistance))
140}
141
142// MatchAlphabet initialises the alphabet for the Bitap algorithm.
143func (dmp *DiffMatchPatch) MatchAlphabet(pattern string) map[byte]int {

Callers 1

MatchBitapMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected