1 | /** @file
|
---|
2 | * IPRT - Sorting.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2011 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_sort_h
|
---|
27 | #define ___iprt_sort_h
|
---|
28 |
|
---|
29 | #include <iprt/types.h>
|
---|
30 |
|
---|
31 | /** @defgroup grp_rt_sort RTSort - Sorting Algorithms
|
---|
32 | * @ingroup grp_rt
|
---|
33 | * @{ */
|
---|
34 |
|
---|
35 | RT_C_DECLS_BEGIN
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Callback for comparing two array elements.
|
---|
39 | *
|
---|
40 | * @retval 0 if equal.
|
---|
41 | * @retval -1 if @a pvElement1 comes before @a pvElement2.
|
---|
42 | * @retval 1 if @a pvElement1 comes after @a pvElement2.
|
---|
43 | *
|
---|
44 | * @param pvElement1 The 1st element.
|
---|
45 | * @param pvElement2 The 2nd element.
|
---|
46 | * @param pvUser The user argument passed to the sorting function.
|
---|
47 | */
|
---|
48 | typedef DECLCALLBACK(int) FNRTSORTCMP(void const *pvElement1, void const *pvElement2, void *pvUser);
|
---|
49 | /** Pointer to a compare function. */
|
---|
50 | typedef FNRTSORTCMP *PFNRTSORTCMP;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Sorter function for an array of variable sized elementes.
|
---|
54 | *
|
---|
55 | * @param papvArray The array to sort.
|
---|
56 | * @param cElements The number of elements in the array.
|
---|
57 | * @param cbElements The size of an array element.
|
---|
58 | * @param pfnCmp Callback function comparing two elements.
|
---|
59 | * @param pvUser User argument for the callback.
|
---|
60 | */
|
---|
61 | typedef DECLCALLBACK(void) FNRTSORT(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
62 | /** Pointer to a sorter function for an array of variable sized elements. */
|
---|
63 | typedef FNRTSORT *PFNRTSORT;
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Pointer array sorter function.
|
---|
67 | *
|
---|
68 | * @param papvArray The array to sort.
|
---|
69 | * @param cElements The number of elements in the array.
|
---|
70 | * @param pfnCmp Callback function comparing two elements.
|
---|
71 | * @param pvUser User argument for the callback.
|
---|
72 | */
|
---|
73 | typedef DECLCALLBACK(void) FNRTSORTAPV(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
74 | /** Pointer to a pointer array sorter function. */
|
---|
75 | typedef FNRTSORTAPV *PFNRTSORTAPV;
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Shell sort an array of variable sized elementes.
|
---|
79 | *
|
---|
80 | * @param papvArray The array to sort.
|
---|
81 | * @param cElements The number of elements in the array.
|
---|
82 | * @param cbElements The size of an array element.
|
---|
83 | * @param pfnCmp Callback function comparing two elements.
|
---|
84 | * @param pvUser User argument for the callback.
|
---|
85 | */
|
---|
86 | RTDECL(void) RTSortShell(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Same as RTSortShell but speciallized for an array containing element
|
---|
90 | * pointers.
|
---|
91 | *
|
---|
92 | * @param papvArray The array to sort.
|
---|
93 | * @param cElements The number of elements in the array.
|
---|
94 | * @param pfnCmp Callback function comparing two elements.
|
---|
95 | * @param pvUser User argument for the callback.
|
---|
96 | */
|
---|
97 | RTDECL(void) RTSortApvShell(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Checks if an array of variable sized elementes is sorted.
|
---|
101 | *
|
---|
102 | * @returns true if it is sorted, false if it isn't.
|
---|
103 | * @param papvArray The array to check.
|
---|
104 | * @param cElements The number of elements in the array.
|
---|
105 | * @param cbElements The size of an array element.
|
---|
106 | * @param pfnCmp Callback function comparing two elements.
|
---|
107 | * @param pvUser User argument for the callback.
|
---|
108 | */
|
---|
109 | RTDECL(bool) RTSortIsSorted(void const *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Same as RTSortShell but speciallized for an array containing element
|
---|
113 | * pointers.
|
---|
114 | *
|
---|
115 | * @returns true if it is sorted, false if it isn't.
|
---|
116 | * @param papvArray The array to check.
|
---|
117 | * @param cElements The number of elements in the array.
|
---|
118 | * @param pfnCmp Callback function comparing two elements.
|
---|
119 | * @param pvUser User argument for the callback.
|
---|
120 | */
|
---|
121 | RTDECL(bool) RTSortApvIsSorted(void const * const *papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
|
---|
122 |
|
---|
123 | RT_C_DECLS_END
|
---|
124 |
|
---|
125 | /** @} */
|
---|
126 |
|
---|
127 | #endif
|
---|
128 |
|
---|