Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Suffix-prefix matching done right

by LanX (Saint)
on Nov 05, 2021 at 11:43 UTC ( [id://11138459]=note: print w/replies, xml ) Need Help??


in reply to Suffix-prefix matching done right

Please provide a real test case!

Randomly chosen base64 strings will almost never overlap. And comparing the efficiency of different solutions is not possible with the fuzzy specs given.

So efficiency will also depend on the nature of the real data.

My suggestions:

  • for 2 same length substrings $a (tail $A) and $b (head $B) you'll get the number of missmatches $m by counting the none null bytes in ($a ^ $b)
  • those mismatches have to be <= your allowed threshold $X
  • (see my remarks on no feature 'bitwise' the docs don't seem to be up to date anymore°)

But you don't need to try all possible length, because only a small number of positions are likely:

  • for $X=0 you only need to check those tails in $A which start with the first character $b0 in $B
  • for $X=1 you also need to check those positions which start with the second character $b1 in $B (assuming $b0 was a mismatch)
  • and so on for bigger $X

This should be far more efficient than your code.

updates
  • You've not provided a ranking function, allowing to stop the search for different solutions.

    I.e. when is a longer overlap with one mismatch "better" than a shorter with none?

  • checking base64 for incomplete matches sounds like an XY problem to me

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) euphemism for buggy

edit
added none

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-23 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found