RBTNode* RBT_SearchNode(RBTNode* Tree, ElementType Target) { if (Tree == Nil) return NULL; if (Tree->Data > Target) return RBT_SearchNode(Tree->Left, Target); else if (Tree->Data < Target) return RBT_SearchNode(Tree->Right, Target); else return Tree; }
craftIk_session* craftIk_session_get( int sockfd ) { RBTNode* nodeget = RBT_SearchNode( sessions, sockfd ); if( nodeget == NULL ){ #ifdef DEBUG fprintf(stderr,"[DEBUG] no node found to get : fd(%d)\n", sockfd ); #endif return NULL; } else { return (craftIk_session*)nodeget->data; } }
RBTNode* RBT_RemoveNode(RBTNode** Root, ElementType Data) { RBTNode* Removed = NULL; RBTNode* Successor = NULL; RBTNode* Target = RBT_SearchNode((*Root), Data); if (Target == NULL) return NULL; if (Target->Left == Nil || Target->Right == Nil) { Removed = Target; } else { Removed = RBT_SearchMinNode(Target->Right); Target->Data = Removed->Data; } if (Removed->Left != Nil) Successor = Removed->Left; else Successor = Removed->Right; Successor->Parent = Removed->Parent; if (Removed->Parent == NULL) (*Root) = Successor; else { if (Removed == Removed->Parent->Left) Removed->Parent->Left = Successor; else Removed->Parent->Right = Successor; } if (Removed->Color == BLACK) RBT_RebuildAfterRemove(Root, Successor); return Removed; }