Ejemplo n.º 1
0
 public DecodingMatcherForVarLenCharEncoding(IDfaMatcher <char> matcher, VarLenCharEncoding encoding)
 {
     this.matcher      = matcher;
     this.encoding     = encoding;
     this.matcherSteps = new Stack <int>();
     Reset();
 }
        /// <summary>
        /// Match values in the tree
        /// </summary>
        public IEnumerable <IEnumerable <TKey> > Match(IDfaMatcher <TKey> matcher)
        {
            var prefix = new List <TKey>();
            var stack  = new Stack <KeyValuePair <int, bool> >();

            if (nodeManager.RootNodeId != NodeManager.NoId &&
                nodeManager.RootNodeId != NodeManager.NewId)
            {
                stack.Push(new KeyValuePair <int, bool>(nodeManager.RootNodeId, false));
            }

            while (stack.Count > 0)
            {
                var current = stack.Pop();
                if (current.Key == NodeManager.NoId)
                {
                    matcher.Pop();
                    prefix.RemoveAt(prefix.Count - 1);
                    continue;
                }

                var node = nodeManager.Get(current.Key);

                if (current.Value)
                {
                    matcher.Next(node.Split);
                    prefix.Add(node.Split);

                    if (node.IsFinal && matcher.IsFinal())
                    {
                        yield return(prefix);
                    }
                    continue;
                }

                if (node.Hikid != NodeManager.NoId)
                {
                    stack.Push(new KeyValuePair <int, bool>(node.Hikid, false));
                }

                if (matcher.Next(node.Split))
                {
                    matcher.Pop();

                    stack.Push(new KeyValuePair <int, bool>(NodeManager.NoId, false));

                    if (node.Eqkid != NodeManager.NoId)
                    {
                        stack.Push(new KeyValuePair <int, bool>(node.Eqkid, false));
                    }

                    stack.Push(new KeyValuePair <int, bool>(current.Key, true));
                }

                if (node.Lokid != NodeManager.NoId)
                {
                    stack.Push(new KeyValuePair <int, bool>(node.Lokid, false));
                }
            }
        }
Ejemplo n.º 3
0
 public DecodingMatcher(IDfaMatcher <char> matcher, int maxLength, ITextEncoding encoding)
 {
     this.matcher   = matcher;
     this.maxLength = maxLength;
     this.encoding  = encoding;
     this.data      = new byte[maxLength];
     this.dataIndex = 0;
 }
Ejemplo n.º 4
0
 public static bool IsMatch <T>(this IDfaMatcher <T> matcher, IEnumerable <T> word)
 {
     matcher.Reset();
     foreach (var c in word)
     {
         if (!matcher.Next(c))
         {
             return(false);
         }
     }
     return(matcher.IsFinal());
 }
 public DecodingMatcherForUTF8(IDfaMatcher <char> matcher, int maxLength)
 {
     this.matcher = matcher;
     this.stack   = new ValueTuple <int, int> [maxLength];
 }
Ejemplo n.º 6
0
 public IDfaMatcher <byte> CreateMatcher(IDfaMatcher <char> charMatcher, int maxLength)
 => encoding == Encoding.UTF8 ?
 (IDfaMatcher <byte>) new DecodingMatcherForUTF8(charMatcher, GetMaxEncodedLength(maxLength)) :
 (IDfaMatcher <byte>) new DecodingMatcher(charMatcher, GetMaxEncodedLength(maxLength), this);
Ejemplo n.º 7
0
 public IDfaMatcher <byte> CreateMatcher(IDfaMatcher <char> charMatcher, int maxLength)
 => (IDfaMatcher <byte>) new DecodingMatcherForVarLenCharEncoding(charMatcher, encoding);
Ejemplo n.º 8
0
 public DfaTermMatcher(IDfaMatcher <char> matcher)
 {
     this.matcher = matcher;
 }