Brunet.Symphony.AHAddress.RightDistanceTo C# (CSharp) Метод

RightDistanceTo() публичный Метод

public RightDistanceTo ( AHAddress addr ) : BigInteger
addr AHAddress
Результат Brunet.Util.BigInteger
    public BigInteger RightDistanceTo(AHAddress addr)
    {
      BigInteger n_x = ToBigInteger();
      BigInteger n_y = addr.ToBigInteger();

      BigInteger dist;
      
      if (n_y < n_x) {
	//The given address is smaller than us, just subtract
        dist = n_x - n_y;
      }
      else {
	//We need to add AHAddress.Full to the result:
        dist = n_x - n_y + AHAddress.Full;
      }
      return dist;
    }
    /** Utility method to determine if this address is between start and end

Usage Example

Пример #1
0
        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."));
            }
        }
All Usage Examples Of Brunet.Symphony.AHAddress::RightDistanceTo