libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_sort.h
Go to the documentation of this file.
1/*! \file
2 * \ingroup sorting
3 * \brief Generialized array sorting algorithms
4 *
5 * This file contains a collection of sorting algorithms,
6 * each with the same function prototype so that they can
7 * be passed around generically. Each is expected to
8 * operate on an array of data, accepting a custom
9 * comparator callback.
10 *
11 * \todo
12 * - gblSortRadix()
13 *
14 * \author 2023 Falco Girgis
15 * \copyright MIT License
16 */
17
18#ifndef GIMBAL_SORT_H
19#define GIMBAL_SORT_H
20
21#include "../core/gimbal_decls.h"
22
24
25//! Function taking two elements and returning their numeric difference as an integer
26typedef int (*GblSortComparatorFn) (const void*, const void*);
27//! Generic function pointer type for containing one of the array sorting algorithms
28typedef void (*GblSortFn) (void*, size_t, size_t, GblSortComparatorFn);
29
30/*! \defgroup sorting Sorting
31 * \ingroup algorithms
32 * \brief Collection of sorting algorithms
33 * @{
34 */
35//! Performs a Selection Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
36GBL_EXPORT void gblSortSelection (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
37//! Performs a Quick Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
38GBL_EXPORT void gblSortQuick (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
39//! Performs an Insertion Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
40GBL_EXPORT void gblSortInsertion (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
41//! Performs a Shell Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
42GBL_EXPORT void gblSortShell (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
43//! Performs a Merge Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
44GBL_EXPORT void gblSortMerge (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
45//! Performs a Comb Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
46GBL_EXPORT void gblSortComb (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
47//! Performs a Bubble Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
48GBL_EXPORT void gblSortBubble (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
49//! Performs a Heap Sort over the given array with \p count \p elemSize elements, using \p pFnCmp to compare them
50GBL_EXPORT void gblSortHeap (void* pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
51//! @}
52
53//! Performs a Binary Search over the given array, from index \p l to index \p r, returning its position
54GBL_EXPORT size_t gblSearchBinary (void* pSrc, size_t elemSize, int l, int r, void* pDst, GblSortComparatorFn pFnCmp) GBL_NOEXCEPT;
55
57
58#endif // GIMBAL_SORT_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
size_t gblSearchBinary(void *pSrc, size_t elemSize, int l, int r, void *pDst, GblSortComparatorFn pFnCmp)
Performs a Binary Search over the given array, from index l to index r, returning its position.
int(* GblSortComparatorFn)(const void *, const void *)
Function taking two elements and returning their numeric difference as an integer.
Definition gimbal_sort.h:26
void(* GblSortFn)(void *, size_t, size_t, GblSortComparatorFn)
Generic function pointer type for containing one of the array sorting algorithms.
Definition gimbal_sort.h:28
void gblSortMerge(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Merge Sort over the given array with count elemSize elements, using pFnCmp to compare them...
void gblSortHeap(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Heap Sort over the given array with count elemSize elements, using pFnCmp to compare them.
void gblSortSelection(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Selection Sort over the given array with count elemSize elements, using pFnCmp to compare ...
void gblSortShell(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Shell Sort over the given array with count elemSize elements, using pFnCmp to compare them...
void gblSortQuick(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Quick Sort over the given array with count elemSize elements, using pFnCmp to compare them...
void gblSortInsertion(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs an Insertion Sort over the given array with count elemSize elements, using pFnCmp to compare...
void gblSortBubble(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Bubble Sort over the given array with count elemSize elements, using pFnCmp to compare the...
void gblSortComb(void *pArray, size_t count, size_t elemSize, GblSortComparatorFn pFnCmp)
Performs a Comb Sort over the given array with count elemSize elements, using pFnCmp to compare them.