public int Compare(Connection x, Connection y)
{
//Equals is fast to check, lets do it before we
//do more intense stuff :
if (x.Equals(y))
{
return(0);
}
if ((x.Address is AHAddress) && (y.Address is AHAddress))
{
AHAddress add_x = (AHAddress)x.Address;
AHAddress add_y = (AHAddress)y.Address;
/**
* We compute the distances with the given zero
* dist_x : distance from zero to x
* dist_y : distance from zero to y
*
* The AHAddress.RightDistanceTo function gives
* the distance as measured from the node in count-clockwise.
*
* We can use this to set the "zero" we want :
*/
BigInteger dist_x = _zero.RightDistanceTo(add_x);
BigInteger dist_y = _zero.RightDistanceTo(add_y);
//Since we know they are not equal, either n_x is bigger
//that n_y or vice-versa :
if (dist_x > dist_y)
{
//Then dist_x - dist_y > 0, and n_x is the bigger
return(1);
}
else
{
return(-1);
}
}
else
{
/**
* If addresses are not AHAddress, throw an exception
*/
throw new Exception(
String.Format("The addresses are not AHAddress. Only AHAddress can be compared."));
}
}