473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binary searching

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
8 2367
On Sat, 1 May 2004 12:51:02 -0700, Gordon Knote
<an*******@disc ussions.microso ft.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

"Barry Schwarz" <sc******@deloz .net> wrote in message
news:c7******** **@216.39.134.6 9...
On Sat, 1 May 2004 12:51:02 -0700, Gordon Knote
<an*******@disc ussions.microso ft.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.o rg

Nov 17 '05 #3
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
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*******@disc ussions.microso ft.com> wrote in message
news:77******** *************** ***********@mic rosoft.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
"andrea catto'" <ac****@datafli ght.com> wrote in message
news:u$******** ********@TK2MSF TNGP11.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
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******** ******@TK2MSFTN GP12.phx.gbl...
"andrea catto'" <ac****@datafli ght.com> wrote in message
news:u$******** ********@TK2MSF TNGP11.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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2854
by: tsunami | last post by:
hi all; I have an array and want to insert all the elements from this array to a binary search tree.That array is an object of the class of a stringtype which includes overloaded "< > = ==" functions and every other thing it needs. void InsertElementFromArray(StringType Array,int first element,int last element);
28
2808
by: wwj | last post by:
void main() { char* p="Hello"; printf("%s",p); *p='w'; printf("%s",p); }
15
5101
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked lists. I'm totally new to binary searches by the way. Can anyone help me with the commented sections below? Much of the code such as functions and printfs has already been completed. Any help is greatly appreciated. Thanks,
24
3186
by: pristo | last post by:
hello All, how can i insert unique ID into binary file (that created by compiler)? (so after compiling i can to identify the src that i use) thx
10
9783
by: free2cric | last post by:
Hi, I have a single link list which is sorted. structure of which is like typedef struct mylist { int num; struct mylist *next;
3
18459
by: utab | last post by:
Dear all, What are the advantages of binary files over text files? I would like to search for a specific value of a variable in an output file, I was doing this lately by the string library functions of the language. But wondering the advantages of searching and reading from a binary file. If the files get too large, I guess the advantage of reading from a binary file is that it is much faster. Regards,
6
16881
by: fdmfdmfdm | last post by:
This might not be the best place to post this topic, but I assume most of the experts in C shall know this. This is an interview question. My answer is: hash table gives you O(1) searching but according to your hash function you might take more memory than binary tree. On the contrary, binary tree gives you O(logN) searching but less memory. Am I right?
4
5350
by: Hunk | last post by:
Hi I have a binary file which contains records sorted by Identifiers which are strings. The Identifiers are stored in ascending order. I would have to write a routine to give the record given the Identifier. The logical way would be to read the record once and put it in an STL container such as vector and then use lower_bound to search for a given identifier. But for some strange reason i'm asked to not use a container but instead...
0
6982
by: Atos | last post by:
Binary search is used to locate a value in a sorted list of values. It selects the middle element in the array of sorted values, and compares it with the target value; that is the key we are searhing for in the array. If it islower than the target value then the search is made after that middle element and till the end of the array. If it is equal then the target value is found and the middle is returned. Otherwise, search is made from the...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.