/** * Recursively allocate the first dimensionsToPreallocate dimensions of the tree * * Pre-allocating the first few dimensions helps limit contention during tree traversals in put() * * @param subarray current node in the tree * @param dimension current level in the tree * @param dimensionsToPreallocate preallocate only this many dimensions (starting from the first) */ private void preallocateArray( Object[] subarray, int dimension, int dimensionsToPreallocate ) { if ( dimension >= dimensionsToPreallocate - 1 ) { return; } for ( int i = 0; i < subarray.length; i++ ) { subarray[i] = new Object[dimensions[dimension + 1]]; preallocateArray((Object[])subarray[i], dimension + 1, dimensionsToPreallocate); } }
public NestedIntegerArray(final int... dimensions) { numDimensions = dimensions.length; if ( numDimensions == 0 ) throw new ReviewedGATKException("There must be at least one dimension to an NestedIntegerArray"); this.dimensions = dimensions.clone(); int dimensionsToPreallocate = Math.min(dimensions.length, NUM_DIMENSIONS_TO_PREALLOCATE); if ( logger.isDebugEnabled() ) logger.debug(String.format("Creating NestedIntegerArray with dimensions %s", Arrays.toString(dimensions))); if ( logger.isDebugEnabled() ) logger.debug(String.format("Pre-allocating first %d dimensions", dimensionsToPreallocate)); data = new Object[dimensions[0]]; preallocateArray(data, 0, dimensionsToPreallocate); if ( logger.isDebugEnabled() ) logger.debug(String.format("Done pre-allocating first %d dimensions", dimensionsToPreallocate)); }