]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BaseSortLib/BaseSortLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / BaseSortLib / BaseSortLib.c
1 /** @file
2 Library used for sorting routines.
3
4 Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8 #include <Uefi.h>
9
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/SortLib.h>
15
16 /**
17 Function to perform a Quick Sort alogrithm on a buffer of comparable elements.
18
19 Each element must be equal sized.
20
21 if BufferToSort is NULL, then ASSERT.
22 if CompareFunction is NULL, then ASSERT.
23
24 if Count is < 2 then perform no action.
25 if Size is < 1 then perform no action.
26
27 @param[in, out] BufferToSort on call a Buffer of (possibly sorted) elements
28 on return a buffer of sorted elements
29 @param[in] Count the number of elements in the buffer to sort
30 @param[in] ElementSize Size of an element in bytes
31 @param[in] CompareFunction The function to call to perform the comparison
32 of any 2 elements
33 **/
34 VOID
35 EFIAPI
36 PerformQuickSort (
37 IN OUT VOID *BufferToSort,
38 IN CONST UINTN Count,
39 IN CONST UINTN ElementSize,
40 IN SORT_COMPARE CompareFunction
41 )
42 {
43 VOID *Buffer;
44
45 ASSERT (BufferToSort != NULL);
46 ASSERT (CompareFunction != NULL);
47
48 Buffer = AllocateZeroPool (ElementSize);
49 ASSERT (Buffer != NULL);
50
51 QuickSort (
52 BufferToSort,
53 Count,
54 ElementSize,
55 CompareFunction,
56 Buffer
57 );
58
59 FreePool (Buffer);
60 return;
61 }
62
63 /**
64 Not supported in Base version.
65
66 @param[in] Buffer1 Ignored.
67 @param[in] Buffer2 Ignored.
68
69 ASSERT and return 0.
70 **/
71 INTN
72 EFIAPI
73 DevicePathCompare (
74 IN CONST VOID *Buffer1,
75 IN CONST VOID *Buffer2
76 )
77 {
78 ASSERT (FALSE);
79 return 0;
80 }
81
82 /**
83 Not supported in Base version.
84
85 @param[in] Buffer1 Ignored.
86 @param[in] Buffer2 Ignored.
87
88 ASSERT and return 0.
89 **/
90 INTN
91 EFIAPI
92 StringNoCaseCompare (
93 IN CONST VOID *Buffer1,
94 IN CONST VOID *Buffer2
95 )
96 {
97 ASSERT (FALSE);
98 return 0;
99 }
100
101 /**
102 Not supported in Base version.
103
104 @param[in] Buffer1 Ignored.
105 @param[in] Buffer2 Ignored.
106
107 ASSERT and return 0.
108 **/
109 INTN
110 EFIAPI
111 StringCompare (
112 IN CONST VOID *Buffer1,
113 IN CONST VOID *Buffer2
114 )
115 {
116 ASSERT (FALSE);
117 return 0;
118 }