|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object rice.pastry.Id
public class Id
Represents a Pastry identifier for a node, object or key. A single identifier and the bit length for Ids is stored in this class. Ids are stored little endian. NOTE: Ids are immutable, and are coalesced for memory efficiency. New Ids are to be constructed from the build() methods, which ensure that only one copy of each Id is in memory at a time.
Nested Class Summary | |
---|---|
static class |
Id.Distance
A class for representing and manipulating the distance between two Ids on the circle. |
Field Summary | |
---|---|
static int[] |
Half
|
static int |
IdBitLength
This is the bit length of the node ids. |
static int[] |
NegOne
|
static int |
nlen
|
static int[] |
Null
Distance constants |
static int[] |
One
|
static java.lang.String[] |
tran
The static translation array |
static short |
TYPE
|
Constructor Summary | |
---|---|
protected |
Id(int[] material)
Constructor. |
Method Summary | |
---|---|
Id |
add(Id.Distance offset)
Returns an Id corresponding to this Id plus a given distance |
Id |
addToId(Id.Distance offset)
Returns an Id corresponding to this Id plus a given distance |
void |
blit(byte[] target)
Blits the Id into a target array. |
void |
blit(byte[] target,
int offset)
Blits the distance into a target array, starting at the given offset. |
static Id |
build()
Constructor. |
static Id |
build(byte[] material)
Constructor. |
static Id |
build(char[] chars,
int offset,
int length)
Constructor, which takes the output of a toStringFull() and converts it back into an Id. |
static Id |
build(InputBuffer buf)
Id (Version 0) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + 160 Bit + + + + + + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
static Id |
build(int[] material)
Constructor. |
static Id |
build(java.lang.String hex)
Constructor, which takes the output of a toStringFull() and converts it back into an Id. |
boolean |
checkBit(int i)
Checks if the ith bit is flipped. |
boolean |
clockwise(Id nid)
Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring. |
boolean |
clockwise(Id nid)
Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring. |
int |
compareTo(java.lang.Object obj)
Comparison operator for Ids. |
byte[] |
copy()
Copy the Id into a freshly generated array. |
Id.Distance |
distance(Id nid)
Returns the shorter numerical distance on the ring between a pair of Ids. |
Id.Distance |
distance(Id nid,
Id.Distance d)
|
Id.Distance |
distanceFromId(Id nid)
Returns the shorter numerical distance on the ring between a pair of Ids. |
boolean |
equals(Id nid)
Equivalence relation for Ids. |
boolean |
equals(java.lang.Object obj)
Equality operator for Ids. |
Id |
getAlternateId(int num,
int b,
int i)
produces a set of ids (keys) that are evenly distributed around the id ring. |
int |
getByteArrayLength()
Returns the length of the byte[] representing this Id |
Id |
getCCW()
gets the Id just counterclockwise from this |
Id |
getCW()
gets the Id just clockwise from this |
int |
getDigit(int i,
int b)
Gets the ith digit in base 2^b. |
Id |
getDomainPrefix(int row,
int column,
int suffixDigit,
int b)
produces a Id whose prefix up to row is identical to this, followed by a digit with value column, followed by a suffix of digits with value suffixDigits. |
short |
getType()
|
int |
hashCode()
Hash codes for Ids. |
int |
indexOfMSDB(Id nid)
Returns the index of the most significant differing bit (MSDB). |
int |
indexOfMSDD(Id nid,
int base)
Returns the index of the most significant different digit (MSDD) in a given base. |
boolean |
isBetween(Id ccw,
Id cw)
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle |
boolean |
isBetween(Id ccw,
Id cw)
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle |
Id.Distance |
longDistance(Id nid)
Returns the longer numerical distance on the ring between a pair of Ids. |
Id.Distance |
longDistanceFromId(Id nid)
Returns the longer numerical distance on the ring between a pair of Ids. |
static Id |
makeRandomId(java.util.Random rng)
Creates a random Id. |
static Id |
makeRandomId(RandomSource rng)
|
static int |
numDigits(int base)
return the number of digits in a given base |
protected static Id |
resolve(java.util.WeakHashMap map,
Id id)
Method which performs the coalescing and interaction with the weak hash map |
void |
serialize(OutputBuffer buf)
Serialize |
byte[] |
toByteArray()
Returns the byte array representation of this Id |
void |
toByteArray(byte[] array,
int offset)
Stores the byte[] value of this Id in the provided byte array |
java.lang.String |
toString()
Returns a string representation of the Id in base 16. |
java.lang.String |
toStringBare()
Similar to toString(), but not wrapped by <0x ..> |
java.lang.String |
toStringFull()
Returns the complete represntation of this Id, in hex. |
protected static int[] |
trans(byte[] material)
Internal method for mapping byte[] -> int[] |
protected static byte |
trans(char c)
Internal method for mapping digit -> num |
protected static int[] |
trans(java.lang.String hex)
Static method for converting the hex representation into an array of ints. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final short TYPE
public static final java.lang.String[] tran
public static final int IdBitLength
public static final int nlen
public static final int[] Null
public static final int[] One
public static final int[] NegOne
public static final int[] Half
Constructor Detail |
---|
protected Id(int[] material)
material
- an array of length at least IdBitLength/32 containing raw Id material.Method Detail |
---|
public static int numDigits(int base)
base
- the number of bits in the base
public static Id makeRandomId(java.util.Random rng)
rng
- random number generator
public static Id makeRandomId(RandomSource rng)
public static Id build(int[] material)
material
- an array of length at least IdBitLength/32 containing raw Id material.public static Id build(InputBuffer buf) throws java.io.IOException
buf
-
java.io.IOException
public void serialize(OutputBuffer buf) throws java.io.IOException
Id
serialize
in interface Id
java.io.IOException
public static Id build(java.lang.String hex)
hex
- The hexadeciaml representation from the toStringFull()public static Id build(char[] chars, int offset, int length)
hex
- The hexadeciaml representation from the toStringFull()protected static byte trans(char c)
digit
- The printed charnum
- The byte numberpublic static Id build(byte[] material)
material
- an array of length at least IdBitLength/8 containing raw Id material.protected static int[] trans(byte[] material)
material
- The input byte[]
public static Id build()
protected static int[] trans(java.lang.String hex)
hex
- The hexadecimal represetnation
protected static Id resolve(java.util.WeakHashMap map, Id id)
id
- The Id to coalesce
public Id getCW()
public Id getCCW()
public boolean isBetween(Id ccw, Id cw)
ccw
- the counterclockwise idcw
- the clockwise id
public int getDigit(int i, int b)
i
- which digit to get.b
- which power of 2 is the base to get it in.
public Id getDomainPrefix(int row, int column, int suffixDigit, int b)
row
- the length of the prefixcolumn
- the value of the following digitsuffixDigit
- the value of the suffix digitsb
- power of 2 of the base
public Id getAlternateId(int num, int b, int i)
num
- the number of Ids in the set (must be <= 2^b)b
- the routing base (as a power of 2)i
- the index of the requested member of the set (0<=ipublic boolean isBetween(Id ccw, Id cw)
isBetween
in interface Id
ccw
- the counterclockwise idcw
- the clockwise id
public void blit(byte[] target)
target
- an array of length at least IdBitLength/8 for the Id to be stored in.public void blit(byte[] target, int offset)
offset
- The offset to start attarget
- an array of length at least IdBitLength/8 for the distance to be stored in.public byte[] copy()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- a Id object
public int compareTo(java.lang.Object obj)
compareTo
in interface java.lang.Comparable
obj
- the Id to compare with.
public byte[] toByteArray()
toByteArray
in interface Id
public void toByteArray(byte[] array, int offset)
toByteArray
in interface Id
public int getByteArrayLength()
getByteArrayLength
in interface Id
public int hashCode()
hashCode
in class java.lang.Object
public Id add(Id.Distance offset)
offset
- the distance to add
public Id.Distance distance(Id nid)
nid
- the other node id.
public Id.Distance distance(Id nid, Id.Distance d)
public Id.Distance longDistance(Id nid)
nid
- the other node id.
public boolean equals(Id nid)
nid
- the other node id.
public boolean clockwise(Id nid)
nid
- The Id we are comparing to
public boolean checkBit(int i)
i
- which bit to check.
public int indexOfMSDB(Id nid)
nid
- another node id to compare with.
public int indexOfMSDD(Id nid, int base)
nid
- another node id to compare with.base
- the base (as a power of two) to compare in.
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toStringBare()
public java.lang.String toStringFull()
toStringFull
in interface Id
public boolean clockwise(Id nid)
clockwise
in interface Id
nid
- DESCRIBE THE PARAMETER
public Id addToId(Id.Distance offset)
addToId
in interface Id
offset
- the distance to add
public Id.Distance distanceFromId(Id nid)
distanceFromId
in interface Id
nid
- the other node id.
public Id.Distance longDistanceFromId(Id nid)
longDistanceFromId
in interface Id
nid
- the other node id.
public short getType()
getType
in interface Id
|
Rice Pastry API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |