qsort-def.h File Reference
QSort preprocessor metaprogram. More...
#include "host.h"#include <assert.h>Go to the source code of this file.
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.
Definition in file qsort-def.h.
Define Documentation
| #define VL_QSORT_array QSortType* |
Data type of the qsort container
Definition at line 56 of file qsort-def.h.
| #define VL_QSORT_array VL_QSORT_type* |
Data type of the qsort container
Definition at line 56 of file qsort-def.h.
| #define VL_QSORT_prefix QSortPrefix |
Prefix of the qsort functions
Definition at line 54 of file qsort-def.h.
| #define VL_QSORT_type QSortType |
Data type of the qsort elements
Definition at line 55 of file qsort-def.h.
Referenced by VL_QSORT_swap().
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 Ato compare.indexB index of the second element Bto comapre.
- Returns:
- a negative number if
A<B, 0 ifA==B, and a positive number if ifA>B.
Definition at line 74 of file qsort-def.h.
Referenced by VL_QSORT_sort_recursive().
| 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.
Definition at line 184 of file qsort-def.h.
References VL_QSORT_sort_recursive().
- 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.
Definition at line 128 of file qsort-def.h.
References VL_QSORT_cmp(), and VL_QSORT_swap().
Referenced by VL_QSORT_sort().
- 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 =.
Definition at line 101 of file qsort-def.h.
References VL_QSORT_type.
Referenced by VL_QSORT_sort_recursive().