Skip to content

Commit

Permalink
Merge pull request #96 from kzrnm/feature/sa
Browse files Browse the repository at this point in the history
Add SuffixArray test
  • Loading branch information
kzrnm authored Jan 24, 2023
2 parents d162b45 + cdf8545 commit 15ba366
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/ac-library-csharp/String/StringLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public static int[] SaIs(ReadOnlySpan<int> s, int upper, int thresholdNaive, int
Induce(lms, s, sa, ls, sumS, sumL);

// LMSを再帰的にソート
// m の値は再帰ごとに半分以下になるので再帰の回数も log(n) に抑えられる
if (m > 0)
{
var sortedLms = new SimpleList<int>(m);
Expand Down
22 changes: 21 additions & 1 deletion Test/ac-library-csharp.Test/String/StringLibTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void SAAllABTest()
}
}
[Fact]
public void SA()
public void SuffixArray()
{
var s = "missisippi";

Expand All @@ -296,6 +296,26 @@ public void SA()
s[sa[i]..].Should().Be(answer[i]);
}
}
[Fact]
public void SuffixArrayInt()
{
int[] s, sa;
s = Enumerable.Range(0, 500000).SelectMany(i => new[] { i, ~i }).ToArray();
sa = StringLib.SuffixArray(s);
sa.Should().Equal(
Enumerable.Range(0, 500000).Select(i => 999999 - 2 * i).Concat(
Enumerable.Range(0, 500000).Select(i => 2 * i))
);

s = Enumerable.Range(0, 1000000).ToArray();
sa = StringLib.SuffixArray(s);
sa.Should().Equal(s);

s = Enumerable.Range(0, 1000000).Reverse().ToArray();
sa = StringLib.SuffixArray(s);
sa.Should().Equal(s);
}

[Fact]
public void SASingle()
{
Expand Down

0 comments on commit 15ba366

Please sign in to comment.