blob: 4e3bc0c14301cd3644fe6f3c6a2569c1515ffdbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*======================================================================
FILE: qsort_gen.h
SPDX-FileCopyrightText: 2018, Markus Minichmayr <markus@tapkey.com>
SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
The Initial Developer of the Original Code is Markus Minichmayr.
======================================================================*/
#ifndef QSORT_GEN_H
#define QSORT_GEN_H
/**
* @file qsort_gen.h
* @brief An implementation of qsort that is more flexible than the version
* provided with stdlib.
*
* In contrast to the qsort provided with stdlib, this version doesn't assume
* that the data to be sorted is stored in a contiguous block of memory.
*/
/**
* @brief Sort an arbitrary list of items using the qsort algorithm.
* @param context A pointer representing the list to be sorted. Won't be
* interpreted by this function but passed to the compar and swapr functions.
* @param nitems The number of items in the list.
* @param compar The comparator function. The function receives the pointer
* to the list to be sorted and the indices of the elements to be compared.
* @param swapr The function used to swap two elements within the list. The
* function receives the pointer to the list to be sorted and the indices of
* the elements to be compared.
*/
void qsort_gen(void *list, size_t nitems,
int(*compar)(const void *, size_t, size_t),
void(*swapr)(void *, size_t, size_t));
/**
* @brief Swaps two arbitrary blocks of memory.
* @param m1 Pointer to the first block of memory.
* @param m2 Pointer to the second block of memory.
* @param size Size of the memory blocks to be swapped.
*/
void qsort_gen_memswap(void *m1, void *m2, size_t size);
#endif /* QSORT_GEN_H */
|