I want to define
isGood[___] = False;
isGood[#] = True & /@ list
where list is a list of several million integers. What's the fastest way of doing this?
|
I want to define
where |
||||
|
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
Query values:
|
|||||
|
|
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:
Function itself:
Usage:
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. |
|||||
|
Scan[]instead ofMap[], for starters... is there no regular pattern to these "several million integers" that can possibly be exploited? – J. M.♦ Oct 25 '12 at 16:44