Skip to content

Commit

Permalink
comment stuff?
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Oct 23, 2021
1 parent b0cf150 commit 54d63b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion BlueprintExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion BlueprintExplorer/FuzzyMatchContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ public class FuzzyMatchContext<T>
{
private static FuzzyMatchResult<T> FuzzyMatch(FuzzyMatchResult<T> 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)
Expand All @@ -72,27 +77,37 @@ private static FuzzyMatchResult<T> FuzzyMatch(FuzzyMatchResult<T> 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;
Expand Down

0 comments on commit 54d63b2

Please sign in to comment.