VLFeat - Documentation > C API

# VLFeat.org

Documentation> C API

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

Macros | Functions
qsort-def.h File Reference

QSort preprocessor metaprogram. More...

`#include "host.h"`
`#include <assert.h>`

## Macros

#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. More...
void | VL_QSORT_swap (VL_QSORT_array array, vl_uindex indexA, vl_uindex indexB)
| Swap two array elements. More...
void | VL_QSORT_sort_recursive (VL_QSORT_array array, vl_uindex begin, vl_uindex end)
| Sort portion of an array using quicksort. More...
void | VL_QSORT_sort (VL_QSORT_array array, vl_size size)
| Sort array using quicksort. More...

## Detailed Description

Author
  Andrea Vedaldi

# 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 operates 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.

## Macro Definition 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 if `A==B`, and a positive number if if `A>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.

void VL_QSORT_sort_recursive | ( | VL_QSORT_array | array,
|  | vl_uindex | begin,
|  | vl_uindex | end
| ) |  |

inline

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`.

void VL_QSORT_swap | ( | VL_QSORT_array | array,
|  | vl_uindex | indexA,
|  | vl_uindex | indexB
| ) |  |

inline

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 `=`.