public Enumerator(Tree <T> tree)
 {
     this.data      = tree.m_data.m_buffer;
     this.count     = tree.m_data.m_count;
     this.id        = count;
     this.ancestors = Stack <NodeId> .Create();
 }
示例#2
0
            // O(|head1|+|head2|) runtime, O(1) space
            public static LinkedList.Node FindIntersection(LinkedList.Node head1, LinkedList.Node head2)
            {
                // If either head node is null, throw exception.
                if (head1 == null)
                {
                    throw new System.ArgumentNullException("head1");
                }
                if (head2 == null)
                {
                    throw new System.ArgumentNullException("head2");
                }

                // Create array of NodeCounts to organize data.
                var ncArray = new NodeCount[2]
                {
                    new NodeCount()
                    {
                        Node = head1
                    },
                    new NodeCount()
                    {
                        Node = head2
                    }
                };

                // Calculate the length and terminating node of each list.
                for (int i = 0; i < ncArray.Length; i++)
                {
                    ncArray[i].TerminalNode = ncArray[i].Node;
                    while (ncArray[i].TerminalNode.Next != null)
                    {
                        ncArray[i].Count++;
                        ncArray[i].TerminalNode = ncArray[i].TerminalNode.Next;
                    }
                }

                // If the terminating nodes of the lists are not the same node, they do not intersect.
                if (!ncArray[0].TerminalNode.Equals(ncArray[0].TerminalNode))
                {
                    return(null);
                }

                // Sort ncArray by length of each list.
                ncArray = ncArray.OrderBy(x => x.Count).ToArray <NodeCount>();

                // Trim the start of the longer list until they are the same length.
                while (ncArray[1].Count > ncArray[0].Count)
                {
                    ncArray[1].Node = ncArray[1].Node.Next;
                    ncArray[1].Count--;
                }

                // Check node-by-node until the intersecting node is found.
                while (ncArray[0].Node.Equals(ncArray[1].Node))
                {
                    ncArray[0].Node = ncArray[0].Node.Next;
                    ncArray[1].Node = ncArray[1].Node.Next;
                }
                return(ncArray[0].Node);
            }
示例#3
0
        /// <inheritdoc />
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine("---------------------");
            sb.AppendLine($"Graph ({NodeCount.ToString()} nodes)");
            foreach (var t in _connections)
            {
                sb.AppendLine($"Node: {t.Key.ToString()}");
                foreach (var x1 in t.Value)
                {
                    sb.AppendLine($"\tConnection to: {x1.ToString()}");
                }
            }
            sb.AppendLine("---------------------");
            return(sb.ToString());
        }
示例#4
0
 public override string ToString()
 {
     return(Name + ": " + filename + " (" + NodeCount.ToString() + " nodes)");
 }
示例#5
0
 public Tree(T root, NodeCount capacity)
 {
     this.m_data = new Stack <Node>(capacity);
     ref var r = ref this.m_data.Push();
示例#6
0
 public override string ToString()
 {
     return(CenterX.ToString() + ", " + CenterY.ToString() + ", " + SizeX.ToString() + ", " + SizeY.ToString() + ", " +
            NodeIndex.ToString() + ", " + NodeCount.ToString() + ", " + Short7.ToString() + ", " + Short8.ToString() + ", " +
            FloatUtil.ToString(Float1) + ", " + Byte1.ToString() + ", " + Byte2.ToString() + ", " + Byte3.ToString() + ", " + Byte4.ToString());
 }
示例#7
0
        public override void Update(JuixelTime Time)
        {
            Location MoveVector = 0;

            if (Input.KeyIsDown(Keys.W))
            {
                MoveVector += new Location(0, -1);
            }
            if (Input.KeyIsDown(Keys.S))
            {
                MoveVector += new Location(0, 1);
            }

            if (Input.KeyIsDown(Keys.A))
            {
                MoveVector += new Location(-1, 0);
            }
            if (Input.KeyIsDown(Keys.D))
            {
                MoveVector += new Location(1, 0);
            }

            if (MoveVector.X != 0 || MoveVector.Y != 0)
            {
                Player.Position += MoveVector.Angle.Location * Pixels_Per_Second * Time.ElapsedSec;
                Tiles.Focus      = (Player.Position / 40).Int;
            }

            base.Update(Time);

            if (Input.KeyIsDown(Keys.Y))
            {
                var Player = new Player();
                Player.Scale    = 10;
                Player.Position = Location.Random * 1000;
                Player.Layer    = Player.Position.Y;
                AddChild(Player);
                Players.Add(Player);

                Player          = new Player();
                Player.Scale    = 10;
                Player.Position = Location.Random * 1000;
                Player.Layer    = Player.Position.Y;
                AddChild(Player);
                Players.Add(Player);
            }


            if (Input.KeyIsDown(Keys.OemPlus))
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    Players[i].Health += 0.01;
                }
            }

            if (Input.KeyIsDown(Keys.OemMinus))
            {
                for (int i = 0; i < Players.Count; i++)
                {
                    Players[i].Health -= 0.01;
                }
            }


            IntLocation TilePosition = (Player.Position / Tiles.Scale / 8).IntFloor;
            Tile        CurrentTile  = Tiles.Get(TilePosition.X, TilePosition.Y);

            int TileCount    = 0;
            int WeatherCount = 0;

            if (CurrentTile != LastTile)
            {
                for (int Y = -Weather_Detect_Radius; Y <= Weather_Detect_Radius; Y++)
                {
                    for (int X = -Weather_Detect_Radius; X <= Weather_Detect_Radius; X++)
                    {
                        Tile Tile = Tiles.Get(TilePosition.X + X, TilePosition.Y + Y);
                        if (Tile != null)
                        {
                            WeatherCount += Tile.WeatherIntensity;
                            TileCount++;
                        }
                    }
                }
                LastTile        = CurrentTile;
                TargetIntensity = (WeatherCount / (double)TileCount) * 4;
            }

            if (Snow.Intensity != TargetIntensity)
            {
                double Difference = TargetIntensity - Snow.Intensity;
                double Change     = Weather_Change_Per_Second * Time.ElapsedSec;
                if (Math.Abs(Difference) < Change)
                {
                    Snow.Intensity = TargetIntensity;
                }
                else
                {
                    Snow.Intensity += Change * (Difference / Math.Abs(Difference));
                }
            }

            JuixelGame.ShowDebugText(NodeCount.ToString(), 2);

            if (Client != null)
            {
                Info.Text = Client.Latency.ToString();
            }
        }
示例#8
0
        /// <summary>
        /// Sorts the nodes of a graph in topological order.
        /// </summary>
        /// <typeparam name="TNode">The type of a node.</typeparam>
        /// <typeparam name="TKey">The type of a node key.</typeparam>
        /// <param name="nodes">The set of nodes.</param>
        /// <param name="key">The function which maps a node to its key.</param>
        /// <param name="next">The function which maps a node to its adjacent nodes.</param>
        /// <returns>The topologically sorted nodes.</returns>
        /// <exception cref="Shields.Graphs.GraphCycleException">This exception is thrown if the graph contains a cycle.</exception>
        public static IEnumerable <TNode> OrderTopologically <TNode, TKey>(
            this IEnumerable <TNode> nodes,
            Func <TNode, TKey> key,
            Func <TNode, IEnumerable <TNode> > next)
        {
            var incoming = new Dictionary <TKey, NodeCount <TNode> >();

            foreach (var u in nodes)
            {
                var key_u = key(u);
                if (!incoming.ContainsKey(key_u))
                {
                    incoming.Add(key_u, new NodeCount <TNode> {
                        Node = u, Count = 0
                    });
                }
                foreach (var v in next(u))
                {
                    var key_v = key(v);
                    NodeCount <TNode> data;
                    if (!incoming.TryGetValue(key_v, out data))
                    {
                        data = new NodeCount <TNode> {
                            Node = v, Count = 0
                        };
                        incoming.Add(key_v, data);
                    }
                    data.Count++;
                }
            }
            var S = new Queue <TNode>(incoming.Values
                                      .Where(data => data.Count == 0)
                                      .Select(data => data.Node)
                                      .ToList());

            foreach (var u in S)
            {
                incoming.Remove(key(u));
            }
            while (S.Count > 0)
            {
                var u = S.Dequeue();
                yield return(u);

                foreach (var v in next(u))
                {
                    var key_v = key(v);
                    var data  = incoming[key_v];
                    data.Count--;
                    if (data.Count == 0)
                    {
                        incoming.Remove(key_v);
                        S.Enqueue(v);
                    }
                }
            }
            if (incoming.Count > 0)
            {
                throw new GraphCycleException();
            }
        }