From 9cc507553125982990e02472bd57d6a653a54884 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 11 Dec 2024 13:59:57 +0100 Subject: [PATCH] modified: src/planner.c modified: src/planner.h modified: src/test.c --- src/planner.c | 15 +++++++++++++-- src/planner.h | 3 ++- src/test.c | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/planner.c b/src/planner.c index 81046a5..a069141 100644 --- a/src/planner.c +++ b/src/planner.c @@ -69,13 +69,24 @@ char *taskToStr(Task *t) { } // for llist -int cmpTask(void *a, void *b) { + +// compare task by name +int cmpTaskN(void *a, void *b) { Task *aa = (Task *)a; Task *bb = (Task *)b; return strcmp(aa->name, bb->name); } + +// compare task by priority +int cmpTaskP(void *a, void *b) { + Task *aa = (Task *)a; + Task *bb = (Task *)b; + return aa->priority - bb->priority; +} + +// cmp event by task name int cmpEvent(void *a, void *b) { Event *aa = (Event *)a; Event *bb = (Event *)b; - return cmpTask(aa->task, bb->task); + return cmpTaskN(aa->task, bb->task); } diff --git a/src/planner.h b/src/planner.h index c6aab1c..2f94461 100644 --- a/src/planner.h +++ b/src/planner.h @@ -29,7 +29,8 @@ Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp); /* * compare function for Task */ -int cmpTask(void *a, void *b); +int cmpTaskN(void *a, void *b); +int cmpTaskP(void *a, void *b); /* * return allocated string representation of Task diff --git a/src/test.c b/src/test.c index 305c7ca..9ac3dba 100644 --- a/src/test.c +++ b/src/test.c @@ -22,7 +22,7 @@ int main() { printf("%s\n", ctime(&now)); // new llist test - llist *list1 = llistNew(t1, cmpTask); + llist *list1 = llistNew(t1, cmpTaskN); llistAppend(list1, &t2); // print test tasks