// The function front scans the frontier of nodePtr. It returns the keys // of the leaves found in the frontier of nodePtr in a SListPure. // These keys include keys of direction indicators detected in the frontier. // // No direction is assigned to the direction indicators. // void EmbedPQTree::getFront( PQNode<edge,indInfo*,bool>* nodePtr, SListPure<PQBasicKey<edge,indInfo*,bool>*> &keys) { Stack<PQNode<edge,indInfo*,bool>*> S; S.push(nodePtr); while (!S.empty()) { PQNode<edge,indInfo*,bool> *checkNode = S.pop(); if (checkNode->type() == PQNodeRoot::leaf) keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) checkNode->getKey()); else { PQNode<edge,indInfo*,bool>* firstSon = 0; if (checkNode->type() == PQNodeRoot::PNode) { firstSon = checkNode->referenceChild(); } else if (checkNode->type() == PQNodeRoot::QNode) { firstSon = checkNode->getEndmost(RIGHT); // By this, we make sure that we start on the left side // since the left endmost child will be on top of the stack } if (firstSon->status() == INDICATOR) { keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) firstSon->getNodeInfo()); } else S.push(firstSon); PQNode<edge,indInfo*,bool> *nextSon = firstSon->getNextSib(0); PQNode<edge,indInfo*,bool> *oldSib = firstSon; while (nextSon && nextSon != firstSon) { if (nextSon->status() == INDICATOR) keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) nextSon->getNodeInfo()); else S.push(nextSon); PQNode<edge,indInfo*,bool> *holdSib = nextSon->getNextSib(oldSib); oldSib = nextSon; nextSon = holdSib; } } } }
// The function front scans the frontier of nodePtr. It returns the keys // of the leaves found in the frontier of nodePtr in a SListPure. // These keys include keys of direction indicators detected in the frontier. // // No direction is assigned to the direction indicators. // void EmbedPQTree::getFront( PQNode<edge,IndInfo*,bool>* nodePtr, SListPure<PQBasicKey<edge,IndInfo*,bool>*> &keys) { ArrayBuffer<PQNode<edge,IndInfo*,bool>*> S; S.push(nodePtr); while (!S.empty()) { PQNode<edge,IndInfo*,bool> *checkNode = S.popRet(); if (checkNode->type() == PQNodeRoot::PQNodeType::Leaf) keys.pushBack((PQBasicKey<edge,IndInfo*,bool>*) checkNode->getKey()); else { PQNode<edge,IndInfo*,bool>* firstSon = nullptr; if (checkNode->type() == PQNodeRoot::PQNodeType::PNode) { firstSon = checkNode->referenceChild(); } else if (checkNode->type() == PQNodeRoot::PQNodeType::QNode) { firstSon = checkNode->getEndmost(PQNodeRoot::SibDirection::Right); // By this, we make sure that we start on the left side // since the left endmost child will be on top of the stack } if (firstSon->status() == PQNodeRoot::PQNodeStatus::Indicator) { keys.pushBack((PQBasicKey<edge,IndInfo*,bool>*) firstSon->getNodeInfo()); } else S.push(firstSon); PQNode<edge,IndInfo*,bool> *nextSon = firstSon->getNextSib(nullptr); PQNode<edge,IndInfo*,bool> *oldSib = firstSon; while (nextSon && nextSon != firstSon) { if (nextSon->status() == PQNodeRoot::PQNodeStatus::Indicator) keys.pushBack((PQBasicKey<edge,IndInfo*,bool>*) nextSon->getNodeInfo()); else S.push(nextSon); PQNode<edge,IndInfo*,bool> *holdSib = nextSon->getNextSib(oldSib); oldSib = nextSon; nextSon = holdSib; } } } }
// The function front scans the frontier of nodePtr. It returns the keys // of the leaves found in the frontier of nodePtr in a SListPure. // These keys include keys of direction indicators detected in the frontier. // // CAREFUL: Funktion marks all full nodes for destruction. // Only to be used in connection with replaceRoot. // void EmbedPQTree::front( PQNode<edge,indInfo*,bool>* nodePtr, SListPure<PQBasicKey<edge,indInfo*,bool>*> &keys) { Stack<PQNode<edge,indInfo*,bool>*> S; S.push(nodePtr); while (!S.empty()) { PQNode<edge,indInfo*,bool> *checkNode = S.pop(); if (checkNode->type() == PQNodeRoot::leaf) keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) checkNode->getKey()); else { PQNode<edge,indInfo*,bool>* firstSon = 0; if (checkNode->type() == PQNodeRoot::PNode) { firstSon = checkNode->referenceChild(); } else if (checkNode->type() == PQNodeRoot::QNode) { firstSon = checkNode->getEndmost(RIGHT); // By this, we make sure that we start on the left side // since the left endmost child will be on top of the stack } if (firstSon->status() == INDICATOR) { keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) firstSon->getNodeInfo()); m_pertinentNodes->pushBack(firstSon); destroyNode(firstSon); } else S.push(firstSon); PQNode<edge,indInfo*,bool> *nextSon = firstSon->getNextSib(0); PQNode<edge,indInfo*,bool> *oldSib = firstSon; while (nextSon && nextSon != firstSon) { if (nextSon->status() == INDICATOR) { // Direction indicators point with their left sibling pointer // in the direction of their sequence. If an indicator is scanned // from the opposite direction, coming from its right sibling // the corresponding sequence must be reversed. if (oldSib == nextSon->getSib(LEFT)) //Direction changed nextSon->getNodeInfo()->userStructInfo()->changeDir = true; keys.pushBack((PQBasicKey<edge,indInfo*,bool>*) nextSon->getNodeInfo()); m_pertinentNodes->pushBack(nextSon); } else S.push(nextSon); PQNode<edge,indInfo*,bool> *holdSib = nextSon->getNextSib(oldSib); oldSib = nextSon; nextSon = holdSib; } } } }
void EmbedPQTree::ReplacePartialRoot( SListPure<PlanarLeafKey<indInfo*>*> &leafKeys, SListPure<PQBasicKey<edge,indInfo*,bool>*> &frontier, node v) { m_pertinentRoot->childCount(m_pertinentRoot->childCount() + 1 - fullChildren(m_pertinentRoot)->size()); PQNode<edge,indInfo*,bool> *predNode = 0; // dummy PQNode<edge,indInfo*,bool> *beginSequence = 0; // marks begin consecuitve seqeunce PQNode<edge,indInfo*,bool> *endSequence = 0; // marks end consecutive sequence PQNode<edge,indInfo*,bool> *beginInd = 0; // initially, marks direct sibling indicator // next to beginSequence not contained // in consectuive sequence // Get beginning and end of sequence. while (fullChildren(m_pertinentRoot)->size()) { PQNode<edge,indInfo*,bool> *currentNode = fullChildren(m_pertinentRoot)->popFrontRet(); if (!clientSibLeft(currentNode) || clientSibLeft(currentNode)->status() == EMPTY) { if (!beginSequence) { beginSequence = currentNode; predNode = clientSibLeft(currentNode); beginInd =PQTree<edge,indInfo*,bool>::clientSibLeft(currentNode); } else endSequence = currentNode; } else if (!clientSibRight(currentNode) || clientSibRight(currentNode)->status() == EMPTY ) { if (!beginSequence) { beginSequence = currentNode; predNode = clientSibRight(currentNode); beginInd =PQTree<edge,indInfo*,bool>::clientSibRight(currentNode); } else endSequence = currentNode; } } SListPure<PQBasicKey<edge,indInfo*,bool>*> partialFrontier; // Now scan the sequence of full nodes. Remove all of them but the last. // Call ReplaceFullRoot on the last one. // For every full node get its frontier. Scan intermediate indicators. PQNode<edge,indInfo*,bool> *currentNode = beginSequence; while (currentNode != endSequence) { PQNode<edge,indInfo*,bool>* nextNode = clientNextSib(currentNode,predNode); front(currentNode,partialFrontier); frontier.conc(partialFrontier); PQNode<edge,indInfo*,bool>* currentInd = PQTree<edge,indInfo*,bool>:: clientNextSib(currentNode,beginInd); // Scan for intermediate direction indicators. while (currentInd != nextNode) { PQNode<edge,indInfo*,bool> *nextInd = PQTree<edge,indInfo*,bool>:: clientNextSib(currentInd,currentNode); if (currentNode == currentInd->getSib(RIGHT)) //Direction changed currentInd->getNodeInfo()->userStructInfo()->changeDir = true; frontier.pushBack((PQBasicKey<edge,indInfo*,bool>*) currentInd->getNodeInfo()); removeChildFromSiblings(currentInd); m_pertinentNodes->pushBack(currentInd); currentInd = nextInd; } removeChildFromSiblings(currentNode); currentNode = nextNode; } currentNode->parent(m_pertinentRoot); m_pertinentRoot = currentNode; ReplaceFullRoot(leafKeys,partialFrontier,v,true,beginInd); frontier.conc(partialFrontier); }