Why SUndirectedEdge requires source and target being comparable?

Mar 18, 2011 at 5:21 PM

In QuickGraph.Contract.dll, the constructor of SUndirectedEdge<TVertex> (cf. below) requires by contract that the source and the target to be comparable (and source < target).

Why? Is that necessary? And why does in contract-less version of QuickGraph is there no "if ... throw exception" to replace it?

Thanks in advance for your explanation.





public SUndirectedEdge(TVertex source, TVertex target)
Contract.Requires(source != null, null, "source != null");
Contract.Requires(target != null, null, "target != null");
Contract.Requires(Comparer<TVertex>.Default.Compare(source, target) <= 0, null, "Comparer<TVertex>.Default.Compare(source, target) <= 0");
Contract.Ensures(Contract.ValueAtReturn<SUndirectedEdge<TVertex>>(out (SUndirectedEdge<TVertex>) ref this).Source.Equals(source), null, "Contract.ValueAtReturn(out this).Source.Equals(source)");
Contract.Ensures(Contract.ValueAtReturn<SUndirectedEdge<TVertex>>(out (SUndirectedEdge<TVertex>) ref this).Target.Equals(target), null, "Contract.ValueAtReturn(out this).Target.Equals(target)");

Apr 19, 2011 at 8:56 PM

Up. Nobody on that subject? Please....