VirtualBox

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

Last change on this file since 48418 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
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
35RT_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 */
48typedef DECLCALLBACK(int) FNRTSORTCMP(void const *pvElement1, void const *pvElement2, void *pvUser);
49/** Pointer to a compare function. */
50typedef 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 */
61typedef 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. */
63typedef 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 */
73typedef DECLCALLBACK(void) FNRTSORTAPV(void **papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
74/** Pointer to a pointer array sorter function. */
75typedef 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 */
86RTDECL(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 */
97RTDECL(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 */
109RTDECL(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 */
121RTDECL(bool) RTSortApvIsSorted(void const * const *papvArray, size_t cElements, PFNRTSORTCMP pfnCmp, void *pvUser);
122
123RT_C_DECLS_END
124
125/** @} */
126
127#endif
128
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