| 40 |
40 |
| 41 #ifdef __cplusplus |
41 #ifdef __cplusplus |
| 42 extern "C" { |
42 extern "C" { |
| 43 #endif |
43 #endif |
| 44 |
44 |
| 45 #ifndef CX_COMPARE_FUNC_DEFINED |
|
| 46 #define CX_COMPARE_FUNC_DEFINED |
|
| 47 /** |
45 /** |
| 48 * A comparator function comparing two collection elements. |
46 * A comparator function comparing two collection elements. |
| 49 */ |
47 */ |
| |
48 cx_attr_nonnull |
| |
49 cx_attr_nodiscard |
| 50 typedef int(*cx_compare_func)( |
50 typedef int(*cx_compare_func)( |
| 51 const void *left, |
51 const void *left, |
| 52 const void *right |
52 const void *right |
| 53 ); |
53 ); |
| 54 #endif // CX_COMPARE_FUNC_DEFINED |
|
| 55 |
54 |
| 56 /** |
55 /** |
| 57 * Compares two integers of type int. |
56 * Compares two integers of type int. |
| 58 * |
57 * |
| 59 * @param i1 pointer to integer one |
58 * @param i1 pointer to integer one |
| 60 * @param i2 pointer to integer two |
59 * @param i2 pointer to integer two |
| 61 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
60 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 62 * 1 if *i1 is greater than *i2 |
61 * 1 if *i1 is greater than *i2 |
| 63 */ |
62 */ |
| |
63 cx_attr_nonnull |
| |
64 cx_attr_nodiscard |
| 64 int cx_cmp_int(const void *i1, const void *i2); |
65 int cx_cmp_int(const void *i1, const void *i2); |
| 65 |
66 |
| 66 /** |
67 /** |
| 67 * Compares two integers of type long int. |
68 * Compares two integers of type long int. |
| 68 * |
69 * |
| 69 * @param i1 pointer to long integer one |
70 * @param i1 pointer to long integer one |
| 70 * @param i2 pointer to long integer two |
71 * @param i2 pointer to long integer two |
| 71 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
72 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 72 * 1 if *i1 is greater than *i2 |
73 * 1 if *i1 is greater than *i2 |
| 73 */ |
74 */ |
| |
75 cx_attr_nonnull |
| |
76 cx_attr_nodiscard |
| 74 int cx_cmp_longint(const void *i1, const void *i2); |
77 int cx_cmp_longint(const void *i1, const void *i2); |
| 75 |
78 |
| 76 /** |
79 /** |
| 77 * Compares two integers of type long long. |
80 * Compares two integers of type long long. |
| 78 * |
81 * |
| 79 * @param i1 pointer to long long one |
82 * @param i1 pointer to long long one |
| 80 * @param i2 pointer to long long two |
83 * @param i2 pointer to long long two |
| 81 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
84 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 82 * 1 if *i1 is greater than *i2 |
85 * 1 if *i1 is greater than *i2 |
| 83 */ |
86 */ |
| |
87 cx_attr_nonnull |
| |
88 cx_attr_nodiscard |
| 84 int cx_cmp_longlong(const void *i1, const void *i2); |
89 int cx_cmp_longlong(const void *i1, const void *i2); |
| 85 |
90 |
| 86 /** |
91 /** |
| 87 * Compares two integers of type int16_t. |
92 * Compares two integers of type int16_t. |
| 88 * |
93 * |
| 89 * @param i1 pointer to int16_t one |
94 * @param i1 pointer to int16_t one |
| 90 * @param i2 pointer to int16_t two |
95 * @param i2 pointer to int16_t two |
| 91 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
96 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 92 * 1 if *i1 is greater than *i2 |
97 * 1 if *i1 is greater than *i2 |
| 93 */ |
98 */ |
| |
99 cx_attr_nonnull |
| |
100 cx_attr_nodiscard |
| 94 int cx_cmp_int16(const void *i1, const void *i2); |
101 int cx_cmp_int16(const void *i1, const void *i2); |
| 95 |
102 |
| 96 /** |
103 /** |
| 97 * Compares two integers of type int32_t. |
104 * Compares two integers of type int32_t. |
| 98 * |
105 * |
| 99 * @param i1 pointer to int32_t one |
106 * @param i1 pointer to int32_t one |
| 100 * @param i2 pointer to int32_t two |
107 * @param i2 pointer to int32_t two |
| 101 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
108 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 102 * 1 if *i1 is greater than *i2 |
109 * 1 if *i1 is greater than *i2 |
| 103 */ |
110 */ |
| |
111 cx_attr_nonnull |
| |
112 cx_attr_nodiscard |
| 104 int cx_cmp_int32(const void *i1, const void *i2); |
113 int cx_cmp_int32(const void *i1, const void *i2); |
| 105 |
114 |
| 106 /** |
115 /** |
| 107 * Compares two integers of type int64_t. |
116 * Compares two integers of type int64_t. |
| 108 * |
117 * |
| 109 * @param i1 pointer to int64_t one |
118 * @param i1 pointer to int64_t one |
| 110 * @param i2 pointer to int64_t two |
119 * @param i2 pointer to int64_t two |
| 111 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
120 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 112 * 1 if *i1 is greater than *i2 |
121 * 1 if *i1 is greater than *i2 |
| 113 */ |
122 */ |
| |
123 cx_attr_nonnull |
| |
124 cx_attr_nodiscard |
| 114 int cx_cmp_int64(const void *i1, const void *i2); |
125 int cx_cmp_int64(const void *i1, const void *i2); |
| 115 |
126 |
| 116 /** |
127 /** |
| 117 * Compares two integers of type unsigned int. |
128 * Compares two integers of type unsigned int. |
| 118 * |
129 * |
| 119 * @param i1 pointer to unsigned integer one |
130 * @param i1 pointer to unsigned integer one |
| 120 * @param i2 pointer to unsigned integer two |
131 * @param i2 pointer to unsigned integer two |
| 121 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
132 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 122 * 1 if *i1 is greater than *i2 |
133 * 1 if *i1 is greater than *i2 |
| 123 */ |
134 */ |
| |
135 cx_attr_nonnull |
| |
136 cx_attr_nodiscard |
| 124 int cx_cmp_uint(const void *i1, const void *i2); |
137 int cx_cmp_uint(const void *i1, const void *i2); |
| 125 |
138 |
| 126 /** |
139 /** |
| 127 * Compares two integers of type unsigned long int. |
140 * Compares two integers of type unsigned long int. |
| 128 * |
141 * |
| 129 * @param i1 pointer to unsigned long integer one |
142 * @param i1 pointer to unsigned long integer one |
| 130 * @param i2 pointer to unsigned long integer two |
143 * @param i2 pointer to unsigned long integer two |
| 131 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
144 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 132 * 1 if *i1 is greater than *i2 |
145 * 1 if *i1 is greater than *i2 |
| 133 */ |
146 */ |
| |
147 cx_attr_nonnull |
| |
148 cx_attr_nodiscard |
| 134 int cx_cmp_ulongint(const void *i1, const void *i2); |
149 int cx_cmp_ulongint(const void *i1, const void *i2); |
| 135 |
150 |
| 136 /** |
151 /** |
| 137 * Compares two integers of type unsigned long long. |
152 * Compares two integers of type unsigned long long. |
| 138 * |
153 * |
| 139 * @param i1 pointer to unsigned long long one |
154 * @param i1 pointer to unsigned long long one |
| 140 * @param i2 pointer to unsigned long long two |
155 * @param i2 pointer to unsigned long long two |
| 141 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
156 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 142 * 1 if *i1 is greater than *i2 |
157 * 1 if *i1 is greater than *i2 |
| 143 */ |
158 */ |
| |
159 cx_attr_nonnull |
| |
160 cx_attr_nodiscard |
| 144 int cx_cmp_ulonglong(const void *i1, const void *i2); |
161 int cx_cmp_ulonglong(const void *i1, const void *i2); |
| 145 |
162 |
| 146 /** |
163 /** |
| 147 * Compares two integers of type uint16_t. |
164 * Compares two integers of type uint16_t. |
| 148 * |
165 * |
| 149 * @param i1 pointer to uint16_t one |
166 * @param i1 pointer to uint16_t one |
| 150 * @param i2 pointer to uint16_t two |
167 * @param i2 pointer to uint16_t two |
| 151 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
168 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 152 * 1 if *i1 is greater than *i2 |
169 * 1 if *i1 is greater than *i2 |
| 153 */ |
170 */ |
| |
171 cx_attr_nonnull |
| |
172 cx_attr_nodiscard |
| 154 int cx_cmp_uint16(const void *i1, const void *i2); |
173 int cx_cmp_uint16(const void *i1, const void *i2); |
| 155 |
174 |
| 156 /** |
175 /** |
| 157 * Compares two integers of type uint32_t. |
176 * Compares two integers of type uint32_t. |
| 158 * |
177 * |
| 159 * @param i1 pointer to uint32_t one |
178 * @param i1 pointer to uint32_t one |
| 160 * @param i2 pointer to uint32_t two |
179 * @param i2 pointer to uint32_t two |
| 161 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
180 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 162 * 1 if *i1 is greater than *i2 |
181 * 1 if *i1 is greater than *i2 |
| 163 */ |
182 */ |
| |
183 cx_attr_nonnull |
| |
184 cx_attr_nodiscard |
| 164 int cx_cmp_uint32(const void *i1, const void *i2); |
185 int cx_cmp_uint32(const void *i1, const void *i2); |
| 165 |
186 |
| 166 /** |
187 /** |
| 167 * Compares two integers of type uint64_t. |
188 * Compares two integers of type uint64_t. |
| 168 * |
189 * |
| 169 * @param i1 pointer to uint64_t one |
190 * @param i1 pointer to uint64_t one |
| 170 * @param i2 pointer to uint64_t two |
191 * @param i2 pointer to uint64_t two |
| 171 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
192 * @return -1, if *i1 is less than *i2, 0 if both are equal, |
| 172 * 1 if *i1 is greater than *i2 |
193 * 1 if *i1 is greater than *i2 |
| 173 */ |
194 */ |
| |
195 cx_attr_nonnull |
| |
196 cx_attr_nodiscard |
| 174 int cx_cmp_uint64(const void *i1, const void *i2); |
197 int cx_cmp_uint64(const void *i1, const void *i2); |
| 175 |
198 |
| 176 /** |
199 /** |
| 177 * Compares two real numbers of type float with precision 1e-6f. |
200 * Compares two real numbers of type float with precision 1e-6f. |
| 178 * |
201 * |
| 179 * @param f1 pointer to float one |
202 * @param f1 pointer to float one |
| 180 * @param f2 pointer to float two |
203 * @param f2 pointer to float two |
| 181 * @return -1, if *f1 is less than *f2, 0 if both are equal, |
204 * @return -1, if *f1 is less than *f2, 0 if both are equal, |
| 182 * 1 if *f1 is greater than *f2 |
205 * 1 if *f1 is greater than *f2 |
| 183 */ |
206 */ |
| 184 |
207 cx_attr_nonnull |
| |
208 cx_attr_nodiscard |
| 185 int cx_cmp_float(const void *f1, const void *f2); |
209 int cx_cmp_float(const void *f1, const void *f2); |
| 186 |
210 |
| 187 /** |
211 /** |
| 188 * Compares two real numbers of type double with precision 1e-14. |
212 * Compares two real numbers of type double with precision 1e-14. |
| 189 * |
213 * |
| 190 * @param d1 pointer to double one |
214 * @param d1 pointer to double one |
| 191 * @param d2 pointer to double two |
215 * @param d2 pointer to double two |
| 192 * @return -1, if *d1 is less than *d2, 0 if both are equal, |
216 * @return -1, if *d1 is less than *d2, 0 if both are equal, |
| 193 * 1 if *d1 is greater than *d2 |
217 * 1 if *d1 is greater than *d2 |
| 194 */ |
218 */ |
| 195 int cx_cmp_double( |
219 cx_attr_nonnull |
| 196 const void *d1, |
220 cx_attr_nodiscard |
| 197 const void *d2 |
221 int cx_cmp_double(const void *d1, const void *d2); |
| 198 ); |
|
| 199 |
222 |
| 200 /** |
223 /** |
| 201 * Compares the integer representation of two pointers. |
224 * Compares the integer representation of two pointers. |
| 202 * |
225 * |
| 203 * @param ptr1 pointer to pointer one (const intptr_t*) |
226 * @param ptr1 pointer to pointer one (const intptr_t*) |
| 204 * @param ptr2 pointer to pointer two (const intptr_t*) |
227 * @param ptr2 pointer to pointer two (const intptr_t*) |
| 205 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
228 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
| 206 * 1 if *ptr1 is greater than *ptr2 |
229 * 1 if *ptr1 is greater than *ptr2 |
| 207 */ |
230 */ |
| 208 int cx_cmp_intptr( |
231 cx_attr_nonnull |
| 209 const void *ptr1, |
232 cx_attr_nodiscard |
| 210 const void *ptr2 |
233 int cx_cmp_intptr(const void *ptr1, const void *ptr2); |
| 211 ); |
|
| 212 |
234 |
| 213 /** |
235 /** |
| 214 * Compares the unsigned integer representation of two pointers. |
236 * Compares the unsigned integer representation of two pointers. |
| 215 * |
237 * |
| 216 * @param ptr1 pointer to pointer one (const uintptr_t*) |
238 * @param ptr1 pointer to pointer one (const uintptr_t*) |
| 217 * @param ptr2 pointer to pointer two (const uintptr_t*) |
239 * @param ptr2 pointer to pointer two (const uintptr_t*) |
| 218 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
240 * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal, |
| 219 * 1 if *ptr1 is greater than *ptr2 |
241 * 1 if *ptr1 is greater than *ptr2 |
| 220 */ |
242 */ |
| 221 int cx_cmp_uintptr( |
243 cx_attr_nonnull |
| 222 const void *ptr1, |
244 cx_attr_nodiscard |
| 223 const void *ptr2 |
245 int cx_cmp_uintptr(const void *ptr1, const void *ptr2); |
| 224 ); |
|
| 225 |
246 |
| 226 /** |
247 /** |
| 227 * Compares the pointers specified in the arguments without de-referencing. |
248 * Compares the pointers specified in the arguments without de-referencing. |
| 228 * |
249 * |
| 229 * @param ptr1 pointer one |
250 * @param ptr1 pointer one |
| 230 * @param ptr2 pointer two |
251 * @param ptr2 pointer two |
| 231 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
252 * @return -1 if ptr1 is less than ptr2, 0 if both are equal, |
| 232 * 1 if ptr1 is greater than ptr2 |
253 * 1 if ptr1 is greater than ptr2 |
| 233 */ |
254 */ |
| 234 int cx_cmp_ptr( |
255 cx_attr_nonnull |
| 235 const void *ptr1, |
256 cx_attr_nodiscard |
| 236 const void *ptr2 |
257 int cx_cmp_ptr(const void *ptr1, const void *ptr2); |
| 237 ); |
|
| 238 |
258 |
| 239 #ifdef __cplusplus |
259 #ifdef __cplusplus |
| 240 } // extern "C" |
260 } // extern "C" |
| 241 #endif |
261 #endif |
| 242 |
262 |