Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Find repeated patterns in strings

by bioMan (Beadle)
on Oct 04, 2005 at 17:16 UTC ( [id://497340]=note: print w/replies, xml ) Need Help??


in reply to Re: Find repeated patterns in strings
in thread Find repeated patterns in strings

Gentlemen,

We seem to have moved off point from the original problem. It was my original post (Search for identical strings) which sent Grandfather on his quest to optimize a search for identical substrings within a string.

If I read this regex correctly it doesn't do what I originally asked for. That is, to find the longest set of identical substrings anywhere within a parent string.

If I read the regex in findCycle_2 correctly it looks for a string of characters that must begin at the start of the parent string, and this substring is immediately followed by zero or more copies of itself to the end of the parent string. My original code also used a regex

/(.+).*\1/

The time estimate for a search of my original data set was around 3 years! (But my data set is very large.) The time estimate was based on how long it took to search a subset of my dataset. My biggest problem appears to be with regex backtracking.

Anyway, back to findCycle_2. Using a test string of 'ABCDEFG123456ABCDEFG' findCycle_2 returns the entire 20 character string because it found the string but no copies of itself. If I force the presence of a second copy of the substring with

/^(.*?)\1$/

I get nothing. If I allow intervening trash with

/^(.*?).*\1$/

I get nothing. In order for the regex to find any occurrence of the longest paired substrings within a parent string it appears that the regex should be written

/(.+).*\1/

And this appears to return me to the three year run.

I should note that Grandfather created a script which ran in under a minute for my entire dataset and found over 98% of the paired substrings.

Mike

Replies are listed 'Best First'.
Re^3: Find repeated patterns in strings
by QM (Parson) on Oct 04, 2005 at 18:11 UTC
    You note that find_cycle_2seems to be broken, or at the very least doing something else.

    The lesson learned here is that benchmarks must be accompanied by tests to prove that the code actually works as intended.

    If it doesn't work, it doesn't matter how fast it is.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-19 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found