I want to define
isGood[___] = False; isGood[#] = True & /@ list
list is a list of several million integers. What's the fastest way of doing this?
As J. M. suggested:
On my computer, this takes about 3 seconds for a million integers. Isn't this fast enough?
Retrieval of the results is also quite quick:
Out of curiosity, I compared this to the undocumented
We see that retrieval is a bit faster, but putting the keys into the
Are you sure you want to use
This seems to be faster to define downvalues
My solution is ugly, but task-specific. It builds a bitmap out of machine-sized integers in imperative fashion and uses Compile. This works reasonably in memory usage for ranges that have at least couple percent of True values.
A million integers:
Originally I wanted to solve this problem using bitwise operations of arbitrarily large integers, but the issue with that is that functional programming with bigints has large return value overheads - even when just some individual bits are twiddled.