src/cx/compare.h

Wed, 07 Dec 2022 20:11:44 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 07 Dec 2022 20:11:44 +0100
changeset 631
406376e64fd8
parent 605
be5a4902d405
child 650
77021e06b1a8
permissions
-rw-r--r--

tests for compare functions

     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  */
    37 #ifndef UCX_COMPARE_H
    38 #define UCX_COMPARE_H
    40 #ifdef __cplusplus
    41 extern "C" {
    42 #endif
    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);
    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);
    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);
    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);
    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);
    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);
   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);
   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);
   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);
   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);
   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);
   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);
   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  */
   173 int cx_cmp_float(void const *f1, void const *f2);
   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(
   184         void const *d1,
   185         void const *d2
   186 );
   188 /**
   189  * Compares the integer representation of two pointers.
   190  *
   191  * @param ptr1 pointer to pointer one (intptr_t const*)
   192  * @param ptr2 pointer to pointer two (intptr_t const*)
   193  * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
   194  * 1 if *ptr1 is greater than *ptr2
   195  */
   196 int cx_cmp_intptr(
   197         void const *ptr1,
   198         void const *ptr2
   199 );
   201 /**
   202  * Compares the unsigned integer representation of two pointers.
   203  *
   204  * @param ptr1 pointer to pointer one (uintptr_t const*)
   205  * @param ptr2 pointer to pointer two (uintptr_t const*)
   206  * @return -1 if *ptr1 is less than *ptr2, 0 if both are equal,
   207  * 1 if *ptr1 is greater than *ptr2
   208  */
   209 int cx_cmp_uintptr(
   210         void const *ptr1,
   211         void const *ptr2
   212 );
   214 #ifdef __cplusplus
   215 } // extern "C"
   216 #endif
   218 #endif //UCX_COMPARE_H

mercurial