Package hlcd.testing.arrayTester
Class SegmentSplitter
java.lang.Object
hlcd.testing.arrayTester.SegmentSplitter
Uses a 1-D array of
ints to mimic the splitting of segments. The
length of the array represents the number of segments required. The value
stored in each cell represents the length the segment.
//minimal example to execute this class:
public static void main(String[] args) {
System.out.println("Running SegmentSplitter...");
//number of complete 1D arrays
long fullSegments = (long) (Math.random() * 100000);
//extra is a value between 0 and maxSegmentLength, including both
long extra = (long) (Math.random() * (MAX_SEGMENT_LENGTH + 1));
long size = fullSegments * MAX_SEGMENT_LENGTH + extra;
double sizeInGb = (64 * size) / 8000000000.0;
//System.out.println("Total GBs of RAM used: " + sizeInGb);
SegmentSplitter data = new SegmentSplitter(size);
System.out.println("The size of each segment in the 2-D array: ");
System.out.println(data);
//count the number of cells allocated
long cells = 0;
for (int i = 0; i < data.array.length; i++) {
cells += data.array[i];
}
//ensure the number of allocated cells matches the size specified
if (size != cells) {
System.out.println("Failed.");
}else{
System.out.println("Success!");
}
System.out.println("SegmentSplitter completed.");
}- Since:
- April 13th, 2022
- Version:
- 1.0
- Author:
- Maysara Al Jumaily
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intThe maximum size of each 1-D array. -
Constructor Summary
ConstructorsConstructorDescriptionSegmentSplitter(long size)The only constructor which uses the specified size to calculates the number of segments required as well as the length of each segment. -
Method Summary
-
Field Details
-
MAX_SEGMENT_LENGTH
public static int MAX_SEGMENT_LENGTHThe maximum size of each 1-D array.
-
-
Constructor Details
-
SegmentSplitter
public SegmentSplitter(long size)The only constructor which uses the specified size to calculates the number of segments required as well as the length of each segment.- Parameters:
size- the number of cells required to be stored
-
-
Method Details