本文整理汇总了C++中SplayTree::nodeKey方法的典型用法代码示例。如果您正苦于以下问题:C++ SplayTree::nodeKey方法的具体用法?C++ SplayTree::nodeKey怎么用?C++ SplayTree::nodeKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplayTree
的用法示例。
在下文中一共展示了SplayTree::nodeKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}