diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2021-10-16 21:50:40 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-03-30 22:31:30 +0200 |
commit | e5fa9d585ed090602bcc045689046702199def86 (patch) | |
tree | 2b391a68d67972686db86f5d44a90a416695c058 /lib/fstree/fstree_sort.c | |
parent | 5e54880a2db2aeb7a6c301a69ee2bef9a09a237f (diff) |
Cleanup: remove node sorting from libfstree
Always insert the tree nodes in the correct oder and remove the
post-process sorting step.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstree/fstree_sort.c')
-rw-r--r-- | lib/fstree/fstree_sort.c | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/lib/fstree/fstree_sort.c b/lib/fstree/fstree_sort.c deleted file mode 100644 index 58ffadf..0000000 --- a/lib/fstree/fstree_sort.c +++ /dev/null @@ -1,60 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * fstree_sort.c - * - * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> - * Copyright (C) 2019 Zachary Dremann <dremann@gmail.com> - */ -#include "internal.h" - -#include <string.h> - -static tree_node_t *merge(tree_node_t *lhs, tree_node_t *rhs) -{ - tree_node_t *it; - tree_node_t *head = NULL; - tree_node_t **next_ptr = &head; - - while (lhs != NULL && rhs != NULL) { - if (strcmp(lhs->name, rhs->name) <= 0) { - it = lhs; - lhs = lhs->next; - } else { - it = rhs; - rhs = rhs->next; - } - - *next_ptr = it; - next_ptr = &it->next; - } - - it = (lhs != NULL ? lhs : rhs); - *next_ptr = it; - return head; -} - -tree_node_t *tree_node_list_sort(tree_node_t *head) -{ - tree_node_t *it, *half, *prev; - - it = half = prev = head; - while (it != NULL) { - prev = half; - half = half->next; - it = it->next; - if (it != NULL) { - it = it->next; - } - } - - // half refers to the (count/2)'th element ROUNDED UP. - // It will be null therefore only in the empty and the - // single element list - if (half == NULL) { - return head; - } - - prev->next = NULL; - - return merge(tree_node_list_sort(head), tree_node_list_sort(half)); -} |