示例#1
0
        public (int begin, int end) Find(string query)
        {
            var p = new StringView(query);
            int l = LowerBound(p, 0, CharacterCount);
            int u = UpperBound(p, 0, CharacterCount);

            return(l, u);
        }
示例#2
0
 private int LowerBound(StringView pattern, int start, int end)
 {
     while (start < end)
     {
         int mid    = start + (end - start) / 2;
         var suffix = GetSuffix(SA[mid], pattern.Length);
         if (Algorithm.LexicographicalCompare(suffix, pattern))
         {
             start = mid + 1;
         }
         else
         {
             end = mid;
         }
     }
     return(start);
 }
示例#3
0
        public static bool LexicographicalCompare(StringView a, StringView b)
        {
            int first1 = a.Offset;
            int first2 = b.Offset;
            int last1  = a.Offset + a.Length;
            int last2  = b.Offset + b.Length;

            while (first1 != last1)
            {
                if (first2 == last2 || b.AtAbsolute(first2) < a.AtAbsolute(first1))
                {
                    return(false);
                }
                if (a.AtAbsolute(first1) < b.AtAbsolute(first2))
                {
                    return(true);
                }
                ++first1;
                ++first2;
            }

            return(first2 != last2);
        }