Package stdlib

Class ArrayGenerator

java.lang.Object
stdlib.ArrayGenerator

public class ArrayGenerator extends Object
Provides methods to generate arrays of Integer objects, arrays of doubles in [0.0,1.0), and arrays of characters.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    Generate a partially sorted array with unique elements.
    static double[]
    Generate a partially sorted array with unique elements.
    static double[]
    doubleRandom(int N, int numValues)
    Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    static double[]
    Generate a shuffled array of length N with unique values 0, 1, ...
    static double[]
    Generate an array of length N with values N-1, N-2, ...
    static double[]
    Generate an array of doubles from a string.
    static double[]
    Generate an array of length N with values 0, 1, ..., N-1.
    static String[]
    Generate an array of strings from a string.
    static Integer[]
    Generate a partially sorted array with unique elements.
    static Integer[]
    Generate a partially sorted array with unique elements.
    static Integer[]
    integerRandom(int N, int numValues)
    Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    static Integer[]
    integerRandom(int N, int minValue, int maxValue)
    Generate an array of length N whose values are chosen uniformly from the range [minValue,maxValue).
    static Integer[]
    Generate a shuffled array of length N with unique values 0, 1, ...
    static Integer[]
    Generate an array of length N with values N-1, N-2, ...
    static Integer[]
    Generate an array of length N with values 0, 1, ..., N-1.
    static int[]
    Generate a partially sorted array with unique elements.
    static int[]
    Generate a partially sorted array with unique elements.
    static int[]
    intRandom(int N, int numValues)
    Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    static int[]
    intRandom(int N, int minValue, int maxValue)
    Generate an array of length N whose values are chosen uniformly from the range [minValue,maxValue).
    static int[]
    Generate a shuffled array of length N with unique values 0, 1, ...
    static int[]
    Generate an array of length N with values N-1, N-2, ...
    static int[]
    Generate an array of ints from a string.
    static int[]
    Generate an array of length N with values 0, 1, ..., N-1.
    static void
    print(boolean[] a)
    Print an array of booleans to standard output.
    static void
    print(boolean[][] a)
    Print the M-by-N array of booleans to standard output.
    static void
    print(double[] a)
    Print an array of doubles to standard output.
    static void
    print(double[][] a)
    Print the M-by-N array of doubles to standard output.
    static void
    print(int[] a)
    Print an array of ints to standard output.
    static void
    print(int[][] a)
    Print the M-by-N array of ints to standard output.
    static void
    Print an array of Strings to standard output.
    static void
    print(Object[][] a)
    Print the M-by-N array of Strings to standard output.
    static boolean[]
    Read in and return an array of booleans from fileName.
    static boolean[]
    Read in and return an array of booleans from in.
    static boolean[][]
    Read in and return an M-by-N array of booleans from fileName.
    static boolean[][]
    Read in and return an M-by-N array of booleans from in.
    static double[]
    readDouble1D(String fileName)
    Read in and return an array of doubles from fileName.
    static double[]
    Read in and return an array of doubles from in.
    static double[][]
    readDouble2D(String fileName)
    Read in and return an M-by-N array of doubles from fileName.
    static double[][]
    Read in and return an M-by-N array of doubles from in.
    static int[]
    readInt1D(String fileName)
    Read in and return an array of ints from fileName.
    static int[]
    Read in and return an array of ints from in.
    static int[][]
    readInt2D(String fileName)
    Read in and return an M-by-N array of ints from fileName.
    static int[][]
    Read in and return an M-by-N array of ints from in.
    static String[]
    readString1D(String fileName)
    Read in and return an array of Strings from fileName.
    static String[]
    Read in and return an array of Strings from in.
    static String[][]
    readString2D(String fileName)
    Read in and return an M-by-N array of Strings from fileName.
    static String[][]
    Read in and return an M-by-N array of Strings from in.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • fromString

      public static String[] fromString(String s)
      Generate an array of strings from a string. Each array element will be a string of length one. For example
         fromString("DOG") generates the array { "D", "O", "G" }
       
      See Also:
    • doublesFromString

      public static double[] doublesFromString(String s)
      Generate an array of doubles from a string. The string should include a list of numbers, separated by single spaces. For example
         doublesFromString("10.3 -Infinity 11)" generates the array { 10.3, -Infinity, 11.0 }
       
      See Also:
    • intsFromString

      public static int[] intsFromString(String s)
      Generate an array of ints from a string. The string should include a list of numbers, separated by single spaces. For example
         doublesFromString("10 11)" generates the array { 10, 11.0 }
       
      See Also:
    • intRandom

      public static int[] intRandom(int N, int minValue, int maxValue)
      Generate an array of length N whose values are chosen uniformly from the range [minValue,maxValue).
    • intRandom

      public static int[] intRandom(int N, int numValues)
      Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    • intSortedUnique

      public static int[] intSortedUnique(int N)
      Generate an array of length N with values 0, 1, ..., N-1.
    • intReverseSortedUnique

      public static int[] intReverseSortedUnique(int N)
      Generate an array of length N with values N-1, N-2, ... 0.
    • intRandomUnique

      public static int[] intRandomUnique(int N)
      Generate a shuffled array of length N with unique values 0, 1, ... N-1
    • intPartiallySortedUnique

      public static int[] intPartiallySortedUnique(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves random elements an arbitrary amount until the threshold is achieved.
    • intPartiallySortedUnique2

      public static int[] intPartiallySortedUnique2(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves all elements a small amount.
    • integerRandom

      public static Integer[] integerRandom(int N, int minValue, int maxValue)
      Generate an array of length N whose values are chosen uniformly from the range [minValue,maxValue).
    • integerRandom

      public static Integer[] integerRandom(int N, int numValues)
      Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    • integerSortedUnique

      public static Integer[] integerSortedUnique(int N)
      Generate an array of length N with values 0, 1, ..., N-1.
    • integerReverseSortedUnique

      public static Integer[] integerReverseSortedUnique(int N)
      Generate an array of length N with values N-1, N-2, ... 0.
    • integerRandomUnique

      public static Integer[] integerRandomUnique(int N)
      Generate a shuffled array of length N with unique values 0, 1, ... N-1
    • integerPartiallySortedUnique

      public static Integer[] integerPartiallySortedUnique(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves random elements an arbitrary amount until the threshold is achieved.
    • integerPartiallySortedUnique2

      public static Integer[] integerPartiallySortedUnique2(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves all elements a small amount.
    • doubleRandom

      public static double[] doubleRandom(int N, int numValues)
      Generate an array of length N whose values are chosen uniformly from the range [0,numValues).
    • doubleSortedUnique

      public static double[] doubleSortedUnique(int N)
      Generate an array of length N with values 0, 1, ..., N-1.
    • doubleReverseSortedUnique

      public static double[] doubleReverseSortedUnique(int N)
      Generate an array of length N with values N-1, N-2, ... 0.
    • doubleRandomUnique

      public static double[] doubleRandomUnique(int N)
      Generate a shuffled array of length N with unique values 0, 1, ... N-1
    • doublePartiallySortedUnique

      public static double[] doublePartiallySortedUnique(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves random elements an arbitrary amount until the threshold is achieved.
    • doublePartiallySortedUnique2

      public static double[] doublePartiallySortedUnique2(int N)
      Generate a partially sorted array with unique elements. The number of inversions will be between N and 2N. This algorithm moves all elements a small amount.
    • readString1D

      public static String[] readString1D(String fileName)
      Read in and return an array of Strings from fileName. Input must begin with dimensions.
      See Also:
    • readString1D

      public static String[] readString1D(In in)
      Read in and return an array of Strings from in. Input must begin with dimensions.
      See Also:
    • print

      public static void print(Object[] a)
      Print an array of Strings to standard output.
    • readString2D

      public static String[][] readString2D(String fileName)
      Read in and return an M-by-N array of Strings from fileName. Input must begin with dimensions.
    • readString2D

      public static String[][] readString2D(In in)
      Read in and return an M-by-N array of Strings from in. Input must begin with dimensions.
    • print

      public static void print(Object[][] a)
      Print the M-by-N array of Strings to standard output.
    • readDouble1D

      public static double[] readDouble1D(String fileName)
      Read in and return an array of doubles from fileName. Input must begin with dimensions.
      See Also:
    • readDouble1D

      public static double[] readDouble1D(In in)
      Read in and return an array of doubles from in. Input must begin with dimensions.
      See Also:
    • print

      public static void print(double[] a)
      Print an array of doubles to standard output.
    • readDouble2D

      public static double[][] readDouble2D(String fileName)
      Read in and return an M-by-N array of doubles from fileName. Input must begin with dimensions.
    • readDouble2D

      public static double[][] readDouble2D(In in)
      Read in and return an M-by-N array of doubles from in. Input must begin with dimensions.
    • print

      public static void print(double[][] a)
      Print the M-by-N array of doubles to standard output.
    • readInt1D

      public static int[] readInt1D(String fileName)
      Read in and return an array of ints from fileName. Input must begin with dimensions.
      See Also:
    • readInt1D

      public static int[] readInt1D(In in)
      Read in and return an array of ints from in. Input must begin with dimensions.
      See Also:
    • print

      public static void print(int[] a)
      Print an array of ints to standard output.
    • readInt2D

      public static int[][] readInt2D(String fileName)
      Read in and return an M-by-N array of ints from fileName. Input must begin with dimensions.
    • readInt2D

      public static int[][] readInt2D(In in)
      Read in and return an M-by-N array of ints from in. Input must begin with dimensions.
    • print

      public static void print(int[][] a)
      Print the M-by-N array of ints to standard output.
    • readBoolean1D

      public static boolean[] readBoolean1D(String fileName)
      Read in and return an array of booleans from fileName. Input must begin with dimensions.
    • readBoolean1D

      public static boolean[] readBoolean1D(In in)
      Read in and return an array of booleans from in. Input must begin with dimensions.
    • print

      public static void print(boolean[] a)
      Print an array of booleans to standard output.
    • readBoolean2D

      public static boolean[][] readBoolean2D(String fileName)
      Read in and return an M-by-N array of booleans from fileName. Input must begin with dimensions.
    • readBoolean2D

      public static boolean[][] readBoolean2D(In in)
      Read in and return an M-by-N array of booleans from in. Input must begin with dimensions.
    • print

      public static void print(boolean[][] a)
      Print the M-by-N array of booleans to standard output.