From c986d35c0ad800f09c39bcd6ac60504efd39a18f Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Wed, 9 Nov 2005 02:16:03 +0000 Subject: [PATCH] - Implement most of RtlDelete. svn path=/trunk/; revision=19082 --- reactos/lib/rtl/splaytree.c | 84 +++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/reactos/lib/rtl/splaytree.c b/reactos/lib/rtl/splaytree.c index ab81a43eb66..3bdbef815ae 100644 --- a/reactos/lib/rtl/splaytree.c +++ b/reactos/lib/rtl/splaytree.c @@ -16,16 +16,86 @@ /* FUNCTIONS ***************************************************************/ /* -* @unimplemented -*/ + * @implemented + */ PRTL_SPLAY_LINKS NTAPI -RtlDelete ( - PRTL_SPLAY_LINKS Links - ) +RtlDelete(PRTL_SPLAY_LINKS Links) { - UNIMPLEMENTED; - return 0; + PRTL_SPLAY_LINKS N, P, C, SP; + N = Links; + + /* Check if we have two children */ + if ((RtlLeftChild(N)) && (RtlRightChild(N))) + { + /* Get the predecessor */ + SP = RtlSubtreePredecessor(N); + + /* Swap it with N, this will guarantee that N will have only a child */ + //SwapSplayLinks(SP, N); + DPRINT1("UNIMPLEMENTED!\n"); + } + + /* Check if we have no children */ + if (!(RtlLeftChild(N)) && !(RtlRightChild(N))) + { + /* If we are also the root, then the tree is gone */ + return NULL; + + /* Get our parent */ + P = RtlParent(N); + + /* Find out who is referencing us and delete the reference */ + if (RtlIsLeftChild(N)) + { + /* N was a left child, so erase its parent's left child link */ + RtlLeftChild(RtlParent(N)) = NULL; + } + else + { + /* N was a right child, so erase its parent's right child link */ + RtlRightChild(RtlParent(N)) = NULL; + } + + /* And finally splay the parent */ + return RtlSplay(P); + } + + /* If we got here, we have a child (not two: we swapped above!) */ + if (RtlLeftChild(N)) + { + /* We have a left child, so get it */ + C = RtlLeftChild(N); + } + else + { + /* We have a right child, get him instead */ + C = RtlRightChild(N); + } + + /* Check if we are the root entry */ + if (RtlIsRoot(N)) + { + /* Our child is now root, return him */ + C->Parent = C; + return C; + } + + /* Find out who is referencing us and link to our child instead */ + if (RtlIsLeftChild(N)) + { + /* N was a left child, so set its parent's left child as our child */ + RtlLeftChild(RtlParent(N)) = C; + } + else + { + /* N was a right child, so set its parent's right child as our child */ + RtlRightChild(RtlParent(N)) = C; + } + + /* Finally, inherit our parent and splay the parent */ + C->Parent = N->Parent; + return RtlSplay(RtlParent(C)); } /*