ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Typedefs | Functions
compare.h File Reference

A collection of simple compare functions. More...

#include "common.h"

Go to the source code of this file.

Typedefs

typedef int(* cx_compare_func) (const void *left, const void *right)
 A comparator function comparing two arbitrary values.
 

Functions

int cx_cmp_int (const void *i1, const void *i2)
 Compares two integers of type int.
 
int cx_vcmp_int (int i1, int i2)
 Compares two integers of type int.
 
int cx_cmp_longint (const void *i1, const void *i2)
 Compares two integers of type long int.
 
int cx_vcmp_longint (long int i1, long int i2)
 Compares two integers of type long int.
 
int cx_cmp_longlong (const void *i1, const void *i2)
 Compares two integers of type long long.
 
int cx_vcmp_longlong (long long int i1, long long int i2)
 Compares two integers of type long long.
 
int cx_cmp_int16 (const void *i1, const void *i2)
 Compares two integers of type int16_t.
 
int cx_vcmp_int16 (int16_t i1, int16_t i2)
 Compares two integers of type int16_t.
 
int cx_cmp_int32 (const void *i1, const void *i2)
 Compares two integers of type int32_t.
 
int cx_vcmp_int32 (int32_t i1, int32_t i2)
 Compares two integers of type int32_t.
 
int cx_cmp_int64 (const void *i1, const void *i2)
 Compares two integers of type int64_t.
 
int cx_vcmp_int64 (int64_t i1, int64_t i2)
 Compares two integers of type int64_t.
 
int cx_cmp_uint (const void *i1, const void *i2)
 Compares two integers of type unsigned int.
 
int cx_vcmp_uint (unsigned int i1, unsigned int i2)
 Compares two integers of type unsigned int.
 
int cx_cmp_ulongint (const void *i1, const void *i2)
 Compares two integers of type unsigned long int.
 
int cx_vcmp_ulongint (unsigned long int i1, unsigned long int i2)
 Compares two integers of type unsigned long int.
 
int cx_cmp_ulonglong (const void *i1, const void *i2)
 Compares two integers of type unsigned long long.
 
int cx_vcmp_ulonglong (unsigned long long int i1, unsigned long long int i2)
 Compares two integers of type unsigned long long.
 
int cx_cmp_uint16 (const void *i1, const void *i2)
 Compares two integers of type uint16_t.
 
int cx_vcmp_uint16 (uint16_t i1, uint16_t i2)
 Compares two integers of type uint16_t.
 
int cx_cmp_uint32 (const void *i1, const void *i2)
 Compares two integers of type uint32_t.
 
int cx_vcmp_uint32 (uint32_t i1, uint32_t i2)
 Compares two integers of type uint32_t.
 
int cx_cmp_uint64 (const void *i1, const void *i2)
 Compares two integers of type uint64_t.
 
int cx_vcmp_uint64 (uint64_t i1, uint64_t i2)
 Compares two integers of type uint64_t.
 
int cx_cmp_float (const void *f1, const void *f2)
 Compares two real numbers of type float with precision 1e-6f.
 
int cx_vcmp_float (float f1, float f2)
 Compares two real numbers of type float with precision 1e-6f.
 
int cx_cmp_double (const void *d1, const void *d2)
 Compares two real numbers of type double with precision 1e-14.
 
int cx_vcmp_double (double d1, double d2)
 Compares two real numbers of type double with precision 1e-14.
 
int cx_cmp_intptr (const void *ptr1, const void *ptr2)
 Compares the integer representation of two pointers.
 
int cx_vcmp_intptr (intptr_t ptr1, intptr_t ptr2)
 Compares the integer representation of two pointers.
 
int cx_cmp_uintptr (const void *ptr1, const void *ptr2)
 Compares the unsigned integer representation of two pointers.
 
int cx_vcmp_uintptr (uintptr_t ptr1, uintptr_t ptr2)
 Compares the unsigned integer representation of two pointers.
 
int cx_cmp_ptr (const void *ptr1, const void *ptr2)
 Compares the pointers specified in the arguments without dereferencing.
 

Detailed Description

A collection of simple compare functions.

Author
Mike Becker
Olaf Wintermann

Typedef Documentation

◆ cx_compare_func

typedef int(* cx_compare_func) (const void *left, const void *right)

A comparator function comparing two arbitrary values.

All functions from compare.h with the cx_cmp prefix are compatible with this signature and can be used as compare function for collections, or other implementations that need to be type-agnostic.

For simple comparisons the cx_vcmp family of functions can be used, but they are NOT compatible with this function pointer.

Function Documentation

◆ cx_cmp_double()

int cx_cmp_double ( const void * d1,
const void * d2 )

Compares two real numbers of type double with precision 1e-14.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
d1pointer to double one
d2pointer to double two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_float()

int cx_cmp_float ( const void * f1,
const void * f2 )

Compares two real numbers of type float with precision 1e-6f.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
f1pointer to float one
f2pointer to float two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_int()

int cx_cmp_int ( const void * i1,
const void * i2 )

Compares two integers of type int.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to integer one
i2pointer to integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_int16()

int cx_cmp_int16 ( const void * i1,
const void * i2 )

Compares two integers of type int16_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to int16_t one
i2pointer to int16_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_int32()

int cx_cmp_int32 ( const void * i1,
const void * i2 )

Compares two integers of type int32_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to int32_t one
i2pointer to int32_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_int64()

int cx_cmp_int64 ( const void * i1,
const void * i2 )

Compares two integers of type int64_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to int64_t one
i2pointer to int64_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_intptr()

int cx_cmp_intptr ( const void * ptr1,
const void * ptr2 )

Compares the integer representation of two pointers.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
ptr1pointer to pointer one (const intptr_t*)
ptr2pointer to pointer two (const intptr_t*)
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_longint()

int cx_cmp_longint ( const void * i1,
const void * i2 )

Compares two integers of type long int.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to long integer one
i2pointer to long integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_longlong()

int cx_cmp_longlong ( const void * i1,
const void * i2 )

Compares two integers of type long long.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to long long one
i2pointer to long long two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_ptr()

int cx_cmp_ptr ( const void * ptr1,
const void * ptr2 )

Compares the pointers specified in the arguments without dereferencing.

Parameters
ptr1pointer one
ptr2pointer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_uint()

int cx_cmp_uint ( const void * i1,
const void * i2 )

Compares two integers of type unsigned int.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to unsigned integer one
i2pointer to unsigned integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_uint16()

int cx_cmp_uint16 ( const void * i1,
const void * i2 )

Compares two integers of type uint16_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to uint16_t one
i2pointer to uint16_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_uint32()

int cx_cmp_uint32 ( const void * i1,
const void * i2 )

Compares two integers of type uint32_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to uint32_t one
i2pointer to uint32_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_uint64()

int cx_cmp_uint64 ( const void * i1,
const void * i2 )

Compares two integers of type uint64_t.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to uint64_t one
i2pointer to uint64_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_uintptr()

int cx_cmp_uintptr ( const void * ptr1,
const void * ptr2 )

Compares the unsigned integer representation of two pointers.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
ptr1pointer to pointer one (const uintptr_t*)
ptr2pointer to pointer two (const uintptr_t*)
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_ulongint()

int cx_cmp_ulongint ( const void * i1,
const void * i2 )

Compares two integers of type unsigned long int.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to unsigned long integer one
i2pointer to unsigned long integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_cmp_ulonglong()

int cx_cmp_ulonglong ( const void * i1,
const void * i2 )

Compares two integers of type unsigned long long.

Note
the parameters deliberately have type void* to be compatible with cx_compare_func without the need of a cast.
Parameters
i1pointer to unsigned long long one
i2pointer to unsigned long long two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_double()

int cx_vcmp_double ( double d1,
double d2 )

Compares two real numbers of type double with precision 1e-14.

Parameters
d1double one
d2double two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_float()

int cx_vcmp_float ( float f1,
float f2 )

Compares two real numbers of type float with precision 1e-6f.

Parameters
f1float one
f2float two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_int()

int cx_vcmp_int ( int i1,
int i2 )

Compares two integers of type int.

Parameters
i1integer one
i2integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_int16()

int cx_vcmp_int16 ( int16_t i1,
int16_t i2 )

Compares two integers of type int16_t.

Parameters
i1int16_t one
i2int16_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_int32()

int cx_vcmp_int32 ( int32_t i1,
int32_t i2 )

Compares two integers of type int32_t.

Parameters
i1int32_t one
i2int32_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_int64()

int cx_vcmp_int64 ( int64_t i1,
int64_t i2 )

Compares two integers of type int64_t.

Parameters
i1int64_t one
i2int64_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_intptr()

int cx_vcmp_intptr ( intptr_t ptr1,
intptr_t ptr2 )

Compares the integer representation of two pointers.

Parameters
ptr1pointer one
ptr2pointer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_longint()

int cx_vcmp_longint ( long int i1,
long int i2 )

Compares two integers of type long int.

Parameters
i1long integer one
i2long integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_longlong()

int cx_vcmp_longlong ( long long int i1,
long long int i2 )

Compares two integers of type long long.

Parameters
i1long long int one
i2long long int two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_uint()

int cx_vcmp_uint ( unsigned int i1,
unsigned int i2 )

Compares two integers of type unsigned int.

Parameters
i1unsigned integer one
i2unsigned integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_uint16()

int cx_vcmp_uint16 ( uint16_t i1,
uint16_t i2 )

Compares two integers of type uint16_t.

Parameters
i1uint16_t one
i2uint16_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_uint32()

int cx_vcmp_uint32 ( uint32_t i1,
uint32_t i2 )

Compares two integers of type uint32_t.

Parameters
i1uint32_t one
i2uint32_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_uint64()

int cx_vcmp_uint64 ( uint64_t i1,
uint64_t i2 )

Compares two integers of type uint64_t.

Parameters
i1uint64_t one
i2uint64_t two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_uintptr()

int cx_vcmp_uintptr ( uintptr_t ptr1,
uintptr_t ptr2 )

Compares the unsigned integer representation of two pointers.

Parameters
ptr1pointer one
ptr2pointer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_ulongint()

int cx_vcmp_ulongint ( unsigned long int i1,
unsigned long int i2 )

Compares two integers of type unsigned long int.

Parameters
i1unsigned long integer one
i2unsigned long integer two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument

◆ cx_vcmp_ulonglong()

int cx_vcmp_ulonglong ( unsigned long long int i1,
unsigned long long int i2 )

Compares two integers of type unsigned long long.

Parameters
i1unsigned long long one
i2unsigned long long two
Return values
-1if the left argument is less than the right argument
0if both arguments are equal
1if the left argument is greater than the right argument