|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpqrtree.PQRTree
public class PQRTree
A PQR Tree over a set U is a rooted tree with four types of nodes - P, Q, R and leaves. PQR Tree is a compact way of storing and manipulating all the permutantion of n elements that keep consecutive the elements in certaing given sets. And encapsulates subsets where the consecutive ones fails by R nodes.
Field Summary | |
---|---|
private static int |
COLOR_BLACK
|
private static int |
COLOR_GRAY
|
private static int |
COLOR_WHITE
|
private Leaf[] |
leaves
|
private PQRNode |
root
|
private static int |
TYPE_PNODE
|
private static int |
TYPE_QNODE
|
private static int |
TYPE_RNODE
|
Constructor Summary | |
---|---|
PQRTree(java.lang.Object[] u)
Creates a universal PQRTree. |
|
PQRTree(java.lang.Object[] u,
int[][] c)
Creates a universal PQRTree. |
Method Summary | |
---|---|
void |
addSet(int[] s)
Changes the tree to keep consecutive the elements of the set s , if it's possible. |
private void |
adjustLCA(PQRNode w)
Adjusts the LCA according to its type. |
private void |
changePIntoQ(PQRNode v)
Changes the type of the node from P to Q. |
private void |
changeQIntoR(PQRNode w)
Changes a Q LCA with black children not consecutive into a R node. |
private PQRNode |
colorTree(int[] s)
Colors black the leaves corresponding to the elements of s, colors black, gray or keeps white the internal
nodes, and finds the Least Commons Ancestor. |
java.lang.String |
frontier()
Finds a valid permutation given the collection. |
private java.lang.String |
frontier(Node v)
Creates a string representing a valid permutation recursively. |
private PQRNode |
moveChildrenToGrayNode(PQRNode w,
PQRNode v)
A gray child of the LCA become the ancestor of its black and gray brother nodes. |
private void |
moveChildrenToLCA(PQRNode w,
PQRNode v)
Move the children from a gray node, child of the LCA, to the LCA. |
java.lang.String |
preOrder()
Represents the PQR tree in pre order way. |
private java.lang.String |
preOrder(Node v)
Creates a string representing the tree recursively. |
private void |
prepareLCA(PQRNode w)
Groups the black children of LCA into a new P node. |
private PQRNode |
preparePNode(PQRNode v)
Groups black children and white children into new P nodes. |
private PQRNode |
reduceTree(PQRNode w)
Repeatedly kills, merge, or uncolors gray nodes, sometimes also creating new nodes when needed, until no gray nodes remain in the tree. |
private void |
reverseGrayNode(PQRNode v)
Reverse a Q gray node, if its children isn't in the right order. |
private void |
uncolorTree(int[] s)
Uncolors all black nodes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private PQRNode root
private Leaf[] leaves
private static final int TYPE_PNODE
private static final int TYPE_QNODE
private static final int TYPE_RNODE
private static final int COLOR_WHITE
private static final int COLOR_GRAY
private static final int COLOR_BLACK
Constructor Detail |
---|
public PQRTree(java.lang.Object[] u)
u
- The universe set. Will be represented as leaves.public PQRTree(java.lang.Object[] u, int[][] c)
u
- The universe set. Will be represented as leaves.c
- The collection. A set of sets.PQRTree(Object[])
Method Detail |
---|
public void addSet(int[] s)
s
, if it's possible.
s
- Set of elements that must to be consecutive.private PQRNode colorTree(int[] s)
s, colors black, gray or keeps white the internal
nodes, and finds the Least Commons Ancestor.
- Parameters:
s
- Set of elements that must to be consecutive.
- Returns:
- The Least Common Ancestor.
private PQRNode reduceTree(PQRNode w)
w
- Least Common Ancestor
private void adjustLCA(PQRNode w)
w
- Least Common Ancestorprivate void uncolorTree(int[] s)
s
- Set of elements that must to be consecutive.private void prepareLCA(PQRNode w)
w
is a P node.
w
- Least Common Ancestorprivate PQRNode preparePNode(PQRNode v)
v
- A gray P node, child of the LCA.
private void changeQIntoR(PQRNode w)
w
- Least Common Ancestor of type Q.private void changePIntoQ(PQRNode v)
v
- A gray P node, child of the LCA.private void reverseGrayNode(PQRNode v)
v
- Q gray node.private PQRNode moveChildrenToGrayNode(PQRNode w, PQRNode v)
w
- Least Common Ancestor type P with
at most one black childv
- A Q node in right order or a R node,
gray child of the LCA.private void moveChildrenToLCA(PQRNode w, PQRNode v)
w
- Least Common Ancestor type Q, in right order
relative to the child v
, or type R.v
- Gray node type Q in right order or type R.public java.lang.String frontier()
private java.lang.String frontier(Node v)
v
- Node to be evaluated.
public java.lang.String preOrder()
private java.lang.String preOrder(Node v)
v
- Node to be evaluated.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |