1 | /** @file
|
---|
2 | * IPRT - Sorting.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_sort_h
|
---|
27 | #define IPRT_INCLUDED_sort_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/types.h>
|
---|
33 |
|
---|
34 | /** @defgroup grp_rt_sort RTSort - Sorting Algorithms
|
---|
35 | * @ingroup grp_rt
|
---|
36 | * @{ */
|
---|
37 |
|
---|
38 | RT_C_DECLS_BEGIN
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Callback for comparing two array elements.
|
---|
42 | *
|
---|
43 | * @retval 0 if equal.
|
---|
44 | * @retval -1 if @a pvElement1 comes before @a pvElement2.
|
---|
45 | * @retval 1 if @a pvElement1 comes after @a pvElement2.
|
---|
46 | *
|
---|
47 | * @param pvElement1 The 1st element.
|
---|
48 | * @param pvElement2 The 2nd element.
|
---|
49 | * @param pvUser The user argument passed to the sorting function.
|
---|
50 | */
|
---|
51 | typedef DECLCALLBACK(int) FNRTSORTCMP(void const *pvElement1, void const *pvElement2, void *pvUser);
|
---|
52 | /** Pointer to a compare function. */
|
---|
53 | typedef FNRTSORTCMP *PFNRTSORTCMP;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Sorter function for an array of variable sized elementes.
|
---|
57 | *
|
---|
58 | * @param papvArray The array to sort.
|
---|
59 | * @param cElements The number of elements in the array.
|
---|
60 | * @param cbElement The size of an array element.
|
---|
61 | * @param pfnCmp Callback function comparing two elements.
|
---|
62 | * @param pvUser User argument for the callback.
|
---|
63 | */
|
---|
64 | typedef DECLCALLBACK(void) FNRTSORT(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
65 | /** Pointer to a sorter function for an array of variable sized elements. */
|
---|
66 | typedef FNRTSORT *PFNRTSORT;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Pointer array sorter function.
|
---|
70 | *
|
---|
71 | * @param papvArray The array to sort.
|
---|
72 | * @param cElements The number of elements in the array.
|
---|
73 | * @param pfnCmp Callback function comparing two elements.
|
---|
74 | * @param pvUser User argument for the callback.
|
---|
75 | */
|
---|
76 | typedef DECLCALLBACK(void) FNRTSORTAPV(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
77 | /** Pointer to a pointer array sorter function. */
|
---|
78 | typedef FNRTSORTAPV *PFNRTSORTAPV;
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Shell sort an array of variable sized elementes.
|
---|
82 | *
|
---|
83 | * @param pvArray The array to sort.
|
---|
84 | * @param cElements The number of elements in the array.
|
---|
85 | * @param cbElement The size of an array element.
|
---|
86 | * @param pfnCmp Callback function comparing two elements.
|
---|
87 | * @param pvUser User argument for the callback.
|
---|
88 | */
|
---|
89 | RTDECL(void) RTSortShell(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Same as RTSortShell but speciallized for an array containing element
|
---|
93 | * pointers.
|
---|
94 | *
|
---|
95 | * @param papvArray The array to sort.
|
---|
96 | * @param cElements The number of elements in the array.
|
---|
97 | * @param pfnCmp Callback function comparing two elements.
|
---|
98 | * @param pvUser User argument for the callback.
|
---|
99 | */
|
---|
100 | RTDECL(void) RTSortApvShell(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Checks if an array of variable sized elementes is sorted.
|
---|
104 | *
|
---|
105 | * @returns true if it is sorted, false if it isn't.
|
---|
106 | * @param pvArray The array to check.
|
---|
107 | * @param cElements The number of elements in the array.
|
---|
108 | * @param cbElement The size of an array element.
|
---|
109 | * @param pfnCmp Callback function comparing two elements.
|
---|
110 | * @param pvUser User argument for the callback.
|
---|
111 | */
|
---|
112 | RTDECL(bool) RTSortIsSorted(void const *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Same as RTSortShell but speciallized for an array containing element
|
---|
116 | * pointers.
|
---|
117 | *
|
---|
118 | * @returns true if it is sorted, false if it isn't.
|
---|
119 | * @param papvArray The array to check.
|
---|
120 | * @param cElements The number of elements in the array.
|
---|
121 | * @param pfnCmp Callback function comparing two elements.
|
---|
122 | * @param pvUser User argument for the callback.
|
---|
123 | */
|
---|
124 | RTDECL(bool) RTSortApvIsSorted(void const * const *papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
125 |
|
---|
126 | RT_C_DECLS_END
|
---|
127 |
|
---|
128 | /** @} */
|
---|
129 |
|
---|
130 | #endif /* !IPRT_INCLUDED_sort_h */
|
---|
131 |
|
---|