Пример #1
0
 private PQNode arrange(PQNode node, boolean isRealPertinentRoot) {
   // this boolean value is for Q3 case only
   if (node.getNumFullLeaves() == 0) {
     node.setState(PQNode.State.EMPTY);
     return node;
   }
   List<PQNode> children = node.getChildren();
   ListIterator<PQNode> childItr = children.listIterator();
   while (childItr.hasNext()) {
     PQNode child = childItr.next();
     PQNode newChild = arrange(child, false);
     childItr.set(newChild);
   }
   return node.makeReduction(isRealPertinentRoot);
 }
Пример #2
0
 public PQNode findPertinentRoot(PQNode node) {
   if (node.isLeaf()) {
     if (node.getGraphNode() == myNodeToMerge) {
       node.setState(PQNode.State.FULL);
       node.setNumFullLeaves(1);
     } else {
       node.setState(PQNode.State.EMPTY);
       node.setNumFullLeaves(0);
     }
     return node;
   } else {
     PQNode pertinentRootCandidate = null;
     int numFullChildren = 0;
     int numEmptyChildren = 0;
     int numPartialChildren = 0;
     int numFullLeaves = 0;
     for (PQNode child : ListSequence.fromList(node.getChildren())) {
       PQNode childPertinentRoot = findPertinentRoot(child);
       numFullLeaves += child.getNumFullLeaves();
       if (child.getState() == PQNode.State.EMPTY) {
         numEmptyChildren++;
       } else {
         pertinentRootCandidate = childPertinentRoot;
         if (child.getState() == PQNode.State.FULL) {
           numFullChildren++;
         }
         if (child.getState() == PQNode.State.PARTIAL) {
           numPartialChildren++;
         }
       }
     }
     node.setNumFullLeaves(numFullLeaves);
     if (numPartialChildren > 0) {
       node.setState(PQNode.State.PARTIAL);
     } else {
       int numChildren = ListSequence.fromList(node.getChildren()).count();
       if (numFullChildren == numChildren) {
         node.setState(PQNode.State.FULL);
       } else if (numEmptyChildren == numChildren) {
         node.setState(PQNode.State.EMPTY);
       } else {
         node.setState(PQNode.State.PARTIAL);
       }
     }
     if (numPartialChildren + numFullChildren == 1) {
       return pertinentRootCandidate;
     } else {
       return node;
     }
   }
 }