VirtualBox

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

Last change on this file since 84407 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
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
38RT_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 */
51typedef DECLCALLBACK(int) FNRTSORTCMP(void const *pvElement1, void const *pvElement2, void *pvUser);
52/** Pointer to a compare function. */
53typedef 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 */
64typedef 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. */
66typedef 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 */
76typedef DECLCALLBACK(void) FNRTSORTAPV(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
77/** Pointer to a pointer array sorter function. */
78typedef 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 */
89RTDECL(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 */
100RTDECL(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 */
112RTDECL(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 */
124RTDECL(bool) RTSortApvIsSorted(void const * const *papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
125
126RT_C_DECLS_END
127
128/** @} */
129
130#endif /* !IPRT_INCLUDED_sort_h */
131
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette