Пример #1
0
        public static ICharSet Except(this ICharSet @this, ICharSet other)
        {
            var result = new CharSet(@this);

            result.Remove(other);
            return(result);
        }
Пример #2
0
 public static void Remove(this CharSet @this, ICharSet other)
 {
     foreach (var range in other)
     {
         @this.Remove(range.From, range.To);
     }
 }
Пример #3
0
 public MazePrinter(TextWriter output, ICharSet charSet, Maze maze, Func <Cell, bool> isSolutionCell)
 {
     this.output         = output;
     this.charSet        = charSet;
     this.maze           = maze;
     this.isSolutionCell = isSolutionCell;
 }
Пример #4
0
        public int CompareTo(ICharSet other)
        {
            var x = this;
            var y = other;

            if (x == null && y == null)
            {
                return(0);
            }
            if (x == null)
            {
                return(-1);
            }
            if (y == null)
            {
                return(+1);
            }
            if (x.Length == 0 && y.Length == 0)
            {
                return(0);
            }
            if (x.Length == 0)
            {
                return(-1);
            }
            if (y.Length == 0)
            {
                return(+1);
            }
            var lhs = x.First().First();
            var rhs = y.First().First();

            return(lhs.CompareTo(rhs));
        }
Пример #5
0
        public static ICharSet Intersect(this ICharSet @this, ICharSet other)
        {
            //A and B = !(!A or !B)
            var notA = @this.Negate();
            var notB = other.Negate();

            return(notA.Union(notB).Negate());
        }
Пример #6
0
 public CharSet(ICharSet from)
     : this()
 {
     foreach (var range in from)
     {
         Add(range.From, range.To);
     }
 }
Пример #7
0
 private bool MayConsume(ICharSet c)
 {
     if (!c.Includes(Lookahead))
     {
         return(false);
     }
     index++;
     return(true);
 }
Пример #8
0
        public static ICharSet Union(this ICharSet @this, params ICharSet[] others)
        {
            var result = new CharSet(@this);

            foreach (var other in others)
            {
                result.Add(other);
            }
            return(result);
        }
 public static IEnumerable <int> ReadSet(this ITransitionTargets @this, ICharSet set)
 {
     foreach (var cs in @this)
     {
         if (cs.Key.Contains(set))
         {
             return(cs);
         }
     }
     return(Enumerable.Empty <int>());
 }
Пример #10
0
        public static IAutomaton Consume(ICharSet characters)
        {
            var builder = new AutomatonBuilder();
            var start   = builder.AddState();
            var end     = builder.AddState();

            builder.SetStartState(start);
            builder.AcceptState(end);
            builder.AddTransition(start, characters, end);
            return(builder.Build());
        }
Пример #11
0
 public void AddTransition(int source, ICharSet characters, int target)
 {
     if (source < 0 || source >= StateCounter)
     {
         throw new ArgumentException(nameof(source));
     }
     if (target < 0 || target >= StateCounter)
     {
         throw new ArgumentException(nameof(target));
     }
     transitions.GetValueOrInsertedLazyDefault(source, () => new TransitionTargets())
     .Add(characters, target);
 }
Пример #12
0
 public static bool Contains(this ICharSet @this, ICharSet set)
 {
     if (@this == null)
     {
         return(false);
     }
     foreach (var range in set)
     {
         if ([email protected](range))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #13
0
 public static ICharSet Negate(this ICharSet @this)
 {
     return(CharSet.Full.Except(@this));
 }
Пример #14
0
        public void Add(ICharSet key, int value)
        {
            if (key == null)
            {
                if (nullNode == null)
                {
                    nullNode = new Node(null);
                }
                nullNode.Add(value);
            }
            else
            {
                if (key.Length == 0)
                {
                    return;
                }
                var added = false;
                for (var index = 0; index < nodes.Count; index++)
                {
                    var charset = nodes.Keys[index];
                    var node    = nodes.Values[index];
                    if (charset == null)
                    {
                        continue;
                    }
                    var cmnKey = key.Intersect(charset);
                    if (cmnKey.Any())
                    {
                        if (key.Equals(charset))
                        {
                            added = true;
                            node.Add(value);
                            break;
                        }
                        else
                        {
                            added = true;
                            nodes.RemoveAt(index);

                            var lhsKey = key.Except(charset);
                            var rhsKey = charset.Except(key);

                            nodes.Add(cmnKey, new Node(cmnKey, node.Prepend(value).ToArray()));
                            if (lhsKey.Any())
                            {
                                nodes.Add(lhsKey, new Node(lhsKey, value));
                                index++;
                            }
                            if (rhsKey.Any())
                            {
                                nodes.Add(rhsKey, new Node(rhsKey, node.ToArray()));
                                index++;
                            }
                        }
                    }
                }
                if (!added)
                {
                    nodes.Add(key, new Node(key, value));
                }
            }
        }
Пример #15
0
 public bool Contains(ICharSet key)
 {
     return(key == null ? nullNode != null : nodes.ContainsKey(key));
 }
Пример #16
0
 public IEnumerable <int> this[ICharSet key]
 {
     get { return(key == null ? nullNode : nodes.ContainsKey(key) ? nodes[key] : Enumerable.Empty <int>()); }
 }