summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/rbtreereplace.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/score/src/rbtreereplace.c')
-rw-r--r--cpukit/score/src/rbtreereplace.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/cpukit/score/src/rbtreereplace.c b/cpukit/score/src/rbtreereplace.c
new file mode 100644
index 0000000000..7a54000854
--- /dev/null
+++ b/cpukit/score/src/rbtreereplace.c
@@ -0,0 +1,61 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreRBTree
+ *
+ * @brief _RBTree_Replace_node() implementation.
+ */
+
+/*
+ * Copyright (c) 2015 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/rbtree.h>
+
+void _RBTree_Replace_node(
+ RBTree_Control *the_rbtree,
+ RBTree_Node *victim,
+ RBTree_Node *replacement
+)
+{
+ RBTree_Node *parent = _RBTree_Parent( victim );
+ RBTree_Node **link;
+ RBTree_Node *child;
+
+ if (parent != NULL) {
+ if ( victim == _RBTree_Left( parent ) ) {
+ link = _RBTree_Left_reference( parent );
+ } else {
+ link = _RBTree_Right_reference( parent );
+ }
+ } else {
+ link = _RBTree_Root_reference( the_rbtree );
+ }
+ *link = replacement;
+
+ child = _RBTree_Left( victim );
+ if ( child != NULL ) {
+ RB_PARENT( child, Node ) = replacement;
+ }
+
+ child = _RBTree_Right( victim );
+ if ( child != NULL ) {
+ RB_PARENT( child, Node ) = replacement;
+ }
+
+ *replacement = *victim;
+}