HyperDbg Debugger
Loading...
Searching...
No Matches
BinarySearch.c File Reference

The file contains array management routines (Binary Search) More...

#include "pch.h"

Functions

VOID BinarySearchPrintArray (UINT64 ArrayPtr[], UINT32 NumberOfItems)
 A utility function to print an array of size NumberOfItems.
 
BOOLEAN BinarySearchPerformSearchItem (UINT64 ArrayPtr[], UINT32 NumberOfItems, UINT32 *ResultIndex, UINT64 Key)
 A utility function to perform the binary search.
 

Detailed Description

The file contains array management routines (Binary Search)

Author
Mohammad K. Fallah (mkf19.nosp@m.80@g.nosp@m.mail..nosp@m.com)
Version
0.5
Date
2023-07-28

Function Documentation

◆ BinarySearchPerformSearchItem()

BOOLEAN BinarySearchPerformSearchItem ( UINT64 ArrayPtr[],
UINT32 NumberOfItems,
UINT32 * ResultIndex,
UINT64 Key )

A utility function to perform the binary search.

Parameters
ArrayPtr
NumberOfItems
ResultIndex
Key
Returns
BOOLEAN
47{
48 UINT32 Position = 0;
49 UINT32 Limit = NumberOfItems;
50
51 while (Position < Limit)
52 {
53 UINT32 TestPos = Position + ((Limit - Position) >> 1);
54
55 if (ArrayPtr[TestPos] < Key)
56 Position = TestPos + 1;
57 else
58 Limit = TestPos;
59 }
60
61 if (Position < NumberOfItems && ArrayPtr[Position] == Key)
62 {
63 //
64 // Set the result position in the array
65 //
66 *ResultIndex = Position;
67 return TRUE;
68 }
69 else
70 {
71 return FALSE;
72 }
73}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48

◆ BinarySearchPrintArray()

VOID BinarySearchPrintArray ( UINT64 ArrayPtr[],
UINT32 NumberOfItems )

A utility function to print an array of size NumberOfItems.

Parameters
ArrayPtr
NumberOfItems
Returns
VOID
24{
25 UINT32 i;
26
27 for (i = 0; i < NumberOfItems; i++)
28 {
29 Log("%llx ", ArrayPtr[i]);
30 }
31
32 Log("\n");
33}
#define Log(format,...)
Log without any prefix.
Definition HyperDbgHyperLogIntrinsics.h:129