|
1 /* |
|
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
3 * |
|
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions are met: |
|
8 * |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 * POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 /** |
|
29 * \file compare.h |
|
30 * \brief A collection of simple compare functions. |
|
31 * \author Mike Becker |
|
32 * \author Olaf Wintermann |
|
33 * \version 3.0 |
|
34 * \copyright 2-Clause BSD License |
|
35 */ |
|
36 |
|
37 #ifndef UCX_COMPARE_H |
|
38 #define UCX_COMPARE_H |
|
39 |
|
40 #ifdef __cplusplus |
|
41 extern "C" { |
|
42 #endif |
|
43 |
|
44 /** |
|
45 * Compares two integers of type int. |
|
46 * |
|
47 * @param i1 pointer to integer one |
|
48 * @param i2 pointer to integer two |
|
49 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
50 * 1 if *i1 is greater than *i2 |
|
51 */ |
|
52 int cx_cmp_int(void const *i1, void const *i2); |
|
53 |
|
54 /** |
|
55 * Compares two integers of type long int. |
|
56 * |
|
57 * @param i1 pointer to long integer one |
|
58 * @param i2 pointer to long integer two |
|
59 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
60 * 1 if *i1 is greater than *i2 |
|
61 */ |
|
62 int cx_cmp_longint(void const *i1, void const *i2); |
|
63 |
|
64 /** |
|
65 * Compares two integers of type long long. |
|
66 * |
|
67 * @param i1 pointer to long long one |
|
68 * @param i2 pointer to long long two |
|
69 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
70 * 1 if *i1 is greater than *i2 |
|
71 */ |
|
72 int cx_cmp_longlong(void const *i1, void const *i2); |
|
73 |
|
74 /** |
|
75 * Compares two integers of type int16_t. |
|
76 * |
|
77 * @param i1 pointer to int16_t one |
|
78 * @param i2 pointer to int16_t two |
|
79 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
80 * 1 if *i1 is greater than *i2 |
|
81 */ |
|
82 int cx_cmp_int16(void const *i1, void const *i2); |
|
83 |
|
84 /** |
|
85 * Compares two integers of type int32_t. |
|
86 * |
|
87 * @param i1 pointer to int32_t one |
|
88 * @param i2 pointer to int32_t two |
|
89 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
90 * 1 if *i1 is greater than *i2 |
|
91 */ |
|
92 int cx_cmp_int32(void const *i1, void const *i2); |
|
93 |
|
94 /** |
|
95 * Compares two integers of type int64_t. |
|
96 * |
|
97 * @param i1 pointer to int64_t one |
|
98 * @param i2 pointer to int64_t two |
|
99 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
100 * 1 if *i1 is greater than *i2 |
|
101 */ |
|
102 int cx_cmp_int64(void const *i1, void const *i2); |
|
103 |
|
104 /** |
|
105 * Compares two integers of type unsigned int. |
|
106 * |
|
107 * @param i1 pointer to unsigned integer one |
|
108 * @param i2 pointer to unsigned integer two |
|
109 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
110 * 1 if *i1 is greater than *i2 |
|
111 */ |
|
112 int cx_cmp_uint(void const *i1, void const *i2); |
|
113 |
|
114 /** |
|
115 * Compares two integers of type unsigned long int. |
|
116 * |
|
117 * @param i1 pointer to unsigned long integer one |
|
118 * @param i2 pointer to unsigned long integer two |
|
119 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
120 * 1 if *i1 is greater than *i2 |
|
121 */ |
|
122 int cx_cmp_ulongint(void const *i1, void const *i2); |
|
123 |
|
124 /** |
|
125 * Compares two integers of type unsigned long long. |
|
126 * |
|
127 * @param i1 pointer to unsigned long long one |
|
128 * @param i2 pointer to unsigned long long two |
|
129 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
130 * 1 if *i1 is greater than *i2 |
|
131 */ |
|
132 int cx_cmp_ulonglong(void const *i1, void const *i2); |
|
133 |
|
134 /** |
|
135 * Compares two integers of type uint16_t. |
|
136 * |
|
137 * @param i1 pointer to uint16_t one |
|
138 * @param i2 pointer to uint16_t two |
|
139 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
140 * 1 if *i1 is greater than *i2 |
|
141 */ |
|
142 int cx_cmp_uint16(void const *i1, void const *i2); |
|
143 |
|
144 /** |
|
145 * Compares two integers of type uint32_t. |
|
146 * |
|
147 * @param i1 pointer to uint32_t one |
|
148 * @param i2 pointer to uint32_t two |
|
149 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
150 * 1 if *i1 is greater than *i2 |
|
151 */ |
|
152 int cx_cmp_uint32(void const *i1, void const *i2); |
|
153 |
|
154 /** |
|
155 * Compares two integers of type uint64_t. |
|
156 * |
|
157 * @param i1 pointer to uint64_t one |
|
158 * @param i2 pointer to uint64_t two |
|
159 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
|
160 * 1 if *i1 is greater than *i2 |
|
161 */ |
|
162 int cx_cmp_uint64(void const *i1, void const *i2); |
|
163 |
|
164 /** |
|
165 * Compares two real numbers of type float with precision 1e-6f. |
|
166 * |
|
167 * @param f1 pointer to float one |
|
168 * @param f2 pointer to float two |
|
169 * @return -1, if *f1 is less than *f2, 0 if both are equal, |
|
170 * 1 if *f1 is greater than *f2 |
|
171 */ |
|
172 |
|
173 int cx_cmp_float(void const *f1, void const *f2); |
|
174 |
|
175 /** |
|
176 * Compares two real numbers of type double with precision 1e-14. |
|
177 * |
|
178 * @param d1 pointer to double one |
|
179 * @param d2 pointer to double two |
|
180 * @return -1, if *d1 is less than *d2, 0 if both are equal, |
|
181 * 1 if *d1 is greater than *d2 |
|
182 */ |
|
183 int cx_cmp_double(void const *d1, void const *d2); |
|
184 |
|
185 /** |
|
186 * Compares two pointers. |
|
187 * |
|
188 * @param ptr1 pointer one |
|
189 * @param ptr2 pointer two |
|
190 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
|
191 * 1 if ptr1 is greater than ptr2 |
|
192 */ |
|
193 int cx_cmp_ptr(void const *ptr1, void const *ptr2); |
|
194 |
|
195 #ifdef __cplusplus |
|
196 } // extern "C" |
|
197 #endif |
|
198 |
|
199 #endif //UCX_COMPARE_H |