ReactOS 0.4.15-dev-7654-g6bc40d3
utils.c File Reference
#include "console.h"
#include <debug.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

UINT BisectListSortedByValueEx (IN PLIST_CTL ListCtl, IN ULONG_PTR Value, IN UINT itemStart, IN UINT itemEnd, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
 
UINT BisectListSortedByValue (IN PLIST_CTL ListCtl, IN ULONG_PTR Value, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file utils.c.

Function Documentation

◆ BisectListSortedByValue()

UINT BisectListSortedByValue ( IN PLIST_CTL  ListCtl,
IN ULONG_PTR  Value,
OUT PUINT pValueItem  OPTIONAL,
IN BOOL  BisectRightOrLeft 
)

Definition at line 115 of file utils.c.

120{
121 INT iItemEnd = ListCtl->GetCount(ListCtl);
122 if (iItemEnd == CB_ERR || iItemEnd <= 0)
123 return CB_ERR; // Fail
124
125 return BisectListSortedByValueEx(ListCtl, Value,
126 0, (UINT)(iItemEnd - 1),
127 pValueItem,
128 BisectRightOrLeft);
129}
UINT BisectListSortedByValueEx(IN PLIST_CTL ListCtl, IN ULONG_PTR Value, IN UINT itemStart, IN UINT itemEnd, OUT PUINT pValueItem OPTIONAL, IN BOOL BisectRightOrLeft)
Definition: utils.c:39
unsigned int UINT
Definition: ndis.h:50
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define CB_ERR
Definition: winuser.h:2434

Referenced by AddCodePage(), BuildCodePageList(), EnumFontSizesProc(), and FontSizeList_SelectFontSize().

◆ BisectListSortedByValueEx()

UINT BisectListSortedByValueEx ( IN PLIST_CTL  ListCtl,
IN ULONG_PTR  Value,
IN UINT  itemStart,
IN UINT  itemEnd,
OUT PUINT pValueItem  OPTIONAL,
IN BOOL  BisectRightOrLeft 
)

Definition at line 39 of file utils.c.

46{
47 UINT iItemStart, iItemEnd, iItem;
48 ULONG_PTR itemData;
49
50 /* Sanity checks */
51 if (itemStart > itemEnd)
52 return CB_ERR; // Fail
53
54 /* Initialize */
55 iItemStart = itemStart;
56 iItemEnd = itemEnd;
57 iItem = iItemStart;
58
59 if (pValueItem)
60 *pValueItem = CB_ERR;
61
62 while (iItemStart <= iItemEnd)
63 {
64 /*
65 * Bisect. Note the following:
66 * - if iItemEnd == iItemStart + 1, then iItem == iItemStart;
67 * - if iItemStart == iItemEnd, then iItemStart == iItem == iItemEnd.
68 * In all but the last case, iItemStart <= iItem < iItemEnd.
69 */
70 iItem = (iItemStart + iItemEnd) / 2;
71
72 itemData = ListCtl->GetData(ListCtl, iItem);
73 if (itemData == CB_ERR)
74 return CB_ERR; // Fail
75
76 if (Value == itemData)
77 {
78 /* Found a candidate */
79 if (pValueItem)
80 *pValueItem = iItem;
81
82 /*
83 * Try to find the last element (if BisectRightOrLeft == TRUE)
84 * or the first element (if BisectRightOrLeft == FALSE).
85 */
86 if (BisectRightOrLeft)
87 {
88 iItemStart = iItem + 1; // iItemStart may be > iItemEnd
89 }
90 else
91 {
92 if (iItem <= itemStart) break;
93 iItemEnd = iItem - 1; // iItemEnd may be < iItemStart, i.e. iItemStart may be > iItemEnd
94 }
95 }
96 else if (Value < itemData)
97 {
98 if (iItem <= itemStart) break;
99 /* The value should be before iItem */
100 iItemEnd = iItem - 1; // iItemEnd may be < iItemStart, i.e. iItemStart may be > iItemEnd, if iItem == iItemStart.
101 }
102 else // if (itemData < Value)
103 {
104 /* The value should be after iItem */
105 iItemStart = iItem + 1; // iItemStart may be > iItemEnd, if iItem == iItemEnd.
106 }
107
108 /* Here, iItemStart may be == iItemEnd */
109 }
110
111 return iItemStart;
112}
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by BisectListSortedByValue().