NSphere Sort (nsphere_sort.h)
Clean wrapper for quadsort to suppress warnings and add support for doubles.
This header provides a clean interface to quadsort by:
Containing all warnings through pragma directives
Adding support for double and long double types
Keeping the original quadsort implementation pristine
Note
This wrapper is specifically designed for the NSphere simulation system to ensure consistent sorting behavior across all numerical types.
Defines
-
ns_sort_array
Restore warning settings to their previous state.
Pops the diagnostic pragma stack to restore compiler warning settings that were modified earlier in this header.
Define clean aliases to quadsort functions with zero overhead
These macros provide a consistent naming convention for sorting functions in the NSphere codebase, making it clear which functions are part of the NSphere API rather than direct quadsort calls.
-
ns_sort_extended
-
ns_sort_prim
-
ns_sort_size
Functions
-
static inline void ns_quadsort_extended(void *array, size_t nmemb, size_t size, CMPFUNC *cmp)
Push current warning state and disable specific warnings.
These pragma directives are used to suppress compiler warnings that would otherwise be generated by the quadsort implementation. This allows us to use the original quadsort code without modification.
Include the original quadsort header with warnings suppressed
The GCC/Clang warning suppression includes "-Wmacro-redefined" to allow quadsort.h to define QUAD_CACHE even though it may be defined via compiler flags. This approach preserves dynamic cache sizing from Makefiles while allowing direct inclusion in other contexts.
NSphere extensions to quadsort - Support for double and long double types
These extensions add specialized sorting implementations for floating-point types that may not be efficiently handled by the standard quadsort. They are conditionally compiled based on compiler support.
Extended quadsort function with support for double and long double types
This function extends the standard quadsort implementation to handle double and long double types with specialized implementations. For other types, it falls back to the standard quadsort. This provides optimal performance for all data types used in the NSphere simulation system.
Parameters
array : void* Pointer to the array to be sorted. nmemb : size_t Number of elements in the array. size : size_t Size of each element in bytes. cmp : CMPFUNC* Pointer to comparison function that returns negative, zero, or positive if first argument is less than, equal to, or greater than the second.
Returns
None
See also
quadsort - The original implementation used for standard types.
Note
This function automatically selects the appropriate sorting implementation based on the element size, providing optimized sorting for double and long double types when supported by the compiler.
Warning
The implementation for double and long double is only available when compiled with GCC or compatible compilers.