QSort preprocessor metaprogram. More...
Defines | |
#define | VL_QSORT_array VL_QSORT_type* |
#define | VL_QSORT_prefix QSortPrefix |
#define | VL_QSORT_type QSortType |
#define | VL_QSORT_array QSortType* |
Functions | |
VL_QSORT_type | VL_QSORT_cmp (VL_QSORT_array_const array, vl_uindex indexA, vl_uindex indexB) |
Compare two array elements. | |
void | VL_QSORT_swap (VL_QSORT_array array, vl_uindex indexA, vl_uindex indexB) |
Swap two array elements. | |
void | VL_QSORT_sort_recursive (VL_QSORT_array array, vl_uindex begin, vl_uindex end) |
Sort portion of an array using quicksort. | |
void | VL_QSORT_sort (VL_QSORT_array array, vl_size size) |
Sort array using quicksort. |
Detailed Description
Overview
qsort-def.h is a metaprogram to define specialized instances of the quick-sort algorithm.
Usage
qsort-def.h is used to define a specialization of the VL_QSORT_sort function that operatoes on a given type of array. For instance the code
#define VL_QSORT_type float #define VL_QSORT_prefix my_qsort #include <vl/qsort-def.h>
defines a function my_qsort_sort
that operates on an array of floats.
- Todo:
- large array compatibility.
Define Documentation
#define VL_QSORT_array VL_QSORT_type* |
Data type of the qsort container
#define VL_QSORT_array QSortType* |
Data type of the qsort container
#define VL_QSORT_prefix QSortPrefix |
Prefix of the qsort functions
#define VL_QSORT_type QSortType |
Data type of the qsort elements
Function Documentation
VL_QSORT_type VL_QSORT_cmp | ( | VL_QSORT_array_const | array, |
vl_uindex | indexA, | ||
vl_uindex | indexB | ||
) | [inline] |
- Parameters:
-
array qsort array. indexA index of the first element A
to compare.indexB index of the second element B
to comapre.
- Returns:
- a negative number if
A<B
, 0 ifA==B
, and a positive number if ifA>B
.
void VL_QSORT_sort | ( | VL_QSORT_array | array, |
vl_size | size | ||
) | [inline] |
- Parameters:
-
array (in/out) pointer to the array. size size of the array.
The function sorts the array using quick-sort.
- Parameters:
-
array (in/out) pointer to the array. begin first element of the array portion. end last element of the array portion.
The function sorts the array using quick-sort. Note that begin
must be not larger than end
.
- Parameters:
-
array qsort array. indexA index of the first element to swap. indexB index of the second element to swap.
The function swaps the two elements a and @ b. The function uses a temporary element of type VL_QSORT_type and the copy operator =
.