hypercast.HC
Class HC_LogicalAddress

java.lang.Object
  |
  +--hypercast.HC.HC_LogicalAddress
All Implemented Interfaces:
I_Address, I_LogicalAddress

public final class HC_LogicalAddress
extends java.lang.Object
implements I_LogicalAddress

This class includes all the functions related with logical address

Functionality:
* It provides the logical address for a hypercube node. It includes all operations which one might need to do regarding a Logical address. This would include, 1. Converting from Gray to Colex and vice-versa
2. Printing the Logical Address
3. Find parent of a node with respect to a root
4. Finding neighbor information


Constructor Summary
HC_LogicalAddress(byte[] byteAddr, int offset)
          Constructs HC_LogicalAddress object from an byte array using Colex index Algorithm:
HC_LogicalAddress(hypercast.HC.HC_LogicalAddress laddr)
          Constructs a new HC_LogicalAddress object from another HC_LogicalAddress
HC_LogicalAddress(int index, boolean iscolex)
          Constructs HC_LogicalAddress object from an Gray index or Colex index
HC_LogicalAddress(java.lang.String addr)
          added by Guangyu May 02, 04
 
Method Summary
 hypercast.HC.HC_LogicalAddress[] children(hypercast.HC.HC_LogicalAddress root, hypercast.HC.HC_LogicalAddress hroot)
          Gets the children of this node
 boolean equals(hypercast.HC.HC_LogicalAddress hcla)
          Check the equality of two HC_LogicalAddress objects
 boolean equals(java.lang.Object o)
          Implements Object.equals(Object) as required by I_Address.
 int findNeighborIndex(hypercast.HC.HC_LogicalAddress laddr)
          Finds the colex index of a neighbor with a specified logical address.
 int getColexIndex()
          Gets the colex index
 int getGrayIndex()
          Gets the gray index
 hypercast.HC.HC_LogicalAddress getNthNeighbor(int index)
          Gets the Nth Neighbor's logical address
 int getSize()
          Returns the size of the byte array of this HC_LogicalAddress
 boolean greaterThan(hypercast.I_Address laddr)
          Compares two HC_LogicalAddress objects
 hypercast.HC.HC_LogicalAddress parent(hypercast.HC.HC_LogicalAddress root)
          Gets the Parent of this node
 byte[] toByteArray()
          Returns the byte array
 java.lang.String toString()
          Converts logical address object to String
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface hypercast.I_Address
hashCode
 

Constructor Detail

HC_LogicalAddress

public HC_LogicalAddress(int index,
                         boolean iscolex)
Constructs HC_LogicalAddress object from an Gray index or Colex index

Algorithm:
If the second argument is true, the integer is the colex ordering, and the gray ordering is trivial to find from the colex ordering, using the the formula (colex XOR (colex/2))
If the second argument is false, and the integer is a gray index, the reverse conversion is a bit more difficult, and is explained in greater detail in the tech report
The SortedNeighborhood variable is set to false

Parameters:
index - An Integer which can represent the nodes gray index or colex index
iscolex - a boolean to indicate if the first argument is colex or a gray index

HC_LogicalAddress

public HC_LogicalAddress(java.lang.String addr)
added by Guangyu May 02, 04


HC_LogicalAddress

public HC_LogicalAddress(byte[] byteAddr,
                         int offset)
Constructs HC_LogicalAddress object from an byte array using Colex index Algorithm:

Parameters:
byteAddr - a bytearray containing the Colex index.
offset - the start position of index in the byte array.

HC_LogicalAddress

public HC_LogicalAddress(hypercast.HC.HC_LogicalAddress laddr)
Constructs a new HC_LogicalAddress object from another HC_LogicalAddress

Parameters:
laddr - An object of type HC_LogicalAddress
Method Detail

getNthNeighbor

public hypercast.HC.HC_LogicalAddress getNthNeighbor(int index)
Gets the Nth Neighbor's logical address

Algorithm:
1. Create the ordering if it is not created, by calling orderNeighborhood
2. Find the bit in which the required neighbor differs and then XOR
that bit in GrayIndex, and create a new HC_LogicalAddress.

Parameters:
index - The index of the neighbor, where all neighbors are ordered by the colex number
Returns:
HC_LogicalAddress object corresponding to Neigbor
Throws:
No - formal Exceptions raised; however, it ArrayBoundsException will be raised by the system if index is out of bounds

findNeighborIndex

public int findNeighborIndex(hypercast.HC.HC_LogicalAddress laddr)
Finds the colex index of a neighbor with a specified logical address. Find the HammingVector by XORing the GrayIndex variable of the argument and the node itself. If this Vector has only one bit then it is a neighbor and we return the index in the neighborhood, else return -1 The index in the neighborhood is found by finding the position of the flipped bit, and using BitToOrdered to figure out its place in the ordering.

Parameters:
laddr - HC_LogicalAddress of a node
Returns:
-1 if the node is not a neighbor, and the ColexIndex otherwise

parent

public hypercast.HC.HC_LogicalAddress parent(hypercast.HC.HC_LogicalAddress root)
Gets the Parent of this node

Algorithm:
1. Compare the ColexIndex of the node with that of the root
2. If ColexIndex of the node is less than that of the root, flip the least bit of difference
3. If the situation is otherwise, then flip the greatest bit of difference

Parameters:
root - Takes as argument the HC_LogicalAddress object of the node which will be the root of the tree against which you want to find this nodes parent
Returns:
HC_LogicalAddress of the Parent
Throws:
Exits, - if the node itself is passed as a root

children

public hypercast.HC.HC_LogicalAddress[] children(hypercast.HC.HC_LogicalAddress root,
                                                 hypercast.HC.HC_LogicalAddress hroot)
Gets the children of this node

Algorithm:
1. Compare the ColexIndex of the node with that of the root
2. If ColexIndex of the node is less than that of the root, flip the least bit of difference
3. If the situation is otherwise, then flip the greatest bit of difference

Parameters:
root - the HC_LogicalAddress object of the node which will be the root of the tree
hroot - the HC_LogicalAddress object of the HRoot of the Hypercube
Returns:
HC_LogicalAddress array of the Children
Throws:
Exits, - if the node itself is passed as a root

getColexIndex

public int getColexIndex()
Gets the colex index

Returns:
ColexIndex of the object

getGrayIndex

public int getGrayIndex()
Gets the gray index

Returns:
Gray Index of the object

equals

public boolean equals(hypercast.HC.HC_LogicalAddress hcla)
Check the equality of two HC_LogicalAddress objects

Algorithm:
Compares the GrayIndex of both nodes, and the ColexIndex of both. If both pairs match, return true. If both pairs don't match return false If however, only one of the pairs matches, there is an inconsistency, So it exits.

Parameters:
hcla - HC_LogicalAddress object against which testing is to be done
Returns:
true or false depending on result of equality test
Throws:
No - formal exceptions; however it exits if it finds an inconsistency

equals

public boolean equals(java.lang.Object o)
Implements Object.equals(Object) as required by I_Address.

Specified by:
equals in interface I_Address
Overrides:
equals in class java.lang.Object

greaterThan

public boolean greaterThan(hypercast.I_Address laddr)
Compares two HC_LogicalAddress objects

Algorithm:
Compares the ColexIndex of both nodes

Specified by:
greaterThan in interface I_Address
Parameters:
laddr - HC_LogicalAddress object against which testing is to be done
Returns:
true or false depending on result of compare result

toByteArray

public byte[] toByteArray()
Returns the byte array

Specified by:
toByteArray in interface I_Address

getSize

public int getSize()
Returns the size of the byte array of this HC_LogicalAddress

Specified by:
getSize in interface I_Address

toString

public java.lang.String toString()
Converts logical address object to String

Overrides:
toString in class java.lang.Object
Returns:
String which is a printable representation of object contents colexindex (grayindex)