MCPcopy Create free account
hub / github.com/pmezard/go-difflib / Ratio

Method Ratio

difflib/difflib.go:465–471  ·  view source on GitHub ↗

Return a measure of the sequences' similarity (float in [0,1]). Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common. .Ratio() is expensive to compute i

()

Source from the content-addressed store, hash-verified

463// want to try .QuickRatio() or .RealQuickRation() first to get an
464// upper bound.
465func (m *SequenceMatcher) Ratio() float64 {
466 matches := 0
467 for _, m := range m.GetMatchingBlocks() {
468 matches += m.Size
469 }
470 return calculateRatio(matches, len(m.a)+len(m.b))
471}
472
473// Return an upper bound on ratio() relatively quickly.
474//

Callers 4

TestSequenceMatcherRatioFunction · 0.80
TestWithAsciiOneInsertFunction · 0.80
TestWithAsciiOnDeleteFunction · 0.80

Calls 2

GetMatchingBlocksMethod · 0.95
calculateRatioFunction · 0.85

Tested by 4

TestSequenceMatcherRatioFunction · 0.64
TestWithAsciiOneInsertFunction · 0.64
TestWithAsciiOnDeleteFunction · 0.64