Esempio n. 1
0
        private Graph Propagate(Bind b, BindState s, Node n0 = null)
        {
            if (s.Nodes.IsEmpty)
            {
                return(this);
            }
            else
            {
                var g  = this;
                var v0 = s.Val;

                _depth++;
                Log.WriteLine($"{Prefix}PROP {s}");
                _depth++;
                Log.Write($"{Prefix}{v0}");

                var nodes = s.Nodes.ToArray();
                int i = 0, j = 0;
                var v = v0;

                while (true)
                {
                    var n = nodes[i];

                    if (n != n0 || !v.Equals(v0))
                    {
                        Log.WriteLine($" -> {n}");

                        var(g2, v2) = n.Impel(g, v);
                        var v3 = Val.Combine(v, v2);
                        Log.Write($"{Prefix}{v3}");

                        if (!v3.Equals(v))
                        {
                            j = i;
                        }

                        g = g2;
                        v = v3;
                    }

                    i = (i + 1) % nodes.Length;
                    if (i == j)
                    {
                        break;
                    }
                }

                Log.WriteLine();
                _depth -= 2;

                return(new Graph(
                           g.NodeBinds,
                           g.BindStates.SetItem(b, s.WithVal(v))
                           ));
            }
        }
Esempio n. 2
0
 public BindState WithVal(Val v)
 => new BindState(Nodes, Val.Combine(Val, v));