BigDogArray

BigDogArrays are designed to store extremely large arrays. This is accomplished by internally using an array-of-arrays as a net results they are more complex to work with than DogArrays. In fact, it would be trivial to modify them to exceed the 32-bit limit of Java arrays, but this capability isn’t enabled for backwards compatibility. At least not yet.

ExampleBigDogArray.java

 1 public static void main( String[] args ) {
 2     // Unless you really know what you are doing, use the default constructor
 3     var array = new BigDogArray_I32();
 4 
 5     // It is possible to customize the block size and how the array is grown.
 6     var array = new BigDogArray_I32(10_000, 50_0000, BigDogGrowth.GROW_FIRST);
 7 
 8     // Let's initialize it after pre-allocating memory
 9     array.reserve(50);
10     for (int i = 0; i < 50; i++) {
11         // Set is actually making two array access calls
12         array.set(i, i*2);
13     }
14 
15     // Here's an alternative to do the same thing. It will be smart enough toe process it by blocks
16     // reducing the number of array accesses
17     array.applyIdx(0, 50, ( i, value ) -> i*2);
18 
19     // if you need to process a range of values it's recommended you use forEach or forIdx and it will
20     // handle the internal complexity for you
21     array.forEach(10, 15, v -> System.out.print(v + ","));
22     System.out.println();
23 
24     // If you for some reason need to process a range of values (10 to 20) but need to access the raw
25     // block array, then processByBlock is your friend
26     array.processByBlock(10,20, (block, idx0, idx1, offset)->{
27         // block is the raw array that composes the block
28         // idx0 is the first element in the block that you should process
29         // idx1 is the upper extent, exclusive
30         // offset is the offset to the array's indexing. So block[idx0 + 1] = array[offset + 1]
31         for (int i = idx0; i < idx1; i++) {
32             block[i] = offset + i;
33         }
34     });
35 
36     // Let's see what happened
37     array.forEach(0, 20, v -> System.out.print(v + ","));
38     System.out.println();
39 }