Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arbitrary array length in java

Is there a way to get an array in java which is longer than the length supported by an integer data type?

I'm looking for something that may be indexable using a big integer in Java because the natively supported array length is nowhere near as big as I need it to be for an algorithm I am implementing.

like image 854
Adam Avatar asked Jan 14 '23 11:01

Adam


2 Answers

This library should be useful for you: http://fastutil.dsi.unimi.it/

It says:

"...provides also big (64-bit) arrays..."

like image 172
szegedi Avatar answered Jan 17 '23 17:01

szegedi


Int32 gives you 17 8 gigabytes of storage. Do you have so much memory?

I think you should use sparse arrays, i.e. index elements by hash. For example, with just HashMap<BigInteger,YourValueType> or with some libs like BigMemory and alternatives http://terracotta.org/products/bigmemory

like image 23
Dims Avatar answered Jan 17 '23 16:01

Dims