FubarDevelopment / QuickGraph

Fork of https://quickgraph.codeplex.com/
Microsoft Public License
9 stars 2 forks source link

CP-22118: Don't use Comparer<TVertex>.Default in RootedAlgorithmBase.SetRootVertex() #126

Open fubar-coder opened 6 years ago

fubar-coder commented 6 years ago

From unknown CodePlex user on Thursday, 26 January 2012 07:21:54

In QuickGraph.Algorithms.RootedAlgorithmBase<TVertex,TGraph>.SetRootVertex(TVertex rootVertex) you do the following to check, if the same root vertex is already set:   Comparer.Default.Compare(this.rootVertex, rootVertex) != 0;   This is a problem, if you use a TVertex, which is not IComparable. It would be better to use EqualityComparer.Default, which uses the IEquatable interface or the standard .Equals()-method, which is present for every object.   As a consequence, at the moment no algorithm derived from RootedAlgorithmBase is able to process graphs using a TVertex, which is not IComparable.

fubar-coder commented 6 years ago

Form unknown CodePlex user on Wednesday, 29 August 2012 03:33:44

I think I was hit by this as well. After upgrading my nuget dependency to the 3.6 release my code stopped working:

I got an exception in ShortestPathsDijkstra for IUndirectedGraph saying something about IComparable. I guessed that I had to implement IComparable for my TVertex and indeed that did solve the problem.