By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

Binary searching

P: n/a
Hi

can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++).
The search should be as fast as possible and it would be great if the engine (or so) would accept multiple parameters (like a search offset, a max number of bytes to search in etc.)

Any ideas

Thanks a lot again

Gordon
Nov 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Sat, 1 May 2004 12:51:02 -0700, Gordon Knote
<an*******@discussions.microsoft.com> wrote:
Hi,

can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++).
The search should be as fast as possible and it would be great if the engine (or so) would accept multiple parameters (like a search offset, a max number of bytes to search in etc.).

Give us a hint. Are you searching a file? Memory? An array? A
linked list? An access data base?
<<Remove the del for email>>
Nov 17 '05 #2

P: n/a

"Barry Schwarz" <sc******@deloz.net> wrote in message
news:c7**********@216.39.134.69...
On Sat, 1 May 2004 12:51:02 -0700, Gordon Knote
<an*******@discussions.microsoft.com> wrote:
Hi,

can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++).The search should be as fast as possible and it would be great if the engine (or so) would accept multiple parameters (like a search offset, a max
number of bytes to search in etc.).

Give us a hint. Are you searching a file? Memory? An array? A
linked list? An access data base?


And what are you searching for? A substring? A token? Is the list
pre-sorted?

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
-g*******@mvps.org

Nov 17 '05 #3

P: n/a
It all depends upon the nature of the search that u r looking for .. if u
will explain the whole nature of search that u wan to have in ur program
then there will be suggestions .. right now ..there is nothing clear. enough
to say some thing .. but as u said u need multiple parameters to be accepted
... then it is easily done .. with functions .. but the prupose is not clear
as yet ..

sam
saleem ullah khan
Nov 17 '05 #4

P: n/a
the best way to binary search is to use the C provided library, best because
simplest.
I can't recall what's the name, something like search/find, bsearch....
whatever

yes, it's limited, but 99% it'll work.

the binary search is such a piece of cake to do, that you might as well
doing by yourself.
binary search = also dictionary search, that is calculate the middle element
and compare to your item...
if greater consuider now the second half and redivide otherwise consider the
first half.
it's a logarithmic response it's the best BUT............. how do you have
items inserted ????

consider learning what a Btree is and it's balancing, btree is ideally just
as fast when it comes to searching, because it still goes left/right
dividing each time ......... but it's also immensly fast in inserting
items....

"Gordon Knote" <an*******@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Hi,

can anyone tell me what's the best way to search in binary content? Best if someone could post or link me to some source code (in C/C++). The search should be as fast as possible and it would be great if the engine (or so) would accept multiple parameters (like a search offset, a max
number of bytes to search in etc.).
Any ideas?

Thanks a lot again,

Gordon

Nov 17 '05 #5

P: n/a
"andrea catto'" <ac****@dataflight.com> wrote in message
news:u$****************@TK2MSFTNGP11.phx.gbl...
the binary search is such a piece of cake to do, that you might as well
doing by yourself.


I agree it's a good exercise, but not because it's a piece of
cake. Binary search offers a minefield of off-by-one errors.
Good luck.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 17 '05 #6

P: n/a
I know the question involved searches for binary content, but I must digress
to point out a terrific source for sophisticated text-searching algorithms
at Thierry Lecroq's site: http://www-igm.univ-mlv.fr/~lecroq/string/

The site gives excellent theoretical treatment to many text-searching
algorithms.

But most commendably, the site gives C code for the algorithms _AND_ working
Java simulations of the progression of each algorithm.

It's well worth a visit.

Regards,
Mike
"P.J. Plauger" <pj*@dinkumware.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
"andrea catto'" <ac****@dataflight.com> wrote in message
news:u$****************@TK2MSFTNGP11.phx.gbl...
the binary search is such a piece of cake to do, that you might as well
doing by yourself.


I agree it's a good exercise, but not because it's a piece of
cake. Binary search offers a minefield of off-by-one errors.
Good luck.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

Nov 17 '05 #7

P: n/a
Michael K. O'Neill wrote:
I know the question involved searches for binary content, but I must
digress to point out a terrific source for sophisticated
text-searching algorithms at Thierry Lecroq's site:
http://www-igm.univ-mlv.fr/~lecroq/string/

The site gives excellent theoretical treatment to many text-searching
algorithms.

But most commendably, the site gives C code for the algorithms _AND_
working Java simulations of the progression of each algorithm.

It's well worth a visit.


Yes - that's a great site! (I'd seen it before, but long ago lost the link
to it).

I'd point out that "binary searching" is in no way different from "text
searching", except that the alphabet is larger (and possibly includes
unprintable characters). That means that all of these "exact string
matching algorithms" are perfectly applicable to binary searching.

-cd
Nov 17 '05 #8

P: n/a
andrea catto' wrote:
the best way to binary search is to use the C provided library, best
because simplest.
I can't recall what's the name, something like search/find,
bsearch.... whatever

yes, it's limited, but 99% it'll work.

the binary search is such a piece of cake to do, that you might as
well doing by yourself.


You're talking about using a binary reduction searching algorithm. The OP
was talking about searching unsorted binary data. Two unrelated topics with
similar names.

-cd

Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.