473,796 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bit substring search

I am trying to parse a bit-stream file format (bzip2) that does not have
byte-aligned record boundaries, so I need to do efficient matching of
bit substrings at arbitrary bit offsets.

Is there a package that can do this? This one comes close:

http://ilan.schnell-web.net/prog/bitarray/

but it only supports single bit substring match.

Kris
Jun 27 '08 #1
5 1593
Kris Kennaway:
I am trying to parse a bit-stream file format (bzip2) that does not have
byte-aligned record boundaries, so I need to do efficient matching of
bit substrings at arbitrary bit offsets.
Is there a package that can do this?
You may take a look at Hachoir or some other modules:
http://hachoir.org/wiki/hachoir-core
http://pypi.python.org/pypi/construct/2.00
http://pypi.python.org/pypi/FmtRW/20040603
Etc. More:
http://pypi.python.org/pypi?%3Aactio...ch&term=binary

Bye,
bearophile
Jun 27 '08 #2
be************@ lycos.com wrote:
Kris Kennaway:
>I am trying to parse a bit-stream file format (bzip2) that does not have
byte-aligned record boundaries, so I need to do efficient matching of
bit substrings at arbitrary bit offsets.
Is there a package that can do this?

You may take a look at Hachoir or some other modules:
http://hachoir.org/wiki/hachoir-core
http://pypi.python.org/pypi/construct/2.00
Thanks. hachoir also comes close, but it also doesnt seem to be able to
match substrings at a bit level (e.g. the included bzip2 parser just
reads the header and hands the entire file off to libbzip2 to extract
data from).

construct exports a bit stream but it's again pure python and matching
substrings will be slow. It will need C support to do that efficiently.
http://pypi.python.org/pypi/FmtRW/20040603
Etc. More:
http://pypi.python.org/pypi?%3Aactio...ch&term=binary
Unfortunately I didnt find anything else useful here yet :(

Kris

Jun 27 '08 #3
Kris Kennaway:
Unfortunately I didnt find anything else useful here yet :(
I see, I'm sorry, I have found hachoir quite nice in the past. Maybe
there's no really efficient way to do it with Python, but you can
create a compiled extension, so you can see if it's fast enough for
your purposes.
To create such extension you can:
- One thing that requires very little time is to create an extension
with ShedSkin, once installed it just needs Python code.
- Cython (ex-Pyrex) too may be okay, but it's a bit trikier on Windows
machines.
- Using Pyd to create a D extension for Python is often the faster way
I have found to create extensions. I need just few minutes to create
them this way. But you need to know a bit of D.
- Then, if you want you can write a C extension, but if you have not
done it before you may need some hours to make it work.

Bye,
bearophile
Jun 27 '08 #4
be************@ lycos.com wrote:
Kris Kennaway:
>Unfortunatel y I didnt find anything else useful here yet :(

I see, I'm sorry, I have found hachoir quite nice in the past. Maybe
there's no really efficient way to do it with Python, but you can
create a compiled extension, so you can see if it's fast enough for
your purposes.
To create such extension you can:
- One thing that requires very little time is to create an extension
with ShedSkin, once installed it just needs Python code.
- Cython (ex-Pyrex) too may be okay, but it's a bit trikier on Windows
machines.
- Using Pyd to create a D extension for Python is often the faster way
I have found to create extensions. I need just few minutes to create
them this way. But you need to know a bit of D.
- Then, if you want you can write a C extension, but if you have not
done it before you may need some hours to make it work.
Thanks for the pointers, I think a C extension will end up being the way
to go, unless someone has beaten me to it and I just haven't found it yet.

Kris
Jun 27 '08 #5
Scott David Daniels wrote:
Kris Kennaway wrote:
>Thanks for the pointers, I think a C extension will end up being the
way to go, unless someone has beaten me to it and I just haven't found
it yet.

Depending on the pattern length you are targeting, it may be fastest to
increase the out-of-loop work. For a 40-bit string, build an 8-target
Aho-Corasick machine, and at each match check the endpoints. This will
only work well if 40 bits is at the low end of what you are hunting for.
Thanks, I wasn't aware of Aho-Corasick.

Kris

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2283
by: Nel | last post by:
Hi all, I have been searching for some clues as to how to show a substring from a database search. $pagetitle = "Page Title"; $pagetext = "This is <b>a typical</b> string that would be stored<br>in the database.";
2
1982
by: Larry Woods | last post by:
I want a regular expression that will return TRUE if there is NOT a substring in the string. Example: Return true if the substring "image" is NOT in the string. TIA, Larry Woods
1
8111
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like 'claim%'" This query has substring starting point set to 0. Is there a way to determine the starting point based on the first occurrence of the
7
2207
by: junky_fellow | last post by:
Can anyone suggest some efficient way to search a substring in a text file. For eg. suppose i want to search the pattern "abc" in a text file, then which algorithm should i use. I just want some hints, not the complete program. thanx in advance.....
6
22758
by: becte | last post by:
I am little bit confused Is this a legal way of removing a substring from a string? What about the second alternative using strcpy, is it ok even though the source and dest. strings overlap? // Remove (first occurence of) sub from src void func(char *src, char *sub) { char *p;
3
2307
by: colinhumber | last post by:
How can I use regular expressions to search for a substring within another substring? For example, if I have the string: "This is * some text <button id="123">Some * text</button>" and I only wanted to find the * character(s) that appear within the <button> tags, how could I do that using reg ex? Thanks in advance for the help.
2
6416
by: mallard134 | last post by:
Could someone please help a newbee vb programmer with a question that is driving me crazy. I am trying to understand a line of code that is supposed to return the domain portion of a valid email address. The following code works! ****************************************************************** strEmail = "j...@mydomain.com" String2 = strEmail.Substring(strEmail.IndexOf("@") + 1, _
2
3179
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was a tasty burger"
3
2949
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem in searching out a particular substring in a string. Here the code: --------------------- <html> <script> var tmpString=" ";
4
4923
by: Jean-Guy Mouton | last post by:
Hello, I am teaching myself Dom scripting with Javascript. I do not understand how to get a substring. If I have strings in the form: "This is string number 1" How can I put "1" into a variable to use it elsewhere? I thought I could use the function split and create an array but I have different string lengths with a variable number of words... Can you please help me? Thank you.
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
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...
1
7558
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
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
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
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.