Skip to content

Commit

Permalink
Add comparison counter
Browse files Browse the repository at this point in the history
The previously ported Linux list_sort remove the void pointer `priv`. In
order to benchmark different sorting methods, the pointer is add back.
  • Loading branch information
millaker committed Mar 16, 2024
1 parent 61da385 commit 43a0ca7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions qtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include "random.h"

/* linux list sort*/
void list_sort(struct list_head *head,
bool (*cmp)(struct list_head *, struct list_head *, bool),
bool descend);
void list_sort(
void *priv,
struct list_head *head,
bool (*cmp)(void *priv, struct list_head *, struct list_head *, bool),
bool descend);

/* Shannon entropy */
extern double shannon_entropy(const uint8_t *input_data);
Expand Down Expand Up @@ -1086,8 +1088,10 @@ static bool do_shuffle_random_test(int argc, char *argv[])
return true;
}

bool cmp(struct list_head *a, struct list_head *b, bool descend)
bool cmp(void *priv, struct list_head *a, struct list_head *b, bool descend)
{
if (priv)
priv++;
element_t *a_entry = list_entry(a, element_t, list);
element_t *b_entry = list_entry(b, element_t, list);
return (strcmp(a_entry->value, b_entry->value) > 0) ^ descend;
Expand All @@ -1113,7 +1117,7 @@ static bool do_linux_list_sort(int argc, char *argv[])

set_noallocate_mode(true);
if (current && exception_setup(false))
list_sort(current->q, &cmp, descend);
list_sort(NULL, current->q, &cmp, descend);
exception_cancel();
set_noallocate_mode(false);

Expand Down

0 comments on commit 43a0ca7

Please sign in to comment.