aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-05-21 11:38:35 +0000
committerJoursoir <chat@joursoir.net>2021-05-21 11:38:35 +0000
commitdb09381d5e5f175ee3191e519cf8b9715ab56f5a (patch)
treede33ce66e9f08619e22fd45e1b6b2ab7461c5efd
parent4ca2bf5424307cd83dfc01d3a0e05ec6a194ae6b (diff)
downloadctimeline-db09381d5e5f175ee3191e519cf8b9715ab56f5a.tar.gz
ctimeline-db09381d5e5f175ee3191e519cf8b9715ab56f5a.tar.bz2
ctimeline-db09381d5e5f175ee3191e519cf8b9715ab56f5a.zip
ctimeline: use quick instead of bubble sort for branches
-rw-r--r--ctimeline.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/ctimeline.c b/ctimeline.c
index e09887c..d052b4c 100644
--- a/ctimeline.c
+++ b/ctimeline.c
@@ -43,24 +43,23 @@ static void forget_context()
free(ctx.branches.list);
}
-void sort_branches_by_age()
+static int cmp_by_age(const void *f, const void *s)
{
- int i, j;
- struct ctimeline_branch *i_ptr, *j_ptr;
- struct ctimeline_branch tmp;
+ struct ctimeline_branch *b1 = (struct ctimeline_branch *)f;
+ struct ctimeline_branch *b2 = (struct ctimeline_branch *)s;
- for(i = 0; i < ctx.branches.count; i++) {
- i_ptr = &ctx.branches.list[i];
- for(j = i+1; j < ctx.branches.count; j++) {
- j_ptr = &ctx.branches.list[j];
- if((j_ptr->age_from > i_ptr->age_from) ||
- (j_ptr->age_to > i_ptr->age_to) ) {
- tmp = *i_ptr;
- *i_ptr = *j_ptr;
- *j_ptr = tmp;
- }
- }
+ if(b2->age_to == b1->age_to) {
+ return b2->age_from - b1->age_from;
}
+ else
+ return b2->age_to - b1->age_to;
+}
+
+void sort_branches_by_age()
+{
+ qsort(ctx.branches.list,
+ ctx.branches.count, sizeof(struct ctimeline_branch),
+ cmp_by_age);
}
struct ctimeline_branch *add_branch(const char *name)
@@ -192,6 +191,7 @@ int main(int argc, char **argv)
{
prepare_context();
parse_config_file(CTIMELINE_CONFIG);
+ sort_branches_by_age();
print_http_headers();
print_document_start();