in reply to Re^3: fast+generic interface for range-based indexed retrieval
in thread fast+generic interface for range-based indexed retrieval
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: fast+generic interface for range-based indexed retrieval
by BrowserUk (Patriarch) on Dec 14, 2008 at 09:17 UTC | |
Yes, I do need all those decimal places sometimes. Okay. There is always more than one way to skin a cat. Since you need 11 significant digits to store your 0 - 10,000 range with seven decimal places, and that's too big for an integer, partition the dataset. If you split your floats into their integer and decimal parts, you can then scale the decimal part (multiply by 10e6) and the result fits easily into a 32-bit int. You can now store these packed in an array of strings of sorted packed ints:
This requires 381MB per 100 million floats, allowing a typical 32-bit machine to store 500+ million in ram. To lookup a range, you split the start value into its integer and scaled decimal parts and do a binary chop on the packed integers in the scalar indexed by the integer part. The initial bucket lookup subdivides the total number of floats into 10,000 sets making the binary search require best case (assuming 100 million evenly distributed data points), log2( 100e6/10e3 )=10 probes. Worst case, log2( 100e6 )=19 probes. To put that into some perspective, it takes just over 5 seconds to locate and iterate 1 million "doubles" amongst 100 million:
which is probably faster than you can locate the first one using most DBs. That average lookup time of 5 microseconds per element of the range, is remarkably consistant in my (unthorough and unscientific) testing.
Let me know if you're interested in the POC code. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Dec 16, 2008 at 19:25 UTC | |
Per a private request, here is the proof-of-concept code used to test the idea above, with the addition of some comments:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |