in reply to Fast, Efficient Union and Intersection on arrays
my (@a, @b); # initialize @a and @b here my %hash: @hash{@a} = (1) x @a; my @union = @a, grep { !$hash{$_} } @b; my @intersection = grep { $hash{$_} } @b;
That has the advantage of using only one hash, which might buy you some performance. But I don't know if it is actually faster than anything else.
(If you provide a small Benchmark with lists of typical sizes you might get much better answers; for example for a large number of small integers it might be more memory efficient to use vec than a hash, which might in turn result in some performance benefit.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fast, Efficient Union and Intersection on arrays
by TGI (Parson) on Nov 20, 2008 at 18:43 UTC | |
by admiral_grinder (Pilgrim) on Nov 20, 2008 at 21:13 UTC | |
by TGI (Parson) on Nov 20, 2008 at 22:22 UTC | |
by wanradt (Scribe) on Nov 22, 2008 at 10:44 UTC | |
by TGI (Parson) on Nov 24, 2008 at 19:35 UTC |