in reply to Re^4: Best method to diff large array
in thread Best method to diff very large array efficiently
For integers, this will beat using hashes hands-down:
@a1 = map int( rand 1e6 ), 1 .. 8000; @a2 = map int( rand 1e6 ), 1 .. 6000;; vec( $vec, $_, 1 )=1 for @a2;; @missingFromA2 = grep !vec( $vec, $_, 1 ), @a1;;
A note of caution, if the integers can be bigger than say 2**30, then this won't work properly on older perls; and would consume large amounts of memory on newer perls. But if your integers are less than that, it is very, very fast.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Best method to diff large array
by didier (Vicar) on Nov 25, 2013 at 20:24 UTC |