public void InternalSAISNaive()
        {
            for (int n = 1; n <= 5; n++)
            {
                int m = 1;
                for (int i = 0; i < n; i++)
                {
                    m *= 4;
                }
                for (int f = 0; f < m; f++)
                {
                    var s     = new int[n];
                    int g     = f;
                    int max_c = 0;
                    for (int i = 0; i < n; i++)
                    {
                        s[i]  = g % 4;
                        max_c = Math.Max(max_c, s[i]);
                        g    /= 4;
                    }

                    var sa = InternalString.SAIS(s, max_c, -1, -1);
                    sa.Should().Equal(SaNaive(s));
                }
            }
            for (int n = 1; n <= 10; n++)
            {
                int m = 1;
                for (int i = 0; i < n; i++)
                {
                    m *= 2;
                }
                for (int f = 0; f < m; f++)
                {
                    var s     = new int[n];
                    int g     = f;
                    int max_c = 0;
                    for (int i = 0; i < n; i++)
                    {
                        s[i]  = g % 2;
                        max_c = Math.Max(max_c, s[i]);
                        g    /= 2;
                    }

                    var sa = InternalString.SAIS(s, max_c, -1, -1);
                    sa.Should().Equal(SaNaive(s));
                }
            }
        }
Exemplo n.º 2
0
        public static int[] SuffixArray <T>(ReadOnlySpan <T> s)
        {
            var idx = CreateIdx(s);
            var s2  = new int[s.Length];
            var now = 0;

            // 座標圧縮
            for (int i = 0; i < idx.Length; i++)
            {
                if (i > 0 && !EqualityComparer <T> .Default.Equals(s[idx[i - 1]], s[idx[i]]))
                {
                    now++;
                }
                s2[idx[i]] = now;
            }

            return(InternalString.SAIS(s2, now));
        }
Exemplo n.º 3
0
 public static int[] SuffixArray(int[] s, int upper)
 {
     Contract.Assert(0U <= (uint)upper, reason: $"{nameof(upper)} must be positive.");
     Contract.Assert(s.All(si => (uint)si <= (uint)upper), reason: $"si ∈ {nameof(s)} must be 0 <= si && si <= {nameof(upper)}");
     return(InternalString.SAIS(s, upper));
 }