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.
In reply to As Efficient as Possible by mr_p
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |