예제 #1
0
        public void SimpleSearch(SearchString str)
        {
            position = -1;
            long itoe = 0;

            for (int i = 0; i < str.Text.Length; i++)
            {
                if (str.Text[i] == str.SubText[0])
                {
                    for (int K = 0; K < str.SubText.Length && str.SubText[K] == str.Text[K + i]; K++)
                    {
                        itoe++;
                    }
                    if (itoe == str.SubText.Length)
                    {
                        position = i;
                        return;
                    }
                    itoe = 0;
                }
            }
        }
예제 #2
0
        public void BMSearch(SearchString str)
        {
            string text    = str.Text;
            string pattern = str.SubText;
            int    n       = text.Length;
            int    m       = pattern.Length;

            if (m > n)
            {
                position = -1;
            }

            int[] badShift   = BadCharactersTable(pattern);
            int[] goodSuffix = GoodSuffixTable(pattern);

            int offset = 0;

            while (offset <= n - m)
            {
                int i;
                for (i = m - 1; i >= 0 && pattern[i] == text[i + offset]; i--)
                {
                    ;
                }

                if (i < 0)
                {
                    position = offset;
                    return;
                }// Match found

                offset += Math.Max(i - badShift[(int)text[offset + i]], goodSuffix[i]);
            }

            position = -1;
        }
예제 #3
0
 public void InitializationSearchString(SearchString Str)
 {
     searchText.Text    = Str.Text;
     searchText.SubText = Str.SubText;
 }