in reply to Efficient selection mechanism?
Thank you all for your suggestions.
As oiskuu demonstrated, the bit mapped index -- as suggested by Corion, Salva, Choroba & hdb -- is hands down winner in the performance stakes.
By using vec and string-wise boolean operations (Salva,Choroba) rather than numeral ops, I don't have to worry about the size of the small integers outgrowing the platform integer size, which is a slight but possible consideration.
Mixing code from various solutions, this is what I'm using:
use constant MAX => 20; use constant BLANK => chr(0) x ((MAX / 8) + 1); ... my $key = BLANK; vec( $key, $_, 1 ) = 1 for @$_; $cache{ $key } = $_; ... my @subsel = grep{ ( $_ & $mask ) eq BLANK } keys %cache;
And that's it. Thank you all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Efficient selection mechanism? (Thank you all)
by choroba (Cardinal) on Jan 15, 2014 at 12:18 UTC | |
by BrowserUk (Patriarch) on Jan 15, 2014 at 12:47 UTC |