Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Code requested for array intersection count

by sauoq (Abbot)
on Jun 09, 2003 at 15:43 UTC ( #264361=note: print w/replies, xml ) Need Help??

in reply to Code requested for array intersection count

As you don't care how many times the items are in array 1, I'd use a hash rather than multiple greps. A hash will make it an O(M + N) algorithm, the greps are an O(M x N) solution. Of course, this will use more memory too and you should take that into consideration when choosing which to use.

my %seen; @seen{@array_1} = (0) x @array_1; exists( $seen{$_} ) and $seen{$_}++ for @array_2;

"My two cents aren't worth a dime.";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2020-08-13 21:17 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (75 votes). Check out past polls.