Use a shorter/simpler license convention, stops the header taking so much space. Follow the SPDX license specification: https://spdx.org/licenses - C/C++/objc/objc++ - Python - Shell Scripts - CMake, GNUmakefile While most of the source tree has been included - `./extern/` was left out. - `./intern/cycles` & `./intern/atomic` are also excluded because they use different header conventions. doc/license/SPDX-license-identifiers.txt has been added to list SPDX all used identifiers. See P2788 for the script that automated these edits. Reviewed By: brecht, mont29, sergey Ref D14069
107 lines
2.0 KiB
C
107 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2013 Blender Foundation. All rights reserved. */
|
|
|
|
/** \file
|
|
* \ingroup bli
|
|
*
|
|
* Utility functions for sorting common types.
|
|
*/
|
|
|
|
#include "BLI_sort_utils.h" /* own include */
|
|
|
|
struct SortAnyByFloat {
|
|
float sort_value;
|
|
};
|
|
|
|
struct SortAnyByInt {
|
|
int sort_value;
|
|
};
|
|
|
|
struct SortAnyByPtr {
|
|
const void *sort_value;
|
|
};
|
|
|
|
int BLI_sortutil_cmp_float(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByFloat *a = a_;
|
|
const struct SortAnyByFloat *b = b_;
|
|
if (a->sort_value > b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value < b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByFloat *a = a_;
|
|
const struct SortAnyByFloat *b = b_;
|
|
if (a->sort_value < b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value > b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BLI_sortutil_cmp_int(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByInt *a = a_;
|
|
const struct SortAnyByInt *b = b_;
|
|
if (a->sort_value > b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value < b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByInt *a = a_;
|
|
const struct SortAnyByInt *b = b_;
|
|
if (a->sort_value < b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value > b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BLI_sortutil_cmp_ptr(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByPtr *a = a_;
|
|
const struct SortAnyByPtr *b = b_;
|
|
if (a->sort_value > b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value < b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_)
|
|
{
|
|
const struct SortAnyByPtr *a = a_;
|
|
const struct SortAnyByPtr *b = b_;
|
|
if (a->sort_value < b->sort_value) {
|
|
return 1;
|
|
}
|
|
if (a->sort_value > b->sort_value) {
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|