News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Confusing BinSearch

Started by UlliN, January 16, 2007, 03:54:47 PM

Previous topic - Next topic

UlliN

Hello,

I'm a little bit confused about the description of "BinSearch" :
BinSearch searchs a source string for a sub string and if found, return the zero based offset of the sub string.
This algorithm is ideally suited for binary search ...

AFAIK "Binary search" is normally used to search a sorted table, just like the C-bsearch or COBOL "Search All" do.
Am I wrong or is my english to bad?

Regards
Ulli

MichaelW

When I first saw the name I too was expecting a binary search algorithm. "Binary" in this case refers to binary data. The length of the "strings" is specified, so the code does not depend on null terminators, and since it does straight byte comparisons "it can be used for searching binary files for BYTE sequences."
eschew obfuscation

UlliN

Thank you Michael,

if you don't mind, here is a real ;-) binary search algo using sorted tables. The proc name "SearchAll" was inspired by the COBOL-command "Search all", which does the same. If the table contains duplicate items, you can use a derivate SearchAll1, which returns the lowest valid index (if found). An appropriate string comparison algo is added.
Enjoy it.
Should I post the code in the laboratory for improvement too?

Regards
Ulli






[attachment deleted by admin]

hutch--

Ulli,

Its a good idea to post algos in the Laboratory as more people will get to see it as an algo and you may get some input with its design or optimisation as well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php