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