示例#1
0
文件: Edge.cs 项目: pavkam/abacaxi
        /// <summary>
        ///     Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        ///     A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode()
        {
            var hashCode = 17;

            hashCode = hashCode * 23 + ToVertex.GetHashCode();
            hashCode = hashCode * 23 + FromVertex.GetHashCode();
            hashCode = hashCode * 23 + Weight.GetHashCode();

            return(hashCode);
        }
示例#2
0
            public override bool Equals(object obj)
            {
                Edge edge = (Edge)obj;

                return(FromVertex.Equals(edge.FromVertex) && ToVertex.Equals(edge.ToVertex));
            }
示例#3
0
        /// <summary>
        /// Remove Link
        ///
        /// Removes the link between
        /// two stations if both stations exits
        /// and there is a link to remove.
        ///
        /// </summary>
        /// <param name="from">From station name</param>
        /// <param name="to">To station name</param>
        /// <param name="color">The line color</param>
        public void RemoveLink(T from, T to, ConsoleColor color)
        {
            int        fromPos, toPos, edgePos;
            Vertex <T> FromVertex, ToVertex;

            //Find if the vertecies exists
            if ((fromPos = FindVertex(from)) > -1 && (toPos = FindVertex(to)) > -1)
            {
                //Get the vertecies
                FromVertex = Vertecies[fromPos];
                ToVertex   = Vertecies[toPos];

                //I asume that the edge goes bothway so i wont need to check the other way around
                //Check if the edge exists
                if ((edgePos = Vertecies[fromPos].FindEdge(to, color)) > -1)
                {
                    //Remove the link from the FROM station
                    Vertecies[fromPos].Edges.RemoveAt(edgePos);

                    //Get the line positon for the adjacent vertex
                    edgePos = Vertecies[toPos].FindEdge(from, color);

                    //Remove the line from the adj vertex
                    Vertecies[toPos].Edges.RemoveAt(edgePos);

                    //Display message
                    Helper.MessageDisplay("\nJust Deleted the link between " + FromVertex.ToString() + " and " + ToVertex.ToString() + "\n", ConsoleColor.Green);
                }
                else
                {
                    //Display message
                    Helper.MessageDisplay("\nThe link between " + Vertecies[fromPos].ToString() + " and " + Vertecies[toPos].ToString() + " with color " + color + " doesn't exist\n", ConsoleColor.Red);
                }
            }
            else
            {
                //Display message
                Helper.MessageDisplay("\nOne of the station inputed doesn't exists\n", ConsoleColor.Red);
            }
        }
示例#4
0
 public override int GetHashCode()
 {
     return(FromVertex.GetHashCode() ^ FromEndpoint.GetHashCode() ^ ToVertex.GetHashCode() ^ ToEndpoint.GetHashCode());
 }