mr_p has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I want to make this function efficient as possible. Can someone please let me know what I need to change or add to make it so.
This function takes two arrays and diffs them, and updates $my_bonly with if element does not exist in @a_ref and it does in @b_ref. Also, combines the intersection of @a_ref and @b_ref with @my_bonly.
sub deDuppedArray { my ($a_ref, $b_ref, $my_bonly, $my_isec_plus_bonly) = @_; # refere +nce my (%Aseen, %Bseen, %count, @isec, @diff, @union, @aonly) = (); @Aseen{@$a_ref} = (); # lookup table @Bseen{@$b_ref} = (); # lookup table foreach my $e (@$a_ref, @$b_ref) { $count{$e}++ } # put all items +in hash table foreach my $e (keys %count) { # interate over each key of hash table push(@union, $e); # keys of hash table = union if ($count{$e} == 2) { push @isec, $e; # seen more than once = intersection } else { push(@aonly, $e) unless exists $Bseen{$e}; # seen once + f +rom A = Aonly push(@$my_bonly, $e) unless exists $Aseen{$e}; # seen once + + from A = Aonly } } @$my_isec_plus_bonly = ( @isec, @$my_bonly); }
previously working on thread: http://www.perlmonks.org/?node_id=832494
I don't believe this is not efficient, but I want everyones opinion on how to make it more faster like. Whether if I can do what I'm doing faster using different method.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: As Efficient as Possible
by BrowserUk (Patriarch) on Apr 02, 2010 at 21:27 UTC | |
by mr_p (Scribe) on Apr 02, 2010 at 21:49 UTC | |
by BrowserUk (Patriarch) on Apr 02, 2010 at 22:11 UTC | |
by mr_p (Scribe) on Apr 02, 2010 at 22:24 UTC | |
Re: As Efficient as Possible
by ww (Archbishop) on Apr 02, 2010 at 20:42 UTC | |
by mr_p (Scribe) on Apr 02, 2010 at 21:27 UTC | |
Re: As Efficient as Possible
by crashtest (Curate) on Apr 02, 2010 at 21:40 UTC | |
by BrowserUk (Patriarch) on Apr 02, 2010 at 22:14 UTC | |
by mr_p (Scribe) on Apr 02, 2010 at 22:22 UTC | |
by roboticus (Chancellor) on Apr 03, 2010 at 00:38 UTC | |
by pemungkah (Priest) on Apr 04, 2010 at 00:21 UTC | |
| |
by mr_p (Scribe) on Apr 02, 2010 at 22:09 UTC | |
Re: As Efficient as Possible
by moritz (Cardinal) on Apr 02, 2010 at 20:40 UTC |