Line data Source code
1 : // SPDX-License-Identifier: BSD-2-Clause 2 : // Copyright (C) 2010 Andrea Mazzoleni 3 : 4 : #include "tommylist.h" 5 : #include "tommychain.h" 6 : 7 : /** \internal 8 : * Setup a list. 9 : */ 10 2427 : tommy_inline void tommy_list_set(tommy_list* list, tommy_node* head, tommy_node* tail) 11 : { 12 2427 : head->prev = tail; 13 2427 : tail->next = 0; 14 2427 : *list = head; 15 2427 : } 16 : 17 3340 : TOMMY_API void tommy_list_sort(tommy_list* list, tommy_compare_func* cmp) 18 : { 19 : tommy_chain chain; 20 : tommy_node* head; 21 : 22 3340 : if (tommy_list_empty(list)) 23 913 : return; 24 : 25 2427 : head = tommy_list_head(list); 26 : 27 : /* create a chain from the list */ 28 2427 : chain.head = head; 29 2427 : chain.tail = head->prev; 30 : 31 2427 : tommy_chain_mergesort(&chain, cmp); 32 : 33 : /* restore the list */ 34 2427 : tommy_list_set(list, chain.head, chain.tail); 35 : } 36 :