MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / similarityScore

Function similarityScore

app/src/API/CommandRegistry.cpp:68–84  ·  view source on GitHub ↗

* @brief Lower-is-better score: prefers names sharing the dotted prefix. */

Source from the content-addressed store, hash-verified

66 * @brief Lower-is-better score: prefers names sharing the dotted prefix.
67 */
68static int similarityScore(const QString& want, const QString& have)
69{
70 const auto wantParts = want.split(QLatin1Char('.'));
71 const auto haveParts = have.split(QLatin1Char('.'));
72
73 int sharedSegments = 0;
74 const int minSeg = std::min(wantParts.size(), haveParts.size());
75 for (int i = 0; i < minSeg; ++i)
76 if (wantParts[i].compare(haveParts[i], Qt::CaseInsensitive) == 0)
77 sharedSegments += 1;
78 else
79 break;
80
81 const int dist = editDistance(want, have);
82
83 return dist - (sharedSegments * 6);
84}
85
86//--------------------------------------------------------------------------------------------------
87// Singleton access

Callers 1

Calls 3

editDistanceFunction · 0.85
sizeMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected