Suppose I have two arrays of positive integers, @one and @two, potentially containing several thousand elements.
I want to compute the array @inter which contains those elements which are in both @one and @two, and the array @union which contains those elements which are in either @one or @two.
Here's my first cut at doing this:
intersection: Pick one of the arrays, put the other in a hash with duumy values, and loop through the first array, adding the elements which are also in the other array to @inter.
union: Put both arrays in the same hash with dummy values, so duplicates are ignored, then extract the keys.
Does anyone know a better way of doing this?