mergesort: rename it to llist_mergesort()

Even though the function is generic enough, <anything>sort() inherits connotations from the standard function qsort() that sorts an array. Rename it to llist_mergesort() and describe the external interface in its header file. This incidentally avoids name clashes with mergesort() some platforms declare in, and contaminate user namespace with, their <stdlib.h>. Reported-by: Brian Gernhardt Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 17, 2012 at 11:07 UTC 7365c95d2d67cbbb74c2040918d2ecde06231d93
4 files changed +19 -11
commit.c
+2 -2
@@ -429,8 +429,8 @@ static void commit_list_set_next(void *a, void *next)
429
430 void commit_list_sort_by_date(struct commit_list **list)
431 {
432 - *list = mergesort(*list, commit_list_get_next, commit_list_set_next,
433 - commit_list_compare_by_date);
432 + *list = llist_mergesort(*list, commit_list_get_next, commit_list_set_next,
433 + commit_list_compare_by_date);
434 }
435
436 struct commit *pop_most_recent_commit(struct commit_list **list,
mergesort.c
+4 -4
@@ -23,10 +23,10 @@ static void *pop_item(struct mergesort_sublist *l,
23 return p;
24 }
25
26 -void *mergesort(void *list,
27 - void *(*get_next_fn)(const void *),
28 - void (*set_next_fn)(void *, void *),
29 - int (*compare_fn)(const void *, const void *))
26 +void *llist_mergesort(void *list,
27 + void *(*get_next_fn)(const void *),
28 + void (*set_next_fn)(void *, void *),
29 + int (*compare_fn)(const void *, const void *))
30 {
31 unsigned long l;
32
mergesort.h
+12 -4
@@ -1,9 +1,17 @@
1 #ifndef MERGESORT_H
2 #define MERGESORT_H
3
4 -void *mergesort(void *list,
5 - void *(*get_next_fn)(const void *),
6 - void (*set_next_fn)(void *, void *),
7 - int (*compare_fn)(const void *, const void *));
4 +/*
5 + * Sort linked list in place.
6 + * - get_next_fn() returns the next element given an element of a linked list.
7 + * - set_next_fn() takes two elements A and B, and makes B the "next" element
8 + * of A on the list.
9 + * - compare_fn() takes two elements A and B, and returns negative, 0, positive
10 + * as the same sign as "subtracting" B from A.
11 + */
12 +void *llist_mergesort(void *list,
13 + void *(*get_next_fn)(const void *),
14 + void (*set_next_fn)(void *, void *),
15 + int (*compare_fn)(const void *, const void *));
16
17 #endif
test-mergesort.c
+1 -1
@@ -42,7 +42,7 @@ int main(int argc, const char **argv)
42 p = line;
43 }
44
45 - lines = mergesort(lines, get_next, set_next, compare_strings);
45 + lines = llist_mergesort(lines, get_next, set_next, compare_strings);
46
47 while (lines) {
48 printf("%s", lines->text);