aboutsummaryrefslogtreecommitdiff
path: root/src/cli/stasis_indexer/callbacks.c
blob: 4790e09f37094b4f0a7a03a9ce40d215976e0e62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Created by jhunk on 11/15/24.
//

#include "core.h"
#include "callbacks.h"

// qsort callback to sort delivery contexts by compact python version
int callback_sort_deliveries_cmpfn(const void *a, const void *b) {
    const struct Delivery *delivery1 = (struct Delivery *) a;
    const size_t delivery1_python = strtoul(delivery1->meta.python_compact, NULL, 10);
    const struct Delivery *delivery2 = (struct Delivery *) b;
    const size_t delivery2_python = strtoul(delivery2->meta.python_compact, NULL, 10);

    if (delivery2_python > delivery1_python) {
        return 1;
    }
    if (delivery2_python < delivery1_python) {
        return -1;
    }
    return 0;
}

// qsort callback to sort dynamically allocated delivery contexts by compact python version
int callback_sort_deliveries_dynamic_cmpfn(const void *a, const void *b) {
    const struct Delivery *delivery1 = *(struct Delivery **) a;
    const size_t delivery1_python = strtoul(delivery1->meta.python_compact, NULL, 10);
    const struct Delivery *delivery2 = *(struct Delivery **) b;
    const size_t delivery2_python = strtoul(delivery2->meta.python_compact, NULL, 10);

    if (delivery2_python > delivery1_python) {
        return 1;
    }
    if (delivery2_python < delivery1_python) {
        return -1;
    }
    return 0;
}