- Add support of ORF P4 Irdeto mode
[oscam.git] / tommyDS_hashlin / tommylist.c
blob1fa1f243766f20baee44a5fec2269b64bac3edd3
1 /*
2 * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 #include "tommylist.h"
29 #include "tommychain.h"
31 /** \internal
32 * Setup a list.
34 tommy_inline void tommy_list_set(tommy_list* list, tommy_node* head, tommy_node* tail)
36 head->prev = tail;
37 tail->next = 0;
38 *list = head;
41 void tommy_list_sort(tommy_list* list, tommy_compare_func* cmp)
43 tommy_chain chain;
44 tommy_node* head;
46 if (tommy_list_empty(list))
47 return;
49 head = tommy_list_head(list);
51 /* create a chain from the list */
52 chain.head = head;
53 chain.tail = head->prev;
55 tommy_chain_mergesort(&chain, cmp);
57 /* restore the list */
58 tommy_list_set(list, chain.head, chain.tail);