diff options
| author | xXx-caillou-xXx | 2017-12-20 18:09:53 +0100 |
|---|---|---|
| committer | jvoisin | 2017-12-20 18:09:53 +0100 |
| commit | e7f541396715ee2895abcf73044b91ae9b746201 (patch) | |
| tree | ba0e9765e7f14f04b92585df1f3fcd1830ab4b00 /src/sp_list.c | |
| parent | 8d6cc4f2b63c3f0dc31fe6cecd34ac023ea1cccb (diff) | |
Better parsing of the rules
Thanks to this huge commit from @xXx-caillou-xXx, we can now write amazingly flexible rules.
Diffstat (limited to 'src/sp_list.c')
| -rw-r--r-- | src/sp_list.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/sp_list.c b/src/sp_list.c index c671f51..70d0ebe 100644 --- a/src/sp_list.c +++ b/src/sp_list.c | |||
| @@ -17,6 +17,34 @@ sp_node_t *sp_list_new() { | |||
| 17 | return new; | 17 | return new; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | // Thanks to https://en.wikipedia.org/wiki/Insertion_sort :> | ||
| 21 | sp_node_t *sp_list_sort(sp_node_t *pList, int (*cmp_func)(sp_node_t *, sp_node_t *)) { | ||
| 22 | sp_node_t *head = NULL; | ||
| 23 | |||
| 24 | if (pList == NULL || pList->next == NULL) { | ||
| 25 | return pList; | ||
| 26 | } | ||
| 27 | while (pList != NULL) { | ||
| 28 | sp_node_t *current = pList; | ||
| 29 | pList = pList->next; | ||
| 30 | if (head == NULL || 0 > cmp_func(current, head)) { | ||
| 31 | current->next = head; | ||
| 32 | head = current; | ||
| 33 | } else { | ||
| 34 | sp_node_t *p = head; | ||
| 35 | while (p != NULL) { | ||
| 36 | if (p->next == NULL || 0 > cmp_func(current, p->next)) { | ||
| 37 | current->next = p->next; | ||
| 38 | p->next = current; | ||
| 39 | break; | ||
| 40 | } | ||
| 41 | p = p->next; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | return head; | ||
| 46 | } | ||
| 47 | |||
| 20 | void sp_list_insert(sp_node_t *list, void *data) { | 48 | void sp_list_insert(sp_node_t *list, void *data) { |
| 21 | if (list->head == NULL) { | 49 | if (list->head == NULL) { |
| 22 | list->data = data; | 50 | list->data = data; |
