From 54d63b26ee81d956132b47f86cf4ea6f5b36682c Mon Sep 17 00:00:00 2001 From: factubsio <65080026+factubsio@users.noreply.github.com> Date: Sat, 23 Oct 2021 13:58:46 +0100 Subject: [PATCH] comment stuff? --- BlueprintExplorer.sln | 7 ++++++- BlueprintExplorer/FuzzyMatchContext.cs | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/BlueprintExplorer.sln b/BlueprintExplorer.sln index dff0cd8..7977d8c 100644 --- a/BlueprintExplorer.sln +++ b/BlueprintExplorer.sln @@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.31702.278 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueprintExplorer", "BlueprintExplorer\BlueprintExplorer.csproj", "{58D00E53-3261-4087-9A83-E6B636F8D093}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueprintExplorer", "BlueprintExplorer\BlueprintExplorer.csproj", "{58D00E53-3261-4087-9A83-E6B636F8D093}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0B594754-77CD-420A-9BE8-9E626166436E}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BlueprintExplorer/FuzzyMatchContext.cs b/BlueprintExplorer/FuzzyMatchContext.cs index 933b6a4..8da7848 100644 --- a/BlueprintExplorer/FuzzyMatchContext.cs +++ b/BlueprintExplorer/FuzzyMatchContext.cs @@ -52,16 +52,21 @@ public class FuzzyMatchContext { private static FuzzyMatchResult FuzzyMatch(FuzzyMatchResult result) { + //eye indexes needle, thread indexes haystack. int eye = 0; int thread = -1; var needle = result.Context.Needle; var haystack = result.Haystack; + //find a common prefix if any, so n:cat h:catsgrace is better than n:cat h:blahcatsgrace thread = haystack.IndexOf(needle[eye]); if (thread == 0) result.Bonus = 2.0f; + //penalise matches that don't have a common prefix, while increasing eye(needle) and thread(haystack) to the first match, so: + //n:bOb h:hellOworldbob + // ^ ^ while (thread == -1 && eye < needle.Length) { if (eye == 0) @@ -72,27 +77,37 @@ private static FuzzyMatchResult FuzzyMatch(FuzzyMatchResult result) eye++; } + //Continue to match the next eye(needle) greedily to haystack while (eye < needle.Length) { + + //find the next point in haystack that matches our eye: + //n:bOb h:helloworldBob + // ^ ^ thread = haystack.IndexOf(needle[eye], thread); if (thread == -1) break; + + //continue matching while both are in sync MatchSpan span = new MatchSpan(thread); while (thread < haystack.Length && eye < needle.Length && needle[eye] == haystack[thread]) { + //if this span is rooted at the start of the word give a bonus because start is most importatn if (span.From == 0 && eye > 0) result.Bonus += result.Bonus; eye++; thread++; } + //record the end of the span span.End(thread); result.matches.Add(span); + + //update some stats that get used for scoring if (span.Length > result.BestRun) result.BestRun = span.Length; if (span.Length == 1) result.SingleRuns++; - result.TotalMatched += span.Length; } result.HaystackMatched = result.TotalMatched / (float)haystack.Length;