VirtualBox

source: vbox/trunk/include/iprt/sort.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/** @file
2 * IPRT - Sorting.
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
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 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
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
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.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_sort_h
37#define IPRT_INCLUDED_sort_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/types.h>
43
44/** @defgroup grp_rt_sort RTSort - Sorting Algorithms
45 * @ingroup grp_rt
46 * @{ */
47
48RT_C_DECLS_BEGIN
49
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 */
61typedef DECLCALLBACKTYPE(int, FNRTSORTCMP,(void const *pvElement1, void const *pvElement2, void *pvUser));
62/** Pointer to a compare function. */
63typedef FNRTSORTCMP *PFNRTSORTCMP;
64
65/**
66 * Sorter function for an array of variable sized elementes.
67 *
68 * @param pvArray The array to sort.
69 * @param cElements The number of elements in the array.
70 * @param cbElement The size of an array element.
71 * @param pfnCmp Callback function comparing two elements.
72 * @param pvUser User argument for the callback.
73 */
74typedef DECLCALLBACKTYPE(void, FNRTSORT,(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser));
75/** Pointer to a sorter function for an array of variable sized elements. */
76typedef 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 */
86typedef DECLCALLBACKTYPE(void, FNRTSORTAPV,(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser));
87/** Pointer to a pointer array sorter function. */
88typedef FNRTSORTAPV *PFNRTSORTAPV;
89
90/**
91 * Shell sort an array of variable sized elementes.
92 *
93 * @param pvArray The array to sort.
94 * @param cElements The number of elements in the array.
95 * @param cbElement The size of an array element.
96 * @param pfnCmp Callback function comparing two elements.
97 * @param pvUser User argument for the callback.
98 */
99RTDECL(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 */
110RTDECL(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.
116 * @param pvArray The array to check.
117 * @param cElements The number of elements in the array.
118 * @param cbElement The size of an array element.
119 * @param pfnCmp Callback function comparing two elements.
120 * @param pvUser User argument for the callback.
121 */
122RTDECL(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 */
134RTDECL(bool) RTSortApvIsSorted(void const * const *papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
135
136RT_C_DECLS_END
137
138/** @} */
139
140#endif /* !IPRT_INCLUDED_sort_h */
141
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use