From 19b21f006ffb14b3791d788f57c9fdc90093b183 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 24 Oct 2017 21:46:01 -0400 Subject: mq_tree_insert_sibling*(): Append rather than insert sibling --- (limited to 'src') 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); -- cgit v0.9.1