本文整理汇总了C++中SplayTree::updateNode方法的典型用法代码示例。如果您正苦于以下问题:C++ SplayTree::updateNode方法的具体用法?C++ SplayTree::updateNode怎么用?C++ SplayTree::updateNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplayTree
的用法示例。
在下文中一共展示了SplayTree::updateNode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplayTreeSuccessor
static Tree SplayTreeSuccessor(SplayTree splay)
{
Tree oldRoot, newRoot;
AVERT(SplayTree, splay);
AVER(!SplayTreeIsEmpty(splay));
oldRoot = SplayTreeRoot(splay);
if (!TreeHasRight(oldRoot))
return TreeEMPTY; /* No successor */
/* temporarily chop off the left half-tree, inclusive of root */
SplayTreeSetRoot(splay, TreeRight(oldRoot));
TreeSetRight(oldRoot, TreeEMPTY);
(void)SplaySplay(splay, NULL, compareLess);
newRoot = SplayTreeRoot(splay);
AVER(newRoot != TreeEMPTY);
AVER(TreeLeft(newRoot) == TreeEMPTY);
TreeSetLeft(newRoot, oldRoot);
splay->updateNode(splay, oldRoot);
splay->updateNode(splay, newRoot);
return newRoot;
}
示例2: SplayFindFirst
Bool SplayFindFirst(Tree *nodeReturn, SplayTree splay,
SplayTestNodeFunction testNode,
SplayTestTreeFunction testTree,
void *closureP, Size closureS)
{
SplayFindClosureStruct closureStruct;
Bool found;
AVER(nodeReturn != NULL);
AVERT(SplayTree, splay);
AVER(FUNCHECK(testNode));
AVER(FUNCHECK(testTree));
if (SplayTreeIsEmpty(splay) ||
!testTree(splay, SplayTreeRoot(splay), closureP, closureS))
return FALSE; /* no suitable nodes in tree */
closureStruct.p = closureP;
closureStruct.s = closureS;
closureStruct.testNode = testNode;
closureStruct.testTree = testTree;
closureStruct.splay = splay;
closureStruct.found = FALSE;
found = SplaySplay(splay, &closureStruct,
SplayFindFirstCompare) == CompareEQUAL &&
closureStruct.found;
while (!found) {
Tree oldRoot, newRoot;
/* FIXME: Rename to "seen" and "not yet seen" or something. */
oldRoot = SplayTreeRoot(splay);
newRoot = TreeRight(oldRoot);
if (newRoot == TreeEMPTY || !(*testTree)(splay, newRoot, closureP, closureS))
return FALSE; /* no suitable nodes in the rest of the tree */
/* Temporarily chop off the left half-tree, inclusive of root,
so that the search excludes any nodes we've seen already. */
SplayTreeSetRoot(splay, newRoot);
TreeSetRight(oldRoot, TreeEMPTY);
found = SplaySplay(splay, &closureStruct,
SplayFindFirstCompare) == CompareEQUAL &&
closureStruct.found;
/* Restore the left tree, then rotate left so that the node we
just splayed is at the root. Update both. */
newRoot = SplayTreeRoot(splay);
TreeSetRight(oldRoot, newRoot);
SplayTreeSetRoot(splay, oldRoot);
TreeRotateLeft(&splay->root);
splay->updateNode(splay, oldRoot);
splay->updateNode(splay, newRoot);
}
*nodeReturn = SplayTreeRoot(splay);
return TRUE;
}
示例3: SplayNodeInit
void SplayNodeInit(SplayTree splay, Tree node)
{
AVERT(SplayTree, splay);
AVERT(Tree, node);
AVER(!TreeHasLeft(node)); /* otherwise, call SplayNodeRefresh */
AVER(!TreeHasRight(node)); /* otherwise, call SplayNodeRefresh */
splay->updateNode(splay, node);
}
示例4: SplayFindLast
Bool SplayFindLast(Tree *nodeReturn, SplayTree splay,
SplayTestNodeFunction testNode,
SplayTestTreeFunction testTree,
void *testClosure)
{
SplayFindClosureStruct closureStruct;
Bool found;
AVER_CRITICAL(nodeReturn != NULL);
AVERT_CRITICAL(SplayTree, splay);
AVER_CRITICAL(FUNCHECK(testNode));
AVER_CRITICAL(FUNCHECK(testTree));
if (SplayTreeIsEmpty(splay) ||
!testTree(splay, SplayTreeRoot(splay), testClosure))
return FALSE; /* no suitable nodes in tree */
closureStruct.testClosure = testClosure;
closureStruct.testNode = testNode;
closureStruct.testTree = testTree;
closureStruct.splay = splay;
found = SplaySplay(splay, &closureStruct,
SplayFindLastCompare) == CompareEQUAL &&
closureStruct.found;
while (!found) {
Tree oldRoot, newRoot;
oldRoot = SplayTreeRoot(splay);
newRoot = TreeLeft(oldRoot);
if (newRoot == TreeEMPTY || !(*testTree)(splay, newRoot, testClosure))
return FALSE; /* no suitable nodes in the rest of the tree */
/* Temporarily chop off the right half-tree, inclusive of root,
so that the search excludes any nodes we've seen already. */
SplayTreeSetRoot(splay, newRoot);
TreeSetLeft(oldRoot, TreeEMPTY);
found = SplaySplay(splay, &closureStruct,
SplayFindLastCompare) == CompareEQUAL &&
closureStruct.found;
/* Restore the right tree, then rotate right so that the node we
just splayed is at the root. Update both. */
newRoot = SplayTreeRoot(splay);
TreeSetLeft(oldRoot, newRoot);
SplayTreeSetRoot(splay, oldRoot);
TreeRotateRight(&splay->root);
splay->updateNode(splay, oldRoot);
splay->updateNode(splay, newRoot);
}
*nodeReturn = SplayTreeRoot(splay);
return TRUE;
}
示例5: SplayDebugUpdate
void SplayDebugUpdate(SplayTree splay, Tree tree)
{
AVERT(SplayTree, splay);
AVERT(Tree, tree);
if (tree == TreeEMPTY)
return;
SplayDebugUpdate(splay, TreeLeft(tree));
SplayDebugUpdate(splay, TreeRight(tree));
splay->updateNode(splay, tree);
}
示例6: SplayTreeInsert
Bool SplayTreeInsert(SplayTree splay, Tree node)
{
Tree neighbour;
AVERT(SplayTree, splay);
AVERT(Tree, node);
AVER(TreeLeft(node) == TreeEMPTY);
AVER(TreeRight(node) == TreeEMPTY);
if (SplayTreeIsEmpty(splay)) {
SplayTreeSetRoot(splay, node);
return TRUE;
}
switch (SplaySplay(splay, splay->nodeKey(node), splay->compare)) {
default:
NOTREACHED;
/* fall through */
case CompareEQUAL: /* duplicate node */
return FALSE;
case CompareGREATER: /* left neighbour is at root */
neighbour = SplayTreeRoot(splay);
SplayTreeSetRoot(splay, node);
TreeSetRight(node, TreeRight(neighbour));
TreeSetLeft(node, neighbour);
TreeSetRight(neighbour, TreeEMPTY);
break;
case CompareLESS: /* right neighbour is at root */
neighbour = SplayTreeRoot(splay);
SplayTreeSetRoot(splay, node);
TreeSetLeft(node, TreeLeft(neighbour));
TreeSetRight(node, neighbour);
TreeSetLeft(neighbour, TreeEMPTY);
break;
}
splay->updateNode(splay, neighbour);
splay->updateNode(splay, node);
return TRUE;
}
示例7: SplayUpdateRightSpine
static Tree SplayUpdateRightSpine(SplayTree splay, Tree node, Tree child)
{
AVERT_CRITICAL(SplayTree, splay);
AVERT_CRITICAL(Tree, node);
AVERT_CRITICAL(Tree, child);
while (node != TreeEMPTY) {
Tree parent = TreeRight(node);
TreeSetRight(node, child); /* un-reverse pointer */
splay->updateNode(splay, node);
child = node;
node = parent;
}
return child;
}
示例8: SplayNodeRefresh
void SplayNodeRefresh(SplayTree splay, Tree node)
{
Compare cmp;
AVERT(SplayTree, splay);
AVERT(Tree, node);
AVER(!SplayTreeIsEmpty(splay)); /* must contain node, at least */
cmp = SplaySplay(splay, splay->nodeKey(node), splay->compare);
AVER(cmp == CompareEQUAL);
AVER(SplayTreeRoot(splay) == node);
splay->updateNode(splay, node);
}
示例9: SplayAssembleRev
static void SplayAssembleRev(SplayTree splay, SplayState state)
{
Tree left, right;
AVERT(SplayTree, splay);
AVER(state->middle != TreeEMPTY);
left = TreeLeft(state->middle);
left = SplayUpdateRightSpine(splay, state->leftLast, left);
TreeSetLeft(state->middle, left);
right = TreeRight(state->middle);
right = SplayUpdateLeftSpine(splay, state->rightFirst, right);
TreeSetRight(state->middle, right);
splay->updateNode(splay, state->middle);
}
示例10: SplayTreeDelete
Bool SplayTreeDelete(SplayTree splay, Tree node)
{
Tree leftLast;
Compare cmp;
AVERT(SplayTree, splay);
AVERT(Tree, node);
if (SplayTreeIsEmpty(splay))
return FALSE;
cmp = SplaySplay(splay, splay->nodeKey(node), splay->compare);
AVER(cmp != CompareEQUAL || SplayTreeRoot(splay) == node);
if (cmp != CompareEQUAL) {
return FALSE;
} else if (!TreeHasLeft(node)) {
SplayTreeSetRoot(splay, TreeRight(node));
TreeClearRight(node);
} else if (!TreeHasRight(node)) {
SplayTreeSetRoot(splay, TreeLeft(node));
TreeClearLeft(node);
} else {
Tree rightHalf = TreeRight(node);
TreeClearRight(node);
SplayTreeSetRoot(splay, TreeLeft(node));
TreeClearLeft(node);
(void)SplaySplay(splay, NULL, compareGreater);
leftLast = SplayTreeRoot(splay);
AVER(leftLast != TreeEMPTY);
AVER(!TreeHasRight(leftLast));
TreeSetRight(leftLast, rightHalf);
splay->updateNode(splay, leftLast);
}
TreeFinish(node);
return TRUE;
}
示例11: SplaySplitRev
static Compare SplaySplitRev(SplayStateStruct *stateReturn,
SplayTree splay, TreeKey key,
TreeCompareFunction compare)
{
Tree middle, leftLast, rightFirst;
Compare cmp;
AVERT(SplayTree, splay);
AVER(FUNCHECK(compare));
AVER(!SplayTreeIsEmpty(splay));
leftLast = TreeEMPTY;
rightFirst = TreeEMPTY;
middle = SplayTreeRoot(splay);
for (;;) {
cmp = compare(middle, key);
switch(cmp) {
default:
NOTREACHED;
/* defensive fall-through */
case CompareEQUAL:
goto stop;
case CompareLESS:
if (!TreeHasLeft(middle))
goto stop;
middle = SplayZigRev(middle, &rightFirst);
cmp = compare(middle, key);
switch(cmp) {
default:
NOTREACHED;
/* defensive fall-through */
case CompareEQUAL:
goto stop;
case CompareLESS:
if (!TreeHasLeft(middle))
goto stop;
middle = SplayZigZigRev(middle, &rightFirst);
splay->updateNode(splay, TreeRight(rightFirst));
break;
case CompareGREATER:
if (!TreeHasRight(middle))
goto stop;
middle = SplayZagRev(middle, &leftLast);
break;
}
break;
case CompareGREATER:
if (!TreeHasRight(middle))
goto stop;
middle = SplayZagRev(middle, &leftLast);
cmp = compare(middle, key);
switch(cmp) {
default:
NOTREACHED;
/* defensive fall-through */
case CompareEQUAL:
goto stop;
case CompareGREATER:
if (!TreeHasRight(middle))
goto stop;
middle = SplayZagZagRev(middle, &leftLast);
splay->updateNode(splay, TreeLeft(leftLast));
break;
case CompareLESS:
if (!TreeHasLeft(middle))
goto stop;
middle = SplayZigRev(middle, &rightFirst);
break;
}
break;
}
}
stop:
stateReturn->middle = middle;
stateReturn->leftLast = leftLast;
stateReturn->rightFirst = rightFirst;
return cmp;
}