Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Comparison by position and value

by gaal (Parson)
on Jan 02, 2005 at 15:41 UTC ( #418791=note: print w/replies, xml ) Need Help??

in reply to Comparison by position and value

This is essentially the same as substr and a hash, but will run faster. Forgive the funky pseudocode.

sub is_compatible { my T, B; foreach i from 0 .. stringlen { next if top[i] eq bottom[i] if top[i] is a digit return NOT COMPATIBLE if bottom[i] is a digit T |= top[i] if bottom[i] is a digit B |= bottom[i] } return T&B ? NOT COMPATIBLE : COMPATIBLE }

Assumptions: your "digits" are weakly fewer in number than your integer1 width. If by digit you really do mean 0 .. 9, I think this obtains on all the machines Perl runs on. In which case you can also optimize "is a digit" with low-level ASCII checks. Also, you should probably only split each string once instead of seeking into it. If this isn't fast enough, this is a good candidate for inlining in c.

1 More precisely, whatever does efficient bitwise arithmetic.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2023-10-04 19:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found