Rice Pastry API

rice.pastry.multiring
Class RingId

java.lang.Object
  |
  +--rice.pastry.multiring.RingId
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class RingId
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

This class represents a ringId, which is based on a NodeId and represents a unique identifier for a ring.

Version:
$Id: RingId.java,v 1.2 2003/03/18 07:20:52 amislove Exp $
Author:
Alan Mislove
See Also:
Serialized Form

Field Summary
static int ringIdBitLength
          This is the bit length of the node ids.
 
Constructor Summary
RingId()
          Constructor.
RingId(byte[] material)
          Constructor.
RingId(int[] material)
          Constructor.
 
Method Summary
 void blit(byte[] target)
          Blits the ringId into a target array.
 int compareTo(java.lang.Object obj)
          Comparison operator for ringIds.
 byte[] copy()
          Copy the ringId into a freshly generated array.
 boolean equals(java.lang.Object obj)
          Equality operator for ringIds.
 boolean equals(rice.pastry.multiring.RingId nid)
          Equivalence relation for ringIds.
 int getDigit(int i, int b)
          Gets the ith digit in base 2^b.
 int hashCode()
          Hash codes for ringIds.
static int numDigits(int base)
          return the number of digits in a given base
 rice.pastry.NodeId toNodeId()
          Copy the ringId into a new Nodeid
 java.lang.String toString()
          Returns a string representation of the ringId in base 16.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ringIdBitLength

public static final int ringIdBitLength
This is the bit length of the node ids. If it is n, then there are 2^n different Pastry nodes. We currently assume that it is divisible by 32.

See Also:
Constant Field Values
Constructor Detail

RingId

public RingId(byte[] material)
Constructor.

Parameters:
material - an array of length at least ringIdBitLength/8 containing raw ringId material.

RingId

public RingId(int[] material)
Constructor.

Parameters:
material - an array of length at least ringIdBitLength/32 containing raw ringId material.

RingId

public RingId()
Constructor. It constructs a new RingId with a value of 0 for all bits.

Method Detail

blit

public void blit(byte[] target)
Blits the ringId into a target array.

Parameters:
target - an array of length at least ringIdBitLength/8 for the ringId to be stored in.

toNodeId

public rice.pastry.NodeId toNodeId()
Copy the ringId into a new Nodeid

Returns:
a new nodeId with the value of this ringId

copy

public byte[] copy()
Copy the ringId into a freshly generated array.

Returns:
a fresh copy of the ringId material

numDigits

public static int numDigits(int base)
return the number of digits in a given base

Parameters:
base - the number of bits in the base
Returns:
the number of digits in that base

equals

public boolean equals(java.lang.Object obj)
Equality operator for ringIds.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a ringId object
Returns:
true if they are equal, false otherwise.

compareTo

public int compareTo(java.lang.Object obj)
Comparison operator for ringIds. The comparison that occurs is a numerical comparison.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the RingId to compare with.
Returns:
negative if this < obj, 0 if they are equal and positive if this > obj.

hashCode

public int hashCode()
Hash codes for ringIds.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code.

equals

public boolean equals(rice.pastry.multiring.RingId nid)
Equivalence relation for ringIds.

Parameters:
nid - the other node id.
Returns:
true if they are equal, false otherwise.

getDigit

public int getDigit(int i,
                    int b)
Gets the ith digit in base 2^b. i = 0 is the least significant digit.

Parameters:
i - which digit to get.
b - which power of 2 is the base to get it in.
Returns:
the ith digit in base 2^b.

toString

public java.lang.String toString()
Returns a string representation of the ringId in base 16. The string is a byte string from most to least significant.

Overrides:
toString in class java.lang.Object

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection