1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cx/compare.h Sat Nov 05 17:50:04 2022 +0100 1.3 @@ -0,0 +1,199 @@ 1.4 +/* 1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1.6 + * 1.7 + * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions are met: 1.11 + * 1.12 + * 1. Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * 2. Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 1.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.29 + * POSSIBILITY OF SUCH DAMAGE. 1.30 + */ 1.31 +/** 1.32 + * \file compare.h 1.33 + * \brief A collection of simple compare functions. 1.34 + * \author Mike Becker 1.35 + * \author Olaf Wintermann 1.36 + * \version 3.0 1.37 + * \copyright 2-Clause BSD License 1.38 + */ 1.39 + 1.40 +#ifndef UCX_COMPARE_H 1.41 +#define UCX_COMPARE_H 1.42 + 1.43 +#ifdef __cplusplus 1.44 +extern "C" { 1.45 +#endif 1.46 + 1.47 +/** 1.48 + * Compares two integers of type int. 1.49 + * 1.50 + * @param i1 pointer to integer one 1.51 + * @param i2 pointer to integer two 1.52 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.53 + * 1 if *i1 is greater than *i2 1.54 + */ 1.55 +int cx_cmp_int(void const *i1, void const *i2); 1.56 + 1.57 +/** 1.58 + * Compares two integers of type long int. 1.59 + * 1.60 + * @param i1 pointer to long integer one 1.61 + * @param i2 pointer to long integer two 1.62 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.63 + * 1 if *i1 is greater than *i2 1.64 + */ 1.65 +int cx_cmp_longint(void const *i1, void const *i2); 1.66 + 1.67 +/** 1.68 + * Compares two integers of type long long. 1.69 + * 1.70 + * @param i1 pointer to long long one 1.71 + * @param i2 pointer to long long two 1.72 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.73 + * 1 if *i1 is greater than *i2 1.74 + */ 1.75 +int cx_cmp_longlong(void const *i1, void const *i2); 1.76 + 1.77 +/** 1.78 + * Compares two integers of type int16_t. 1.79 + * 1.80 + * @param i1 pointer to int16_t one 1.81 + * @param i2 pointer to int16_t two 1.82 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.83 + * 1 if *i1 is greater than *i2 1.84 + */ 1.85 +int cx_cmp_int16(void const *i1, void const *i2); 1.86 + 1.87 +/** 1.88 + * Compares two integers of type int32_t. 1.89 + * 1.90 + * @param i1 pointer to int32_t one 1.91 + * @param i2 pointer to int32_t two 1.92 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.93 + * 1 if *i1 is greater than *i2 1.94 + */ 1.95 +int cx_cmp_int32(void const *i1, void const *i2); 1.96 + 1.97 +/** 1.98 + * Compares two integers of type int64_t. 1.99 + * 1.100 + * @param i1 pointer to int64_t one 1.101 + * @param i2 pointer to int64_t two 1.102 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.103 + * 1 if *i1 is greater than *i2 1.104 + */ 1.105 +int cx_cmp_int64(void const *i1, void const *i2); 1.106 + 1.107 +/** 1.108 + * Compares two integers of type unsigned int. 1.109 + * 1.110 + * @param i1 pointer to unsigned integer one 1.111 + * @param i2 pointer to unsigned integer two 1.112 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.113 + * 1 if *i1 is greater than *i2 1.114 + */ 1.115 +int cx_cmp_uint(void const *i1, void const *i2); 1.116 + 1.117 +/** 1.118 + * Compares two integers of type unsigned long int. 1.119 + * 1.120 + * @param i1 pointer to unsigned long integer one 1.121 + * @param i2 pointer to unsigned long integer two 1.122 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.123 + * 1 if *i1 is greater than *i2 1.124 + */ 1.125 +int cx_cmp_ulongint(void const *i1, void const *i2); 1.126 + 1.127 +/** 1.128 + * Compares two integers of type unsigned long long. 1.129 + * 1.130 + * @param i1 pointer to unsigned long long one 1.131 + * @param i2 pointer to unsigned long long two 1.132 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.133 + * 1 if *i1 is greater than *i2 1.134 + */ 1.135 +int cx_cmp_ulonglong(void const *i1, void const *i2); 1.136 + 1.137 +/** 1.138 + * Compares two integers of type uint16_t. 1.139 + * 1.140 + * @param i1 pointer to uint16_t one 1.141 + * @param i2 pointer to uint16_t two 1.142 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.143 + * 1 if *i1 is greater than *i2 1.144 + */ 1.145 +int cx_cmp_uint16(void const *i1, void const *i2); 1.146 + 1.147 +/** 1.148 + * Compares two integers of type uint32_t. 1.149 + * 1.150 + * @param i1 pointer to uint32_t one 1.151 + * @param i2 pointer to uint32_t two 1.152 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.153 + * 1 if *i1 is greater than *i2 1.154 + */ 1.155 +int cx_cmp_uint32(void const *i1, void const *i2); 1.156 + 1.157 +/** 1.158 + * Compares two integers of type uint64_t. 1.159 + * 1.160 + * @param i1 pointer to uint64_t one 1.161 + * @param i2 pointer to uint64_t two 1.162 + * @return -1, if *i1 is less than *i2, 0 if both are equal, 1.163 + * 1 if *i1 is greater than *i2 1.164 + */ 1.165 +int cx_cmp_uint64(void const *i1, void const *i2); 1.166 + 1.167 +/** 1.168 + * Compares two real numbers of type float with precision 1e-6f. 1.169 + * 1.170 + * @param f1 pointer to float one 1.171 + * @param f2 pointer to float two 1.172 + * @return -1, if *f1 is less than *f2, 0 if both are equal, 1.173 + * 1 if *f1 is greater than *f2 1.174 + */ 1.175 + 1.176 +int cx_cmp_float(void const *f1, void const *f2); 1.177 + 1.178 +/** 1.179 + * Compares two real numbers of type double with precision 1e-14. 1.180 + * 1.181 + * @param d1 pointer to double one 1.182 + * @param d2 pointer to double two 1.183 + * @return -1, if *d1 is less than *d2, 0 if both are equal, 1.184 + * 1 if *d1 is greater than *d2 1.185 + */ 1.186 +int cx_cmp_double(void const *d1, void const *d2); 1.187 + 1.188 +/** 1.189 + * Compares two pointers. 1.190 + * 1.191 + * @param ptr1 pointer one 1.192 + * @param ptr2 pointer two 1.193 + * @return -1 if ptr1 is less than ptr2, 0 if both are equal, 1.194 + * 1 if ptr1 is greater than ptr2 1.195 + */ 1.196 +int ucx_cmp_ptr(void const *ptr1, void const *ptr2); 1.197 + 1.198 +#ifdef __cplusplus 1.199 +} // extern "C" 1.200 +#endif 1.201 + 1.202 +#endif //UCX_COMPARE_H