Class MultidimensionalCounter

  • public final class MultidimensionalCounter
    extends Object
    Converter between unidimensional storage structure and multidimensional conceptual structure. This utility will convert from indices in a multidimensional structure to the corresponding index in a one-dimensional array. For example, assuming that the ranges (in 3 dimensions) of indices are 2, 4 and 3, the following correspondences, between 3-tuples indices and unidimensional indices, will hold:
    • (0, 0, 0) corresponds to 0
    • (0, 0, 1) corresponds to 1
    • (0, 0, 2) corresponds to 2
    • (0, 1, 0) corresponds to 3
    • ...
    • (1, 0, 0) corresponds to 12
    • ...
    • (1, 3, 2) corresponds to 23
    • Method Detail

      • of

        public static MultidimensionalCounter of​(int... size)
        Creates a counter.
        size - Counter sizes (number of slots in each dimension).
        a new instance.
        IllegalArgumentException - if one of the sizes is negative or zero.
      • getDimension

        public int getDimension()
        Gets the number of dimensions of the multidimensional counter.
        the number of dimensions.
      • toMulti

        public int[] toMulti​(int index)
        Converts to a multidimensional counter.
        index - Index in unidimensional counter.
        the multidimensional counts.
        IndexOutOfBoundsException - if index is not between 0 and the value returned by getSize() (excluded).
      • toUni

        public int toUni​(int... c)
        Converts to a unidimensional counter.
        c - Indices in multidimensional counter.
        the index within the unidimensionl counter.
        IllegalArgumentException - if the size of c does not match the size of the array given in the constructor.
        IndexOutOfBoundsException - if a value of c is not in the range of the corresponding dimension, as defined in the constructor.
      • getSize

        public int getSize()
        Gets the total number of elements.
        the total size of the unidimensional counter.
      • getSizes

        public int[] getSizes()
        Gets the number of multidimensional counter slots in each dimension.
        the number of slots in each dimension.