Ask HN: How would you handle items' IDs beyond 2^64 (18.4 quintillion)?
Assuming that 2^64 is now the maximum number a computer can handle at once, what's the best way you can handle the ID numbering system when there are more than 2^64 items?
Assuming that 2^64 is now the maximum number a computer can handle at once, what's the best way you can handle the ID numbering system when there are more than 2^64 items?
https://www.wolframalpha.com/input/?i=2%5E64+divided+by+%28p...
What can you do best when you run out of unique combinations and the CPU can't handle more than 64 slots at a time? Upgrade to 128-bit architecture is not the answer I'm seeking.
arc> (expt 2 64)
18446744073709551616
arc> (expt 2 65)
36893488147419103232
arc> (expt 2 165)
46768052394588893382517914646921056628989841375232
Note that this isn't converting the number to a floating-point; it's exact precision: arc> (+ (expt 2 165) 1)
46768052394588893382517914646921056628989841375233In a 64-bit architecture, the data bus or datapath width will be 64-bit long. That is, we only have 2^64 unique numbers to pass in the CPU at a time. What's the best to do when we need more unique figures? Use unsigned integers, for instance?
2^64 is the number of combinations not the the maximum number itself.
Use data structures that are too big to fit in the CPU all at once. The same way that we did on 8-bit CPUs when we needed more than 256 unique ID values. The problem is vastly more rare with 64-bit machines, but the solution remains the same.
Obviously, comparing such value takes more clock cycles than comparing values that fit in the CPU all at once, but that's the price you have to pay.
> Use unsigned integers, for instance?
Signed vs. unsigned, with the same width, provides the same number of unique values. Just different values. So that wouldn't help.
Unless you had been reserving negative values to mark errors when returning ids, in which case making use of that top bit as id space lets you double the number of ids. Of course, you could still treat it as signed or unsigned... it's just a possibly related issue.
My question is: what about the case when the number is longer by one bit, let's say? What's the best/most efficient way to handle it?
Here's a good sort of survey piece to read:
https://www.imperialviolet.org/2010/12/04/ecc.html
You'll be particularly interested in the limb scheduling optimization, which is tailored to the processor.
Great read by the way. Thank you.
If GMP is not suitable, you're probably doing something fairly unique. In that case, details matter, like language, architecture, etc.
To be more clear, let's suppose that the maximum a CPU can read at once is one character (8 bits). If we went by your suggestion to add one or two extra characters [on the high level], or 16 bits [on the lower level], the processor won't be able to handle the 24 (8 + 16) at one time, simply because the max is 8 at a time.
Go to the edge, then add a bit.
Or, whatever, get two computers. Or twenty, they're cheap.