Open mattwar opened 7 years ago
I use vertex comparison in my shortest paths, mst and topological sorting algorithms. Also the main reason for it to be of IComparable
@abdonkov What about allowing the constructors to receive a IComparer
rather than constraining the generic parameter? I mean this similarly to how SortedSet)) works.
That will mean runtime error when used incorrectly and I'm not completely sure I want that. However, something that can be done while maintaining backwards compatibility is moving the IComparable<> constraint to the BFS and DFS methods that use it and introducing a new set of BFS and DFS that do not perform any type of comparison.
That will mean runtime error when used incorrectly and I'm not completely sure I want that.
Yes, you're right - you can have runtime errors.
However, something that can be done while maintaining backwards compatibility is moving the IComparable<> constraint to the BFS and DFS methods that use it and introducing a new set of BFS and DFS that do not perform any type of comparison.
Yes, this sounds like a possible solution. However, it may introduce more code and more effort to maintain it. Regardless of any particular solution, I think it would be great if IComparable
is not always required. Sometimes, certain classes, have no "one size fits all" possible IComparable
implementation.
However, it may introduce more code and more effort to maintain it.
I think it could be done by moving the BFS and DFS to a private method that uses IComparer
You seem to constrain a lot of your TVertex declarations to
ICompareable<TVertext>
when most of the algorithms and data structures only ever need/use equality. You should useIEquatable<TVertex>
in many places instead.