Example #1
0
        /// <summary>
        /// Searches for character match:
        ///   (1) If found, returns class-id
        ///   (2) Not found and doesn't intersect existing match: adds to matches and returns class-id
        ///   (3) Else: split existing matches & associated nfa-nodes, return new class-id
        /// </summary>
        /// <param name="end">Node from which to create transition</param>
        /// <param name="match">Match</param>
        /// <returns>Last match node</returns>
        public int GetClassId(char ch)
        {
            var match = new SingleChar(ch);

            if (!Matches.TryGet(match, out var keyId))
            {
                var matches = this.Matches.GetMatches();
                keyId = this.Matches.Add(match);

                foreach (var key in matches)
                {
                    if (key.IsMatch(ch))
                    {
                        var value = this.Matches[key];
                        var diff  = key.Difference(match);
                        this.Matches.Replace(key, diff, value);

                        var classToNode = classToNodes[value];
                        for (var i = 0; i < classToNode.Count; i++)
                        {
                            classToNode[i] = SplitNodeChar(classToNode[i], keyId);
                        }
                        break;
                    }
                }
            }
            return(keyId);
        }
Example #2
0
 public override bool Equals(object?obj)
 {
     return(obj switch
     {
         CharClass cc => Equals(cc),
         SingleChar sc => IsSingleChar(sc.Ch),
         _ => false
     });