edu.virginia.cs.mng.hypercast.HC
Class HC_LogicalAddress

java.lang.Object
  |
  +--edu.virginia.cs.mng.hypercast.HC.HC_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


Field Summary
private  int[] BitToOrdered
          Permutation required to turn a neighborhood sorted by the bit flipped in the Gray index into a neighborhood table sorted by the Colex index.
private  int ColexIndex
          The index of this node in the hypercube or HC_Node.MaxAddress() if unvalid.
private  int GrayIndex
          The gray code encoding of ColexIndex
private  int[] OrderedToBit
          Permutation required to turn a neighborhood sorted by Colex index into a neighborhood table sorted by the bit flipped in the Gray index.
private  boolean OrderingDone
          True if bitToOrdered and OrderedToBit have been set.
 
Constructor Summary
HC_LogicalAddress(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 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
 
Method Summary
 HC_LogicalAddress[] children(HC_LogicalAddress root, HC_LogicalAddress hroot)
          Gets the children of this node Algorithm:
1.
private  int convertGrayToColex(int index)
          Converts Gray index to Colex index
 boolean equals(HC_LogicalAddress hcla)
          Check the equality of two HC_LogicalAddress objects Algorithm:
Compares the GrayIndex of both nodes, and the ColexIndex of both.
 boolean equals(java.lang.Object o)
          Implements Object.equals(Object) as required by I_Address.
 int findNeighborIndex(HC_LogicalAddress laddr)
          Finds the colex index of a neighbor with a specified logical address.
private  HC_LogicalAddress flipNthBit(int i)
          Flip the Nth bit of the gray code.
 int getColexIndex()
          Gets the colex index
 int getGrayIndex()
          Gets the gray index
 HC_LogicalAddress getNthNeighbor(int index)
          Gets the Nth Neighbor's logical address Algorithm:
1.
 int getSize()
          Returns the size of the byte array of this HC_LogicalAddress
 boolean greaterThan(I_Address laddr)
          Compares two HC_LogicalAddress objects Algorithm:
Compares the ColexIndex of both nodes
private  void orderNeighborhood()
          Initializes the values of OrderedToBit and BitToOrdered.
 HC_LogicalAddress parent(HC_LogicalAddress root)
          Gets the Parent of this node Algorithm:
1.
 byte[] toByteArray()
          Returns the byte array
 java.lang.String toString()
          Converts logical address object to String
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

ColexIndex

private int ColexIndex
The index of this node in the hypercube or HC_Node.MaxAddress() if unvalid.

GrayIndex

private int GrayIndex
The gray code encoding of ColexIndex

OrderingDone

private boolean OrderingDone
True if bitToOrdered and OrderedToBit have been set.

BitToOrdered

private int[] BitToOrdered
Permutation required to turn a neighborhood sorted by the bit flipped in the Gray index into a neighborhood table sorted by the Colex index.

OrderedToBit

private int[] OrderedToBit
Permutation required to turn a neighborhood sorted by Colex index into a neighborhood table sorted by the bit flipped in the Gray index.
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(HC_LogicalAddress laddr)
Constructs a new HC_LogicalAddress object from another HC_LogicalAddress
Parameters:
laddr - An object of type HC_LogicalAddress
Method Detail

convertGrayToColex

private int convertGrayToColex(int index)
Converts Gray index to Colex index
Parameters:
index - An integer which is supposed to represent the GrayIndex
Returns:
the corresponding ColexIndex

orderNeighborhood

private void orderNeighborhood()
Initializes the values of OrderedToBit and BitToOrdered.

flipNthBit

private HC_LogicalAddress flipNthBit(int i)
Flip the Nth bit of the gray code.

Algorithm: Takes the GrayIndex of the node itself, and flips the bit at which the neighbor differs from the node. It then builds the logical address of the neighbor using the appropriate constructor.

Parameters:
i - The bit in which the neighbor differs from the node. The nodes are numbered from 0 to 31
Returns:
HC_LogicalAddress object corresponding to Neigbor
Throws:
No - formal Exceptions raised; however, it exits if the Neighbor index is invalid.

getNthNeighbor

public 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(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 HC_LogicalAddress parent(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 HC_LogicalAddress[] children(HC_LogicalAddress root,
                                    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(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:
laddr - 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.
Overrides:
equals in class java.lang.Object

greaterThan

public boolean greaterThan(I_Address laddr)
Compares two HC_LogicalAddress objects

Algorithm:
Compares the ColexIndex of both nodes

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

getSize

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

toString

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