Ejemplo n.º 1
0
        public StepSummary Step()
        {
            var summary = new StepSummary()
            {
                IsFinished = true,
                K          = k,
                I          = i,
                Matched    = true
            };

            if (i > n - m || k < 0)
            {
                return(summary);
            }

            if (_pattern[k].Equals(_word[i + k]))
            {
                k--;
            }
            else
            {
                // Bad character rule
                int bcx  = k - _rule.Offset(_word[i + k], k);
                int sgsx = delta2[k];
                int z    = k - (m - 1);
                int x    = Math.Max(bcx, sgsx);

                // Shift
                i += x;
                k -= z;

                summary.Matched = false;
                summary.Shift   = new Shift()
                {
                    Strategy = (sgsx > bcx) ? Strategy.StrongGoodSuffix : Strategy.BadCharacter,
                    IsLeft   = true,
                    X        = x,
                    Z        = z,
                    K        = k,
                    I        = i
                };
            }

            summary.IsFinished = false;
            return(summary);
        }
        public StepSummary Step()
        {
            var summary = new StepSummary()
            {
                IsFinished = true,
                K          = k,
                I          = i,
                Matched    = true
            };

            if (i > n - m || k < 0)
            {
                return(summary);
            }

            if (_pattern[k].Equals(_word[i + k]))
            {
                k--;
            }
            else
            {
                // Offset always calculated from the last character in pattern - BMH
                // Character to the right of the pattern must be included in matching, if given - BMHS
                int x = m - ((i + m < n) ? Offset(_word[i + m]) : 0);
                int z = k - (m - 1);

                // Shift
                i += x;
                k -= z;

                summary.Matched = false;
                summary.Shift   = new Shift()
                {
                    Strategy = Strategy.BadCharacter,
                    IsLeft   = true,
                    X        = x,
                    Z        = z,
                    K        = k,
                    I        = i
                };
            }

            summary.IsFinished = false;
            return(summary);
        }
        public StepSummary Step()
        {
            var summary = new StepSummary()
            {
                IsFinished = true,
                K          = k,
                I          = i,
                Matched    = true
            };

            if (i > n - m || k < 0)
            {
                return(summary);
            }

            if (_pattern[k].Equals(_word[i + k]))
            {
                k--;
            }
            else
            {
                // Offset always calculated from the last character in pattern
                int x = m - 1 - Offset(_word[i + m - 1]);
                int z = k - (m - 1);

                // Shift
                i += x;
                k -= z;

                summary.Matched = false;
                summary.Shift   = new Shift()
                {
                    Strategy = Strategy.BadCharacter,
                    IsLeft   = true,
                    X        = x,
                    Z        = z,
                    K        = k,
                    I        = i
                };
            }

            summary.IsFinished = false;
            return(summary);
        }
Ejemplo n.º 4
0
        public StepSummary Step()
        {
            var summary = new StepSummary()
            {
                IsFinished = true,
                K          = k,
                I          = i,
                Matched    = true
            };

            if (i > n - m || k == m)
            {
                return(summary);
            }

            if (_pattern[k].Equals(_word[i + k]))
            {
                k++;
            }
            else
            {
                int x = 1;
                int z = k;

                // Shift
                i += x;
                k -= z;

                summary.Matched = false;
                summary.Shift   = new Shift()
                {
                    Strategy = Strategy.Naive,
                    X        = x,
                    Z        = z,
                    K        = k,
                    I        = i
                };
            }

            summary.IsFinished = false;
            return(summary);
        }
        public StepSummary Step()
        {
            var summary = new StepSummary()
            {
                IsFinished = true,
                K          = k,
                I          = i,
                Matched    = true
            };

            if (i > n - m || k == m)
            {
                return(summary);
            }

            if (_pattern[k].Equals(_word[i + k]))
            {
                k++;
            }
            else
            {
                int x = i + (k - next[k]);
                int z = k - Math.Max(0, next[k]);
                i = x;
                k = k - z;

                summary.Matched = false;
                summary.Shift   = new Shift()
                {
                    Strategy = Strategy.KMP,
                    X        = x,
                    Z        = z,
                    K        = k,
                    I        = i
                };
            }

            summary.IsFinished = false;
            return(summary);
        }