Package dk.alexandra.fresco.stat.utils
Class MultiDimensionalArray<T>
Object
AbstractCollection<T>
MultiDimensionalArray<T>
- Type Parameters:
T
- The type of objects stored in the array.
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
public abstract class MultiDimensionalArray<T> extends AbstractCollection<T>
A multi-dimensional array is a data collection where entries are indexed by a fixed length vector
(the length equals the dimension of the array). The elements are stored recursively using nested
instances
ArrayList
's, so the complexity of get and set operations are linear in the
depth of the array.-
Constructor Summary
Constructors Constructor Description MultiDimensionalArray()
-
Method Summary
Modifier and Type Method Description static <S> MultiDimensionalArray<S>
build(int width, IntFunction<MultiDimensionalArray<S>> populator)
Create a new MultiDimensionalArray.static <S> MultiDimensionalArray<S>
build(List<Integer> shape, Function<List<Integer>,S> populator)
Create a new multi-dimensional array with the given shape and with each entry being generated by the populator function.static <S> MultiDimensionalArray<S>
build(List<S> entries)
Create a new one-dimensional array with the given entries.void
forEachWithIndices(BiConsumer<T,List<Integer>> consumer)
Perform an operation on all elementsT
get(int[] index)
Get the element in this array with the given index vector.T
get(Integer... index)
Get the element in this array with the given index vector.abstract T
get(List<Integer> index)
Get the element in this array with the given index vector.abstract int
getDimension()
Get the dimension of this array.abstract List<Integer>
getShape()
Get the shape of this array.<S> MultiDimensionalArray<S>
map(Function<T,S> function)
Return a newMultiDimensionalArray
of the same size as this, using the given function to map from the elements of this array to the corresponding entry in the new arrayMultiDimensionalArray<T>
project(Function<List<T>,T> projection)
Project this array into an array of dimension d-1 using the given projection function.void
set(int[] index, T value)
Set a new value for the given index vector.abstract void
set(List<Integer> index, T value)
Set a new value for the given index vector.static <S> MultiDimensionalArray<S>
sparse(List<Integer> shape)
Methods inherited from class AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
MultiDimensionalArray
public MultiDimensionalArray()
-
-
Method Details
-
build
public static <S> MultiDimensionalArray<S> build(int width, IntFunction<MultiDimensionalArray<S>> populator)Create a new MultiDimensionalArray.- Type Parameters:
S
- The type of objects stored in the array.- Parameters:
width
- The width of this array in the first dimension.populator
- A function supplying new MultiDimensionalArrays of dimension one less than the resulting array. The function should return arrays for input 0,1,...,width-1.- Returns:
- A new MultiDimensionalArray generated using the given populator.
-
sparse
-
build
Create a new one-dimensional array with the given entries. -
build
public static <S> MultiDimensionalArray<S> build(List<Integer> shape, Function<List<Integer>,S> populator)Create a new multi-dimensional array with the given shape and with each entry being generated by the populator function. -
get
Get the element in this array with the given index vector.- Throws:
IndexOutOfBoundsException
-
get
Get the element in this array with the given index vector.- Throws:
IndexOutOfBoundsException
-
get
Get the element in this array with the given index vector.- Throws:
IndexOutOfBoundsException
-
set
Set a new value for the given index vector.- Throws:
IndexOutOfBoundsException
-
set
Set a new value for the given index vector.- Throws:
IndexOutOfBoundsException
-
getShape
Get the shape of this array. -
getDimension
public abstract int getDimension()Get the dimension of this array. -
project
Project this array into an array of dimension d-1 using the given projection function. -
map
Return a newMultiDimensionalArray
of the same size as this, using the given function to map from the elements of this array to the corresponding entry in the new array -
forEachWithIndices
Perform an operation on all elements
-