Difference between revisions of "Slices"
Jump to navigation
Jump to search
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | This assignment has been replaced by [[Ranges]]. | ||
+ | <!-- | ||
+ | |||
credit for this assignment: Finn Voichick and Dennis Cosgrove | credit for this assignment: Finn Voichick and Dennis Cosgrove | ||
Line 11: | Line 14: | ||
This studio is about creating an easier way to split data so that it can be worked on in parallel. The splitting of the data is still done sequentially. That means at no point in this studio should you be using async() or finish(). | This studio is about creating an easier way to split data so that it can be worked on in parallel. The splitting of the data is still done sequentially. That means at no point in this studio should you be using async() or finish(). | ||
− | + | =Code To Investigate= | |
− | + | [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/IndexedRange.html class IndexedRange] | |
− | + | :[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/slice/core/IndexedRange.html#%3Cinit%3E(int,int,int) constructor]. | |
− | |||
− | = | ||
− | |||
<pre>public IndexedRange(int sliceIndexId, int minInclusive, int maxExclusive)</pre> | <pre>public IndexedRange(int sliceIndexId, int minInclusive, int maxExclusive)</pre> | ||
Line 23: | Line 23: | ||
=Code to Implement= | =Code to Implement= | ||
− | {{CodeToImplement|Slices| | + | {{CodeToImplement|Slices|createNSlices|slices.studio}} |
− | == | + | ==createNSlices== |
− | {{Sequential| | + | {{Sequential|public static List<IndexedRange> createNSlices(int minInclusive, int maxExclusive, int numSlices)}} |
− | Given | + | Given a range [minInclusive, maxExclusive) and a number of slices to make, return a List of IndexedRanges. Understanding what a IndexedRange is and how it is used is important when writing this solution. |
− | + | The goal is to have each slice's range be the entire array when put together, with no overlap. Some examples are giving below. Working through more examples can be a helpful way of figuring out what code to write if you get stuck. | |
− | |||
− | |||
{{ tip | In a slice, the minimum is inclusive and the maximum is exclusive. This means for two slices next to each other, slice1.getMaxExclusive() is equal to slice2.getMinInclusive(). }} | {{ tip | In a slice, the minimum is inclusive and the maximum is exclusive. This means for two slices next to each other, slice1.getMaxExclusive() is equal to slice2.getMinInclusive(). }} | ||
Line 108: | Line 106: | ||
Giving all the remainder to one slice defeats the purpose of balancing the workload! | Giving all the remainder to one slice defeats the purpose of balancing the workload! | ||
− | == | + | ==Convenience Methods== |
In order to support primitive arrays (e.g. byte[], int[], et cetera) and non-primitive arrays (e.g. Object[]) we provide all of the public methods, each which simply call the single method requiring implementation: | In order to support primitive arrays (e.g. byte[], int[], et cetera) and non-primitive arrays (e.g. Object[]) we provide all of the public methods, each which simply call the single method requiring implementation: | ||
− | <nowiki> public static < | + | <nowiki> public static <C> List<IndexedRange> createNSlices(C[] data, int numSlices) { |
− | return | + | return createNSlices(0, data.length, numSlices); |
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(byte[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(char[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(short[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(int[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(long[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(float[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
} | } | ||
− | public static List< | + | |
− | return | + | public static List<IndexedRange> createNSlices(double[] data, int numSlices) { |
+ | return createNSlices(0, data.length, numSlices); | ||
}</nowiki> | }</nowiki> | ||
− | |||
=Testing Your Solution= | =Testing Your Solution= | ||
==Correctness== | ==Correctness== | ||
{{TestSuite|SlicesTestSuite|slice.studio}} | {{TestSuite|SlicesTestSuite|slice.studio}} | ||
+ | |||
+ | =Pledge, Acknowledgments, Citations= | ||
+ | {{Pledge|studio-slices}} | ||
+ | --> |
Latest revision as of 21:56, 30 November 2022
This assignment has been replaced by Ranges.