mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Unifying splaycomparemethod with treecompare.
Copied from Perforce Change: 184428 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
a6d87c91a8
commit
27373efc5c
4 changed files with 21 additions and 22 deletions
|
|
@ -104,7 +104,7 @@ static Bool CBSBlockCheck(CBSBlock block)
|
|||
* See <design/splay/#type.splay.compare.method>
|
||||
*/
|
||||
|
||||
static Compare cbsCompare(void *key, Tree node)
|
||||
static Compare cbsCompare(Tree node, void *key)
|
||||
{
|
||||
Addr base1, base2, limit2;
|
||||
CBSBlock cbsBlock;
|
||||
|
|
@ -213,7 +213,8 @@ Res CBSInit(Arena arena, CBS cbs, void *owner, Align alignment,
|
|||
if (ArgPick(&arg, args, MPS_KEY_CBS_EXTEND_BY))
|
||||
extendBy = arg.val.size;
|
||||
|
||||
SplayTreeInit(treeOfCBS(cbs), &cbsCompare,
|
||||
SplayTreeInit(treeOfCBS(cbs),
|
||||
cbsCompare,
|
||||
fastFind ? cbsUpdateNode : SplayTrivUpdate);
|
||||
MPS_ARGS_BEGIN(pcArgs) {
|
||||
MPS_ARGS_ADD(pcArgs, MPS_KEY_MFS_UNIT_SIZE, sizeof(CBSBlockStruct));
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ static void TagTrivInit(void* tag, va_list args)
|
|||
|
||||
/* TagComp -- splay comparison function for address ordering of tags */
|
||||
|
||||
static Compare TagComp(void *key, Tree node)
|
||||
static Compare TagCompare(Tree node, void *key)
|
||||
{
|
||||
Addr addr1, addr2;
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ static Res DebugPoolInit(Pool pool, ArgList args)
|
|||
if (res != ResOK)
|
||||
goto tagFail;
|
||||
debug->missingTags = 0;
|
||||
SplayTreeInit(&debug->index, TagComp, SplayTrivUpdate);
|
||||
SplayTreeInit(&debug->index, TagCompare, SplayTrivUpdate);
|
||||
}
|
||||
|
||||
debug->sig = PoolDebugMixinSig;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ SRCID(splay, "$Id$");
|
|||
#define SplayTreeRoot(t) RVALUE((t)->root)
|
||||
#define SplayTreeSetRoot(t, r) BEGIN ((t)->root = (r)); END
|
||||
|
||||
#define SplayCompare(tree, key, node) \
|
||||
(((tree)->compare)((key), (node)))
|
||||
#define SplayCompare(tree, key, node) (((tree)->compare)(node, key))
|
||||
|
||||
|
||||
Bool SplayTreeCheck(SplayTree tree)
|
||||
|
|
@ -39,7 +38,8 @@ Bool SplayTreeCheck(SplayTree tree)
|
|||
}
|
||||
|
||||
|
||||
void SplayTreeInit(SplayTree tree, SplayCompareMethod compare,
|
||||
void SplayTreeInit(SplayTree tree,
|
||||
TreeCompare compare,
|
||||
SplayUpdateNodeMethod updateNode)
|
||||
{
|
||||
AVER(tree != NULL);
|
||||
|
|
@ -283,7 +283,7 @@ static void SplayAssemble(SplayTree tree, Tree top,
|
|||
*/
|
||||
|
||||
static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
||||
void *key, SplayCompareMethod compareMethod) {
|
||||
void *key, TreeCompare compare) {
|
||||
/* The sides structure avoids a boundary case in SplayLink* */
|
||||
TreeStruct sides; /* rightTop and leftTop */
|
||||
Tree top, leftLast, rightFirst;
|
||||
|
|
@ -292,7 +292,7 @@ static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
|||
|
||||
AVERT(SplayTree, tree);
|
||||
AVER(nodeReturn != NULL);
|
||||
AVER(FUNCHECK(compareMethod));
|
||||
AVER(FUNCHECK(compare));
|
||||
|
||||
top = SplayTreeRoot(tree); /* will be copied back at end */
|
||||
|
||||
|
|
@ -302,7 +302,7 @@ static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
|||
}
|
||||
|
||||
/* short-circuit case where node is already top */
|
||||
compareTop = (*compareMethod)(key, top);
|
||||
compareTop = compare(top, key);
|
||||
if (compareTop == CompareEQUAL) {
|
||||
*nodeReturn = top;
|
||||
return TRUE;
|
||||
|
|
@ -322,7 +322,7 @@ static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
|||
found = FALSE;
|
||||
goto assemble;
|
||||
} else {
|
||||
Compare compareTopLeft = (*compareMethod)(key, topLeft);
|
||||
Compare compareTopLeft = compare(topLeft, key);
|
||||
|
||||
switch(compareTopLeft) {
|
||||
|
||||
|
|
@ -359,7 +359,7 @@ static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
|||
found = FALSE;
|
||||
goto assemble;
|
||||
} else {
|
||||
Compare compareTopRight = (*compareMethod)(key, topRight);
|
||||
Compare compareTopRight = compare(topRight, key);
|
||||
|
||||
switch(compareTopRight) {
|
||||
|
||||
|
|
@ -399,7 +399,7 @@ static Bool SplaySplay(Tree *nodeReturn, SplayTree tree,
|
|||
NOTREACHED;
|
||||
} break;
|
||||
}
|
||||
compareTop = (*compareMethod)(key, top);
|
||||
compareTop = compare(top, key);
|
||||
} /* end while(TRUE) */
|
||||
|
||||
terminalZig:
|
||||
|
|
@ -750,7 +750,7 @@ typedef struct {
|
|||
SplayTree tree;
|
||||
} SplayFindClosureStruct, *SplayFindClosure;
|
||||
|
||||
static Compare SplayFindFirstCompare(void *key, Tree node)
|
||||
static Compare SplayFindFirstCompare(Tree node, void *key)
|
||||
{
|
||||
SplayFindClosure closure;
|
||||
void *closureP;
|
||||
|
|
@ -781,7 +781,7 @@ static Compare SplayFindFirstCompare(void *key, Tree node)
|
|||
}
|
||||
}
|
||||
|
||||
static Compare SplayFindLastCompare(void *key, Tree node)
|
||||
static Compare SplayFindLastCompare(Tree node, void *key)
|
||||
{
|
||||
SplayFindClosure closure;
|
||||
void *closureP;
|
||||
|
|
@ -849,8 +849,7 @@ Bool SplayFindFirst(Tree *nodeReturn, SplayTree tree,
|
|||
closureStruct.testTree = testTree;
|
||||
closureStruct.tree = tree;
|
||||
|
||||
if (SplaySplay(&node, tree, (void *)&closureStruct,
|
||||
&SplayFindFirstCompare)) {
|
||||
if (SplaySplay(&node, tree, (void *)&closureStruct, SplayFindFirstCompare)) {
|
||||
*nodeReturn = node;
|
||||
return TRUE;
|
||||
} else {
|
||||
|
|
@ -885,8 +884,7 @@ Bool SplayFindLast(Tree *nodeReturn, SplayTree tree,
|
|||
closureStruct.testTree = testTree;
|
||||
closureStruct.tree = tree;
|
||||
|
||||
if (SplaySplay(&node, tree, (void *)&closureStruct,
|
||||
&SplayFindLastCompare)) {
|
||||
if (SplaySplay(&node, tree, (void *)&closureStruct, SplayFindLastCompare)) {
|
||||
*nodeReturn = node;
|
||||
return TRUE;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
typedef struct SplayTreeStruct *SplayTree;
|
||||
|
||||
typedef Compare (*SplayCompareMethod)(void *key, Tree node);
|
||||
typedef Bool (*SplayTestNodeMethod)(SplayTree tree, Tree node,
|
||||
void *closureP, Size closureS);
|
||||
typedef Bool (*SplayTestTreeMethod)(SplayTree tree, Tree node,
|
||||
|
|
@ -26,14 +25,15 @@ typedef void (*SplayUpdateNodeMethod)(SplayTree tree, Tree node);
|
|||
extern void SplayTrivUpdate(SplayTree tree, Tree node);
|
||||
|
||||
typedef struct SplayTreeStruct {
|
||||
SplayCompareMethod compare;
|
||||
TreeCompare compare;
|
||||
SplayUpdateNodeMethod updateNode;
|
||||
Tree root;
|
||||
} SplayTreeStruct;
|
||||
|
||||
|
||||
extern Bool SplayTreeCheck(SplayTree tree);
|
||||
extern void SplayTreeInit(SplayTree tree, SplayCompareMethod compare,
|
||||
extern void SplayTreeInit(SplayTree tree,
|
||||
TreeCompare compare,
|
||||
SplayUpdateNodeMethod updateNode);
|
||||
extern void SplayTreeFinish(SplayTree tree);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue