summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tree.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/tree.c b/src/tree.c
index c3e2323..2db3449 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -156,22 +156,21 @@ mq_tree_insert_sibling_allocated(MqTree *node, MqTree *sibling, gpointer data)
node->root = sibling->root;
node->parent = sibling->parent;
- /* Link to next sibling, if any. */
- if (sibling->next) {
- node->next = sibling->next;
- sibling->next->prev = node;
+ /* Link new node and parent's last child. */
+ node->prev = node->parent->last_child;
+ if (node->prev) {
+ node->prev->next = node;
}
- /* Link to previous sibling. */
- node->prev = sibling;
- sibling->next = node;
+ /* Set parent's new last child. */
+ node->parent->last_child = node;
+
+ node->position = node->parent->position + node->parent->size - 1;
+ update_positions(node, 1);
node->size = 0;
update_sizes(node, 1);
- node->position = sibling->position + sibling->size - 1;
- update_positions(node, 1);
-
node->data = data;
print_tree("Inserted sibling", node);