peersim.pastry
Class Util

java.lang.Object
  extended by peersim.pastry.Util

public class Util
extends java.lang.Object

Some utility and mathematical function to work with numbers and strings.

Title: MSPASTRY

Description: MsPastry implementation for PeerSim

Copyright: Copyright (c) 2007

Company: The Pastry Group


Field Summary
static char[] DIGITS
           
 
Constructor Summary
Util()
           
 
Method Summary
static int charToIndex(char c)
          convert a cipher in the equivalent int value '0'-->0, ...
static java.math.BigInteger distance(java.math.BigInteger a, java.math.BigInteger b)
          return the distance between two number, that is |a-b|.
static boolean hasDigitAt(java.math.BigInteger b, int position, char c)
          Given b, normalize it and check if char c is at specified position
static int max(int a, int b)
          max between a and b
static int min(int a, int b)
          min between a and b
static boolean nearer(java.math.BigInteger center, java.math.BigInteger near, java.math.BigInteger far)
          given a point (center), returns true if the second parameter (near) has less distance from the center respect with the 3rd point (far)
static int pow2(int i)
          2^i
static int prefixLen(java.math.BigInteger b1, java.math.BigInteger b2)
          Given two numbers, returns the length of the common prefix, i.e.
static java.lang.String put0(java.math.BigInteger b)
          convert a BigInteger into a String, by considering the current BASE, and by leading all needed non-significative zeroes in order to reach the canonical length of a nodeid
static boolean startsWith(java.math.BigInteger b, char c)
          return true if b (normalized) starts with c
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIGITS

public static final char[] DIGITS
Constructor Detail

Util

public Util()
Method Detail

prefixLen

public static final int prefixLen(java.math.BigInteger b1,
                                  java.math.BigInteger b2)
Given two numbers, returns the length of the common prefix, i.e. how many digits (in the given base) have in common from the leftmost side of the number

Parameters:
b1 - BigInteger
b2 - BigInteger
Returns:
int

startsWith

public static final boolean startsWith(java.math.BigInteger b,
                                       char c)
return true if b (normalized) starts with c

Parameters:
b - BigInteger
c - char
Returns:
boolean

distance

public static final java.math.BigInteger distance(java.math.BigInteger a,
                                                  java.math.BigInteger b)
return the distance between two number, that is |a-b|. no checking is done.

Parameters:
a - BigInteger
b - BigInteger
Returns:
BigInteger

nearer

public static final boolean nearer(java.math.BigInteger center,
                                   java.math.BigInteger near,
                                   java.math.BigInteger far)
given a point (center), returns true if the second parameter (near) has less distance from the center respect with the 3rd point (far)

Parameters:
center - BigInteger
near - BigInteger
far - BigInteger
Returns:
boolean

hasDigitAt

public static final boolean hasDigitAt(java.math.BigInteger b,
                                       int position,
                                       char c)
Given b, normalize it and check if char c is at specified position

Parameters:
b - BigInteger
position - int
c - char
Returns:
boolean

max

public static final int max(int a,
                            int b)
max between a and b

Parameters:
a - int
b - int
Returns:
int

min

public static final int min(int a,
                            int b)
min between a and b

Parameters:
a - int
b - int
Returns:
int

put0

public static final java.lang.String put0(java.math.BigInteger b)
convert a BigInteger into a String, by considering the current BASE, and by leading all needed non-significative zeroes in order to reach the canonical length of a nodeid

Parameters:
b - BigInteger
Returns:
String

charToIndex

public static final int charToIndex(char c)
convert a cipher in the equivalent int value '0'-->0, ... 'f' --> 15

Parameters:
c - char
Returns:
int

pow2

public static final int pow2(int i)
2^i

Parameters:
i - int i must be a non-negative number
Returns:
int 2^i