Search code examples
javatypeslarge-data-volumes

How would you handle making an array or list that would have more entries than the standard implementation would allow you to access


I am trying to create an array or list that could handle in theory, given adequate hardware and such, as many as 100^100 BigInteger entries. The problem with using an array or standard list is that they can only hold Integer.MAX_VALUE number of entries. How would you work around this limitations? A whole new class/interface? A wrapper for list? another data type entirely?


Solution

  • A 22-dimensional java array would have enough space to hold the data - in theory.

    But we should keep in mind, that the number of atoms in the whole universe is estimated to 10^78 (ref in German).

    So, before starting to implement, you'd have to think how to store 10^23 bytes on every atom in the universe...

    Edit

    In general, if you need large datastructures that support access in O(1), you can create multidimensional arrays.

    A 2-dimensional array array[Integer.MAX_VALUE][Integer.MAX_VALUE] can hold about 4.6x10^18 values. You can address each value ai by array[ai mod Integer.MAX_VALUE][ai div Integer.MAX_VALUE]. And of course this works for higher-dimensional arrays aswell.