The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: UlliN on January 16, 2007, 03:54:47 PM

Title: Confusing BinSearch
Post by: UlliN on January 16, 2007, 03:54:47 PM
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
Title: Re: Confusing BinSearch
Post by: MichaelW on January 16, 2007, 04:43:46 PM
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."
Title: Re: Confusing BinSearch
Post by: UlliN on January 16, 2007, 06:51:59 PM
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]
Title: Re: Confusing BinSearch
Post by: hutch-- on January 16, 2007, 11:18:40 PM
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.