Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanHarltey committed Mar 25, 2024
1 parent d994a5e commit 35a574c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Fastenshtein/Levenshtein.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public int DistanceFrom5(string value)
return value.Length;
}

int previousCost = 1;
int previousCost = 0;

// Add indexing for insertion to first row
for (; previousCost < costs.Length;)
Expand Down Expand Up @@ -307,24 +307,21 @@ public int DistanceFrom(string value)
var costs = this.costs;
var storedValue = this.storedValue;
ref var storedValueRef = ref MemoryMarshal.GetReference(storedValue.AsSpan());

if (costs.Length == 0)
{
return value.Length;
}

int previousCost = 1;

// Add indexing for insertion to first row
int previousCost = 0;
ref var refCosts = ref MemoryMarshal.GetArrayDataReference(costs);
for (; previousCost <= costs.Length; previousCost++)
for (; previousCost < costs.Length;)
{
refCosts = previousCost;
refCosts = ++previousCost;
refCosts = ref Unsafe.Add(ref refCosts, 1);
}
refCosts = ref MemoryMarshal.GetArrayDataReference(costs);


for (int i = 0; i < value.Length; i++)
{
// cost of the first index
Expand Down

0 comments on commit 35a574c

Please sign in to comment.