1 | /* |
2 | * compare.h |
3 | * |
4 | * Copyright (C) 2018 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | //========================================================== |
26 | // Includes. |
27 | // |
28 | |
29 | #include <stdint.h> |
30 | |
31 | |
32 | //========================================================== |
33 | // Public API - qsort() comparators. |
34 | // |
35 | |
36 | static inline int |
37 | cf_compare_uint64_desc(const void* pa, const void* pb) |
38 | { |
39 | uint64_t a = *(const uint64_t*)pa; |
40 | uint64_t b = *(const uint64_t*)pb; |
41 | |
42 | return a > b ? -1 : (a == b ? 0 : 1); |
43 | } |
44 | |
45 | static inline int |
46 | cf_compare_uint32_desc(const void* pa, const void* pb) |
47 | { |
48 | uint32_t a = *(const uint32_t*)pa; |
49 | uint32_t b = *(const uint32_t*)pb; |
50 | |
51 | return a > b ? -1 : (a == b ? 0 : 1); |
52 | } |
53 | |