Zycore 1.5.2
Zyan Core Library for C
Loading...
Searching...
No Matches
Comparison.h File Reference

Defines prototypes of general-purpose comparison functions. More...

#include <Zycore/Defines.h>
#include <Zycore/Types.h>
Include dependency graph for Comparison.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ZYAN_DECLARE_EQUALITY_COMPARISON(name, type)
 Declares a generic equality comparison function for an integral data-type.
#define ZYAN_DECLARE_EQUALITY_COMPARISON_FOR_FIELD(name, type, field_name)
 Declares a generic equality comparison function that compares a single integral data-type field of a struct.
#define ZYAN_DECLARE_COMPARISON(name, type)
 Declares a generic comparison function for an integral data-type.
#define ZYAN_DECLARE_COMPARISON_FOR_FIELD(name, type, field_name)
 Declares a generic comparison function that compares a single integral data-type field of a struct.

Typedefs

typedef ZyanBool(* ZyanEqualityComparison) (const void *left, const void *right)
 Defines the ZyanEqualityComparison function prototype.
typedef ZyanI32(* ZyanComparison) (const void *left, const void *right)
 Defines the ZyanComparison function prototype.

Functions

ZYAN_INLINE ZyanBool ZyanEqualsPointer (const void *const *left, const void *const *right)
 Defines a default equality comparison function for pointer values.
ZYAN_INLINE ZyanBool ZyanEqualsBool (const ZyanBool *left, const ZyanBool *right)
 Defines a default equality comparison function for ZyanBool values.
ZYAN_INLINE ZyanBool ZyanEqualsNumeric8 (const ZyanU8 *left, const ZyanU8 *right)
 Defines a default equality comparison function for 8-bit numeric values.
ZYAN_INLINE ZyanBool ZyanEqualsNumeric16 (const ZyanU16 *left, const ZyanU16 *right)
 Defines a default equality comparison function for 16-bit numeric values.
ZYAN_INLINE ZyanBool ZyanEqualsNumeric32 (const ZyanU32 *left, const ZyanU32 *right)
 Defines a default equality comparison function for 32-bit numeric values.
ZYAN_INLINE ZyanBool ZyanEqualsNumeric64 (const ZyanU64 *left, const ZyanU64 *right)
 Defines a default equality comparison function for 64-bit numeric values.
ZYAN_INLINE ZyanI32 ZyanComparePointer (const void *const *left, const void *const *right)
 Defines a default comparison function for pointer values.
ZYAN_INLINE ZyanI32 ZyanCompareBool (const ZyanBool *left, const ZyanBool *right)
 Defines a default comparison function for ZyanBool values.
ZYAN_INLINE ZyanI32 ZyanCompareNumeric8 (const ZyanU8 *left, const ZyanU8 *right)
 Defines a default comparison function for 8-bit numeric values.
ZYAN_INLINE ZyanI32 ZyanCompareNumeric16 (const ZyanU16 *left, const ZyanU16 *right)
 Defines a default comparison function for 16-bit numeric values.
ZYAN_INLINE ZyanI32 ZyanCompareNumeric32 (const ZyanU32 *left, const ZyanU32 *right)
 Defines a default comparison function for 32-bit numeric values.
ZYAN_INLINE ZyanI32 ZyanCompareNumeric64 (const ZyanU64 *left, const ZyanU64 *right)
 Defines a default comparison function for 64-bit numeric values.

Detailed Description

Defines prototypes of general-purpose comparison functions.

Macro Definition Documentation

◆ ZYAN_DECLARE_COMPARISON

#define ZYAN_DECLARE_COMPARISON ( name,
type )
Value:
ZyanI32 name(const type* left, const type* right) \
{ \
ZYAN_ASSERT(left); \
ZYAN_ASSERT(right); \
\
if (*left < *right) \
{ \
return -1; \
} \
if (*left > *right) \
{ \
return 1; \
} \
return 0; \
}
int32_t ZyanI32
Definition Types.h:222

Declares a generic comparison function for an integral data-type.

Parameters
nameThe name of the function.
typeThe name of the integral data-type.

◆ ZYAN_DECLARE_COMPARISON_FOR_FIELD

#define ZYAN_DECLARE_COMPARISON_FOR_FIELD ( name,
type,
field_name )
Value:
ZyanI32 name(const type* left, const type* right) \
{ \
ZYAN_ASSERT(left); \
ZYAN_ASSERT(right); \
\
if (left->field_name < right->field_name) \
{ \
return -1; \
} \
if (left->field_name > right->field_name) \
{ \
return 1; \
} \
return 0; \
}

Declares a generic comparison function that compares a single integral data-type field of a struct.

Parameters
nameThe name of the function.
typeThe name of the integral data-type.
field_nameThe name of the struct field.

◆ ZYAN_DECLARE_EQUALITY_COMPARISON

#define ZYAN_DECLARE_EQUALITY_COMPARISON ( name,
type )
Value:
ZyanBool name(const type* left, const type* right) \
{ \
ZYAN_ASSERT(left); \
ZYAN_ASSERT(right); \
\
return (*left == *right) ? ZYAN_TRUE : ZYAN_FALSE; \
}
ZyanU8 ZyanBool
Defines the ZyanBool data-type.
Definition Types.h:296
#define ZYAN_FALSE
Definition Types.h:287
#define ZYAN_TRUE
Definition Types.h:288

Declares a generic equality comparison function for an integral data-type.

Parameters
nameThe name of the function.
typeThe name of the integral data-type.

◆ ZYAN_DECLARE_EQUALITY_COMPARISON_FOR_FIELD

#define ZYAN_DECLARE_EQUALITY_COMPARISON_FOR_FIELD ( name,
type,
field_name )
Value:
ZyanBool name(const type* left, const type* right) \
{ \
ZYAN_ASSERT(left); \
ZYAN_ASSERT(right); \
\
return (left->field_name == right->field_name) ? ZYAN_TRUE : ZYAN_FALSE; \
}

Declares a generic equality comparison function that compares a single integral data-type field of a struct.

Parameters
nameThe name of the function.
typeThe name of the integral data-type.
field_nameThe name of the struct field.

Typedef Documentation

◆ ZyanComparison

typedef ZyanI32(* ZyanComparison) (const void *left, const void *right)

Defines the ZyanComparison function prototype.

Parameters
leftA pointer to the first element.
rightA pointer to the second element.
Returns
This function should return values in the following range: left == right -> result == 0 left < right -> result < 0 left > right -> result > 0

◆ ZyanEqualityComparison

typedef ZyanBool(* ZyanEqualityComparison) (const void *left, const void *right)

Defines the ZyanEqualityComparison function prototype.

Parameters
leftA pointer to the first element.
rightA pointer to the second element.
Returns
This function should return ZYAN_TRUE if the left element equals the right one or ZYAN_FALSE, if not.

Function Documentation

◆ ZyanCompareBool()

ZYAN_INLINE ZyanI32 ZyanCompareBool ( const ZyanBool * left,
const ZyanBool * right )

Defines a default comparison function for ZyanBool values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanCompareNumeric16()

ZYAN_INLINE ZyanI32 ZyanCompareNumeric16 ( const ZyanU16 * left,
const ZyanU16 * right )

Defines a default comparison function for 16-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanCompareNumeric32()

ZYAN_INLINE ZyanI32 ZyanCompareNumeric32 ( const ZyanU32 * left,
const ZyanU32 * right )

Defines a default comparison function for 32-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanCompareNumeric64()

ZYAN_INLINE ZyanI32 ZyanCompareNumeric64 ( const ZyanU64 * left,
const ZyanU64 * right )

Defines a default comparison function for 64-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanCompareNumeric8()

ZYAN_INLINE ZyanI32 ZyanCompareNumeric8 ( const ZyanU8 * left,
const ZyanU8 * right )

Defines a default comparison function for 8-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanComparePointer()

ZYAN_INLINE ZyanI32 ZyanComparePointer ( const void *const * left,
const void *const * right )

Defines a default comparison function for pointer values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns 0 if the left value equals the right one, -1 if the left value is less than the right one, or 1 if the left value is greater than the right one.

◆ ZyanEqualsBool()

ZYAN_INLINE ZyanBool ZyanEqualsBool ( const ZyanBool * left,
const ZyanBool * right )

Defines a default equality comparison function for ZyanBool values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.

◆ ZyanEqualsNumeric16()

ZYAN_INLINE ZyanBool ZyanEqualsNumeric16 ( const ZyanU16 * left,
const ZyanU16 * right )

Defines a default equality comparison function for 16-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.

◆ ZyanEqualsNumeric32()

ZYAN_INLINE ZyanBool ZyanEqualsNumeric32 ( const ZyanU32 * left,
const ZyanU32 * right )

Defines a default equality comparison function for 32-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.

◆ ZyanEqualsNumeric64()

ZYAN_INLINE ZyanBool ZyanEqualsNumeric64 ( const ZyanU64 * left,
const ZyanU64 * right )

Defines a default equality comparison function for 64-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.

◆ ZyanEqualsNumeric8()

ZYAN_INLINE ZyanBool ZyanEqualsNumeric8 ( const ZyanU8 * left,
const ZyanU8 * right )

Defines a default equality comparison function for 8-bit numeric values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.

◆ ZyanEqualsPointer()

ZYAN_INLINE ZyanBool ZyanEqualsPointer ( const void *const * left,
const void *const * right )

Defines a default equality comparison function for pointer values.

Parameters
leftA pointer to the first value.
rightA pointer to the second value.
Returns
Returns ZYAN_TRUE if the left value equals the right one or ZYAN_FALSE, if not.