<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://classes.engineering.wustl.edu/cse231/core/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mroitblat</id>
	<title>CSE231 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://classes.engineering.wustl.edu/cse231/core/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mroitblat"/>
	<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Special:Contributions/Mroitblat"/>
	<updated>2026-11-28T07:44:14Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Balanced_String_Map_K_Mer_Counting_Assignment&amp;diff=4983</id>
		<title>Balanced String Map K Mer Counting Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Balanced_String_Map_K_Mer_Counting_Assignment&amp;diff=4983"/>
		<updated>2023-04-21T19:39:23Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Individual Assignment=&lt;br /&gt;
This is an individual assignment.&lt;br /&gt;
&lt;br /&gt;
=Previous Assignment=&lt;br /&gt;
Be sure to complete the [[String_Map_K_Mer_Assignment|unbalanced String Map K-mer Counting group warmup]] first.&lt;br /&gt;
&lt;br /&gt;
=Code to Implement=&lt;br /&gt;
==StringConcurrentMapBalancedKMerCounter==&lt;br /&gt;
{{CodeToImplement|StringConcurrentMapBalancedKMerCounter|constructor&amp;lt;br/&amp;gt;balancer&amp;lt;br/&amp;gt;concurrentMapFactory&amp;lt;br/&amp;gt;createConcurrentMap&amp;lt;br/&amp;gt;parse|kmer.warmup}}&lt;br /&gt;
&lt;br /&gt;
Note: this class forces a somewhat ridiculous amount of abstraction when it comes to constructing new ConcurrentMaps.  The constructor will be passed a KMerBalancer and Supplier to be used instead of, for example, constructing a DefaultKMerBalancer and ConcurrentHashMaps directly.  This allows the testing to catch errors sooner in an effort to aid debugging.&lt;br /&gt;
&lt;br /&gt;
===constructor and instance variable===&lt;br /&gt;
Hang onto the balancer and concurrentMapFactory passed to the constructor in an instance variables so you can use them later.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;public StringConcurrentMapBalancedKMerCounter(KMerBalancer balancer, Supplier&amp;lt;ConcurrentMap&amp;lt;String, Integer&amp;gt;&amp;gt; concurrentMapFactory)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===balancer===&lt;br /&gt;
&lt;br /&gt;
Return the balancer passed to the constructor.&lt;br /&gt;
&lt;br /&gt;
===parse===&lt;br /&gt;
{{Parallel|public StringMapKMerResults parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation will make your StringConcurrentMapUnbalancedKMerCounter implementation into a balanced one. Use the concurrentMapFactory's get() method to create a new ConcurrentMap.&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|_StringConcurrentMapBalancedKMerTestSuite|kmer.warmup}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=K_Mer_Counting_Assignment&amp;diff=4982</id>
		<title>K Mer Counting Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=K_Mer_Counting_Assignment&amp;diff=4982"/>
		<updated>2023-04-21T19:38:02Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: /* AbstractArrayKMerCounter */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: John Gibson and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
K-mer counting is a real world application which provides the opportunity to build thread safe data structures which alleviate contention.&lt;br /&gt;
&lt;br /&gt;
Pulling real data from the National Institutes of Health forces us to address balancing our work.&lt;br /&gt;
&lt;br /&gt;
Finally, k-mer counting provides opportunities for performance engineering.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
The term k-mer refers to a substring of length k and k-mer counting refers to the process of finding the number of occurrences of a k-mer in a given string. This computational problem has many real-world applications, the most notable being in the field of computational genomics. In this assignment, you will design a program that will ultimately take in a human X-chromosome and count the number of k-mers in the string of DNA. You will be making use of everything you have learned thus far, including atomic variables. It is useful to know that given a string of length n, the amount of possible k-mers is equal to '''n - k + 1'''.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Perhaps Out of Date Lecture|&amp;lt;youtube&amp;gt;_oyWzImAx1w&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Client=&lt;br /&gt;
{{Client|KMerCouterClient|main|kmer.client}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Intro to K-mer Counting|&amp;lt;youtube&amp;gt;tFfa7DWLJ_U&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
This demo video shows the big picture of KMer Counting. It included example usage of calculateSumOfAllKMers and calculatePossibleKMers method in &amp;lt;code&amp;gt;KMerUtils&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Research=&lt;br /&gt;
[https://en.wikipedia.org/wiki/K-mer wikipedia article on k-mers]&lt;br /&gt;
&lt;br /&gt;
paper: [https://academic.oup.com/bioinformatics/article-lookup/doi/10.1093/bioinformatics/btr011 A fast, lock-free approach for efficient parallel counting of occurrences of k-mers] (Jellyfish)&lt;br /&gt;
&lt;br /&gt;
paper: [https://peerj.com/articles/cs-94/ Multiple comparative metagenomics using multiset k-mer counting]&lt;br /&gt;
&lt;br /&gt;
[http://homolog.us/Tutorials/index.php?p=3.7&amp;amp;s=2 Collection of approaches to k-mer counting]&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform Burrows–Wheeler transform]&lt;br /&gt;
&lt;br /&gt;
[http://biology.stackexchange.com/questions/45016/what-is-the-biological-significance-of-k-mer-counting Significance of k-mer Counting]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==Runtime==&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#availableProcessors-- Runtime.getRuntime().availableProcessors()]&lt;br /&gt;
&lt;br /&gt;
==[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html BigInteger]==&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#ZERO ZERO]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#ONE ONE]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#shiftLeft(int) shiftLeft(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#flipBit(int) flipBit(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#multiply(java.math.BigInteger) multiply(val)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#pow(int) pow(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#intValueExact() intValueExact()]&lt;br /&gt;
&lt;br /&gt;
==Java Util Concurrent==&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html ConcurrentHashMap]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicIntegerArray.html AtomicIntegerArray].&lt;br /&gt;
&lt;br /&gt;
==[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/util/IntegerKMers.html IntegerKMers]==&lt;br /&gt;
{{CollapsibleCode|IntegerKMers|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;quot;Packs&amp;quot; a k-mer into an int. The bits of the int will be used to store&lt;br /&gt;
 * individual nucleobases.&lt;br /&gt;
 * &lt;br /&gt;
 * @param sequence a sequence of nucleobases&lt;br /&gt;
 * @param offset   the index of the first nucleobase in the desired k-mer&lt;br /&gt;
 * @param k        the length of the desired k-mer&lt;br /&gt;
 * @return an integer uniquely representing this k-mer&lt;br /&gt;
 */&lt;br /&gt;
public static int toPackedInt(byte[] sequence, int offset, int k) {&lt;br /&gt;
	int result = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; k; i++) {&lt;br /&gt;
		switch (sequence[offset + i]) {&lt;br /&gt;
		// case A:&lt;br /&gt;
		// result |= (A_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
		// break;&lt;br /&gt;
		case T:&lt;br /&gt;
			result |= (T_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case C:&lt;br /&gt;
			result |= (C_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case G:&lt;br /&gt;
			result |= (G_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return result;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/util/LongKMers.html LongKMers]==&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|LongKMers|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;quot;Packs&amp;quot; a k-mer into a long. The bits of the long will be used to store&lt;br /&gt;
 * individual nucleobases.&lt;br /&gt;
 * &lt;br /&gt;
 * @param sequence a sequence of nucleobases&lt;br /&gt;
 * @param offset   the index of the first nucleobase in the desired k-mer&lt;br /&gt;
 * @param k        the length of the desired k-mer&lt;br /&gt;
 * @return a long integer uniquely representing this k-mer&lt;br /&gt;
 */&lt;br /&gt;
public static long toPackedLong(byte[] sequence, int offset, int k) {&lt;br /&gt;
	final long T_MASK_LONG = (long) IntegerKMers.T_MASK_INT;&lt;br /&gt;
	final long C_MASK_LONG = (long) IntegerKMers.C_MASK_INT;&lt;br /&gt;
	final long G_MASK_LONG = (long) IntegerKMers.G_MASK_INT;&lt;br /&gt;
	long result = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; k; i++) {&lt;br /&gt;
		switch (sequence[offset + i]) {&lt;br /&gt;
		// case KMerIntegerUtils.A:&lt;br /&gt;
		// result |= (KMerIntegerUtils.A_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
		// break;&lt;br /&gt;
		case IntegerKMers.T:&lt;br /&gt;
			result |= (T_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case IntegerKMers.C:&lt;br /&gt;
			result |= (C_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case IntegerKMers.G:&lt;br /&gt;
			result |= (G_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return result;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==KMerResults==&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/KMerResults.html interface KMerResults]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AbstractMapKMerResults.html abstract class AbstractMapKMerResults&amp;lt;T&amp;gt;]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/core/results/LongMapKMerCount.html class LongMapKMerCount]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AbstractArrayKMerResults.html abstract class AbstractArrayKMerResults]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/IntArrayKMerCount.html class IntArrayKMerCount]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AtomicIntegerArrayKMerCount.html class AtomicIntegerArrayKMerCount]&lt;br /&gt;
&lt;br /&gt;
=Group Warmup=&lt;br /&gt;
Complete the [[String_Map_K_Mer_Assignment|group warm up]] first.&lt;br /&gt;
&lt;br /&gt;
=Individual Warmup=&lt;br /&gt;
Complete the [[Balanced_String_Map_K_Mer_Counting_Assignment|balanced individual warm up]] next.&lt;br /&gt;
&lt;br /&gt;
=Exercise K-mer Counters=&lt;br /&gt;
==Map Based==&lt;br /&gt;
===LongConcurrentMapKMerCounter===&lt;br /&gt;
{{CodeToImplement|LongConcurrentMapKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This parallel implementation will also overlap greatly with what you have done previously in the [[String_Map_K_Mer_Assignment|group]] and [[Balanced_String_Map_K_Mer_Counting_Assignment|individual]] warmups. In those assignments, we used a String representation for each k-mer. For this implementation, we will leverage the fact that since there are only 4 bases (A, T, C, and G), we can store each base in only 2 bits. It follows that for k&amp;lt;=32 we can store the k-mer in a 64-bit long integer. This will allow us to use less memory for each key in our Map.&lt;br /&gt;
&lt;br /&gt;
In order to do this, refer to the [[K_Mer_Counting_Assignment#LongKMers|LongKMers.toPackedLong(sequence, offset, k)]] method which will convert a sequence of bytes into a Long for our purposes. &lt;br /&gt;
&lt;br /&gt;
You will need to balance the workload of this parallel implementation with the KMerBalancer that you stored in the constructor. &lt;br /&gt;
&lt;br /&gt;
Make sure to select the most appropriate parallel fork loop.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;youtube&amp;gt;d_Ze-YQ3Thc&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Maps in Java often have a way to specify an initialCapacity to the constructor.  When used well, this parameter can give a hint as to how many Entries the Map should be expecting.  &lt;br /&gt;
&lt;br /&gt;
KMerUtils has methods which will calculate what you need to compute this value.  calculatePossibleKmers returns 4^k and calculateSumOfAllKmers returns n-k+1.  Think about how each method might be used to calculate an appropriate initial capacity.&lt;br /&gt;
&lt;br /&gt;
Some questions to ask yourself:&lt;br /&gt;
&lt;br /&gt;
# How many entries should the ConcurrentMap expect for a chromosome a million in length if k is 30?&lt;br /&gt;
# How many entries should the ConcurrentMap expect for a chromosome a million in length if k is 1?&lt;br /&gt;
&lt;br /&gt;
In order to test LongConcurrentMapKMerCounter with both java.util.ConcurrentHashMap&amp;lt;K,V&amp;gt; and your ConcurrentBucketHashMap&amp;lt;K,V&amp;gt; implementation, we pass a concurrentMapFactory to LongConcurrentMapKMerCounter's constructor.  You should use this factory to create your instance of ConcurrentMap via the apply method.  The Optional&amp;lt;Integer&amp;gt; parameter to this apply method is the initialCapacity.&lt;br /&gt;
&lt;br /&gt;
Note: anyone feeling the weight of a pandemic should feel free to pass Optional.empty() to the apply method.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Array Based==&lt;br /&gt;
===[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/exercise/AbstractArrayKMerCounter.html AbstractArrayKMerCounter]===&lt;br /&gt;
{{CodeToImplement|AbstractArrayKMerCounter|totalPossibleKMers|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
In the following two array-based implementations, we will leverage the fact that if k&amp;lt;=15 we can use an array instead of a Map to store the k-mer counts.&lt;br /&gt;
&lt;br /&gt;
For each implementation we will encode the k-mer with [[K_Mer_Counting_Assignment#IntegerKMers|IntegerKMers.toPackedInt(byte[] sequence, int offset, int k)]].  This encoded k-mer will be used as the index into the array.  The value at each index will be used to hold the number of times that particular k-mer was encountered.&lt;br /&gt;
&lt;br /&gt;
To make space for each possible k-mer we might find, we need to make an array large enough for each potential index.  To do that we will need to implement totalPossibleKMers(k).&lt;br /&gt;
&lt;br /&gt;
====[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/exercise/AbstractArrayKMerCounter.html#totalPossibleKMers(int) totalPossibleKMers(k)]====&lt;br /&gt;
&lt;br /&gt;
{{Sequential|protected BigInteger totalPossibleKMers(int k)}}&lt;br /&gt;
&lt;br /&gt;
Calculate the total possible different k-mers given a particular k.&lt;br /&gt;
&lt;br /&gt;
For example, for the 1-mers there are 4 possibilities:&lt;br /&gt;
&lt;br /&gt;
*A&lt;br /&gt;
*T&lt;br /&gt;
*C&lt;br /&gt;
*G&lt;br /&gt;
&lt;br /&gt;
For the 2-mers, there are 16 possibilities:&lt;br /&gt;
&lt;br /&gt;
*AA&lt;br /&gt;
*AT&lt;br /&gt;
*AC&lt;br /&gt;
*AG&lt;br /&gt;
*TA&lt;br /&gt;
*TT&lt;br /&gt;
*TC&lt;br /&gt;
*TG&lt;br /&gt;
*CA&lt;br /&gt;
*CT&lt;br /&gt;
*CC&lt;br /&gt;
*GG&lt;br /&gt;
*GA&lt;br /&gt;
*GT&lt;br /&gt;
*GC&lt;br /&gt;
*GG&lt;br /&gt;
&lt;br /&gt;
How many 3-mers are there?  Given a particular k, how many k-mers are there?&lt;br /&gt;
&lt;br /&gt;
===IntArrayKMerCounter===&lt;br /&gt;
{{CodeToImplement|IntArrayKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation will use an int array.  In order to create an array, we will need to know what size it should be.  If we need an element for every possible k-mer we might encounter how many would that be?  Did you just build a method which calculates this number?  Yes, you did.&lt;br /&gt;
&lt;br /&gt;
Note: to convert from a BigInteger to an int, we recommend using [https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#intValueExact() intValueExact()] as it will throw an [https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/ArithmeticException.html ArithmeticException] if the BigInteger is too big.&lt;br /&gt;
&lt;br /&gt;
Since this implementation is sequential, there is no need to balance the workload.  The continuation task will do all of the work.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
This means that you must keep in mind what size to make the array in order to instantiate it. KMerUtils has a method which will calculate this number for you, but think about which one to use, why you would use it, and how that would differ from simply calculating n - k + 1 yourself. Think of using the int array as similar to using the map, but with ints as the key/value pairs. Use KMerUtils.toPackedInt() in order to convert the sequence into an int for our purposes.&lt;br /&gt;
&lt;br /&gt;
Hint: calculatePossibleKmers and calculateSumOfAllKmers are distinct and take different input parameters. calculateSumOfAllKmers performs the n - k + 1 calculation on a list of arrays of sequences and sums the total. It calculate the total number of Kmers in the list of sequences. calculatePossibleKmers only takes the length of the k-mer (k) as the input parameter, meaning it will calculate all possibilities independent of the sequences. Thus, the n - k + 1 calculation would yield a value ranging from 0 (inclusive) to the result of calculatePossibleKmers (exclusive).&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AtomicIntegerArrayKMerCounter===&lt;br /&gt;
{{CodeToImplement|AtomicIntegerArrayKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation is simply the parallel equivalent of the int array implementation. To do so, you will be making use of Java’s atomic version of an array: an AtomicIntegerArray. Like before, you will be need to complete the parse method.  Don't forget to balance the workload in this parallel implementation with the specified KMerBalancer.&lt;br /&gt;
&lt;br /&gt;
Make sure to select the most appropriate parallel fork loop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
==ConcurrentBucketHashMapKMerCounter==&lt;br /&gt;
{{CodeToImplement|ConcurrentBucketHashMapKMerCounter|parse|kmer.lab.concurrentbuckethashmap}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This parallel implementation will go a step beyond the previous implementations and divide entries into 1024 buckets. Although a different number of buckets can be used, we will simply stick to 1024. Every time an entry is added to the bucket dictionary, it will create a hash based on the entry's key and place the entry into one of the 1024 buckets. Because we would only need to search one bucket for an entry based on a key's hash, this mainly serves the purpose of cutting down on search time. The compute method of the ConcurrentBucketHashMap should automatically compute the correct bucket for the entry, so this implementation should closely resemble the previous ConcurrentHashMap implementations. When instantiating the ConcurrentBucketHashMap, we recommend making the key/value pairs a Long and an Integer.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
==Open-ended K-mer Counter==&lt;br /&gt;
&lt;br /&gt;
This implementation is worth up to 4.5 extra credit points.&lt;br /&gt;
&lt;br /&gt;
It is intended as an opportunity to build a high-performing, thread-safe data structure.&lt;br /&gt;
&lt;br /&gt;
One possible path was outlined at a high level in class.  However, students are encouraged to think of alternate solutions.&lt;br /&gt;
&lt;br /&gt;
We have explicitly disallowed implementations akin to our matrix map reduce assignment, since we have already done the &amp;quot;give everyone their own data and combine in post&amp;quot; pattern to death.&lt;br /&gt;
&lt;br /&gt;
Partial credit is possible for solutions which demonstrate significant ingenuity.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__KMerTestSuite|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|kmer}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=K_Mer_Counting_Assignment&amp;diff=4953</id>
		<title>K Mer Counting Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=K_Mer_Counting_Assignment&amp;diff=4953"/>
		<updated>2023-04-14T20:44:54Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: John Gibson and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
K-mer counting is a real world application which provides the opportunity to build thread safe data structures which alleviate contention.&lt;br /&gt;
&lt;br /&gt;
Pulling real data from the National Institutes of Health forces us to address balancing our work.&lt;br /&gt;
&lt;br /&gt;
Finally, k-mer counting provides opportunities for performance engineering.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
The term k-mer refers to a substring of length k and k-mer counting refers to the process of finding the number of occurrences of a k-mer in a given string. This computational problem has many real-world applications, the most notable being in the field of computational genomics. In this assignment, you will design a program that will ultimately take in a human X-chromosome and count the number of k-mers in the string of DNA. You will be making use of everything you have learned thus far, including atomic variables. It is useful to know that given a string of length n, the amount of possible k-mers is equal to '''n - k + 1'''.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Perhaps Out of Date Lecture|&amp;lt;youtube&amp;gt;_oyWzImAx1w&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Client=&lt;br /&gt;
{{Client|KMerCouterClient|main|kmer.client}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Intro to K-mer Counting|&amp;lt;youtube&amp;gt;tFfa7DWLJ_U&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
This demo video shows the big picture of KMer Counting. It included example usage of calculateSumOfAllKMers and calculatePossibleKMers method in &amp;lt;code&amp;gt;KMerUtils&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=Research=&lt;br /&gt;
[https://en.wikipedia.org/wiki/K-mer wikipedia article on k-mers]&lt;br /&gt;
&lt;br /&gt;
paper: [https://academic.oup.com/bioinformatics/article-lookup/doi/10.1093/bioinformatics/btr011 A fast, lock-free approach for efficient parallel counting of occurrences of k-mers] (Jellyfish)&lt;br /&gt;
&lt;br /&gt;
paper: [https://peerj.com/articles/cs-94/ Multiple comparative metagenomics using multiset k-mer counting]&lt;br /&gt;
&lt;br /&gt;
[http://homolog.us/Tutorials/index.php?p=3.7&amp;amp;s=2 Collection of approaches to k-mer counting]&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform Burrows–Wheeler transform]&lt;br /&gt;
&lt;br /&gt;
[http://biology.stackexchange.com/questions/45016/what-is-the-biological-significance-of-k-mer-counting Significance of k-mer Counting]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==Runtime==&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#availableProcessors-- Runtime.getRuntime().availableProcessors()]&lt;br /&gt;
&lt;br /&gt;
==[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html BigInteger]==&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#ZERO ZERO]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#ONE ONE]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#shiftLeft(int) shiftLeft(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#flipBit(int) flipBit(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#multiply(java.math.BigInteger) multiply(val)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#pow(int) pow(n)]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#intValueExact() intValueExact()]&lt;br /&gt;
&lt;br /&gt;
==Java Util Concurrent==&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html ConcurrentHashMap]&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicIntegerArray.html AtomicIntegerArray].&lt;br /&gt;
&lt;br /&gt;
==[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/util/IntegerKMers.html IntegerKMers]==&lt;br /&gt;
{{CollapsibleCode|IntegerKMers|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;quot;Packs&amp;quot; a k-mer into an int. The bits of the int will be used to store&lt;br /&gt;
 * individual nucleobases.&lt;br /&gt;
 * &lt;br /&gt;
 * @param sequence a sequence of nucleobases&lt;br /&gt;
 * @param offset   the index of the first nucleobase in the desired k-mer&lt;br /&gt;
 * @param k        the length of the desired k-mer&lt;br /&gt;
 * @return an integer uniquely representing this k-mer&lt;br /&gt;
 */&lt;br /&gt;
public static int toPackedInt(byte[] sequence, int offset, int k) {&lt;br /&gt;
	int result = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; k; i++) {&lt;br /&gt;
		switch (sequence[offset + i]) {&lt;br /&gt;
		// case A:&lt;br /&gt;
		// result |= (A_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
		// break;&lt;br /&gt;
		case T:&lt;br /&gt;
			result |= (T_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case C:&lt;br /&gt;
			result |= (C_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case G:&lt;br /&gt;
			result |= (G_MASK_INT &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return result;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/util/LongKMers.html LongKMers]==&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|LongKMers|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
 * &amp;quot;Packs&amp;quot; a k-mer into a long. The bits of the long will be used to store&lt;br /&gt;
 * individual nucleobases.&lt;br /&gt;
 * &lt;br /&gt;
 * @param sequence a sequence of nucleobases&lt;br /&gt;
 * @param offset   the index of the first nucleobase in the desired k-mer&lt;br /&gt;
 * @param k        the length of the desired k-mer&lt;br /&gt;
 * @return a long integer uniquely representing this k-mer&lt;br /&gt;
 */&lt;br /&gt;
public static long toPackedLong(byte[] sequence, int offset, int k) {&lt;br /&gt;
	final long T_MASK_LONG = (long) IntegerKMers.T_MASK_INT;&lt;br /&gt;
	final long C_MASK_LONG = (long) IntegerKMers.C_MASK_INT;&lt;br /&gt;
	final long G_MASK_LONG = (long) IntegerKMers.G_MASK_INT;&lt;br /&gt;
	long result = 0;&lt;br /&gt;
	for (int i = 0; i &amp;lt; k; i++) {&lt;br /&gt;
		switch (sequence[offset + i]) {&lt;br /&gt;
		// case KMerIntegerUtils.A:&lt;br /&gt;
		// result |= (KMerIntegerUtils.A_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
		// break;&lt;br /&gt;
		case IntegerKMers.T:&lt;br /&gt;
			result |= (T_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case IntegerKMers.C:&lt;br /&gt;
			result |= (C_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		case IntegerKMers.G:&lt;br /&gt;
			result |= (G_MASK_LONG &amp;lt;&amp;lt; (i + i));&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return result;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==KMerResults==&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/KMerResults.html interface KMerResults]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AbstractMapKMerResults.html abstract class AbstractMapKMerResults&amp;lt;T&amp;gt;]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/core/results/LongMapKMerCount.html class LongMapKMerCount]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AbstractArrayKMerResults.html abstract class AbstractArrayKMerResults]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/IntArrayKMerCount.html class IntArrayKMerCount]&lt;br /&gt;
:: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/kmer/core/results/AtomicIntegerArrayKMerCount.html class AtomicIntegerArrayKMerCount]&lt;br /&gt;
&lt;br /&gt;
=Group Warmup=&lt;br /&gt;
Complete the [[String_Map_K_Mer_Assignment|group warm up]] first.&lt;br /&gt;
&lt;br /&gt;
=Individual Warmup=&lt;br /&gt;
Complete the [[Balanced_String_Map_K_Mer_Counting_Assignment|balanced individual warm up]] next.&lt;br /&gt;
&lt;br /&gt;
=Exercise K-mer Counters=&lt;br /&gt;
==Map Based==&lt;br /&gt;
===LongConcurrentMapKMerCounter===&lt;br /&gt;
{{CodeToImplement|LongConcurrentMapKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This parallel implementation will also overlap greatly with what you have done previously in the [[String_Map_K_Mer_Assignment|group]] and [[Balanced_String_Map_K_Mer_Counting_Assignment|individual]] warmups. In those assignments, we used a String representation for each k-mer. For this implementation, we will leverage the fact that since there are only 4 bases (A, T, C, and G), we can store each base in only 2 bits. It follows that for k&amp;lt;=32 we can store the k-mer in a 64-bit long integer. This will allow us to use less memory for each key in our Map.&lt;br /&gt;
&lt;br /&gt;
In order to do this, refer to the [[K_Mer_Counting_Assignment#LongKMers|LongKMers.toPackedLong(sequence, offset, k)]] method which will convert a sequence of bytes into a Long for our purposes. &lt;br /&gt;
&lt;br /&gt;
You will need to balance the workload of this parallel implementation with the KMerBalancer that you stored in the constructor. &lt;br /&gt;
&lt;br /&gt;
Make sure to select the most appropriate parallel fork loop.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;youtube&amp;gt;d_Ze-YQ3Thc&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Maps in Java often have a way to specify an initialCapacity to the constructor.  When used well, this parameter can give a hint as to how many Entries the Map should be expecting.  &lt;br /&gt;
&lt;br /&gt;
KMerUtils has methods which will calculate what you need to compute this value.  calculatePossibleKmers returns 4^k and calculateSumOfAllKmers returns n-k+1.  Think about how each method might be used to calculate an appropriate initial capacity.&lt;br /&gt;
&lt;br /&gt;
Some questions to ask yourself:&lt;br /&gt;
&lt;br /&gt;
# How many entries should the ConcurrentMap expect for a chromosome a million in length if k is 30?&lt;br /&gt;
# How many entries should the ConcurrentMap expect for a chromosome a million in length if k is 1?&lt;br /&gt;
&lt;br /&gt;
In order to test LongConcurrentMapKMerCounter with both java.util.ConcurrentHashMap&amp;lt;K,V&amp;gt; and your ConcurrentBucketHashMap&amp;lt;K,V&amp;gt; implementation, we pass a concurrentMapFactory to LongConcurrentMapKMerCounter's constructor.  You should use this factory to create your instance of ConcurrentMap via the apply method.  The Optional&amp;lt;Integer&amp;gt; parameter to this apply method is the initialCapacity.&lt;br /&gt;
&lt;br /&gt;
Note: anyone feeling the weight of a pandemic should feel free to pass Optional.empty() to the apply method.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Array Based==&lt;br /&gt;
===[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/exercise/AbstractArrayKMerCounter.html AbstractArrayKMerCounter]===&lt;br /&gt;
{{CodeToImplement|AbstractArrayKMerCounter|totalPossibleKMers|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
In the following two array-based implementations, we will leverage the fact that if k&amp;lt;=15 we can use an array instead of a Map to store the k-mer counts.&lt;br /&gt;
&lt;br /&gt;
For each implementation we will encode the k-mer with [[K_Mer_Counting_Assignment#IntegerKMers|IntKMers.toPackedInt(byte[] sequence, int offset, int k)]].  This encoded k-mer will be used as the index into the array.  The value at each index will be used to hold the number of times that particular k-mer was encountered.&lt;br /&gt;
&lt;br /&gt;
To make space for each possible k-mer we might find, we need to make an array large enough for each potential index.  To do that we will need to implement totalPossibleKMers(k).&lt;br /&gt;
&lt;br /&gt;
====[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/exercise/AbstractArrayKMerCounter.html#totalPossibleKMers(int) totalPossibleKMers(k)]====&lt;br /&gt;
&lt;br /&gt;
{{Sequential|protected BigInteger totalPossibleKMers(int k)}}&lt;br /&gt;
&lt;br /&gt;
Calculate the total possible different k-mers given a particular k.&lt;br /&gt;
&lt;br /&gt;
For example, for the 1-mers there are 4 possibilities:&lt;br /&gt;
&lt;br /&gt;
*A&lt;br /&gt;
*T&lt;br /&gt;
*C&lt;br /&gt;
*G&lt;br /&gt;
&lt;br /&gt;
For the 2-mers, there are 16 possibilities:&lt;br /&gt;
&lt;br /&gt;
*AA&lt;br /&gt;
*AT&lt;br /&gt;
*AC&lt;br /&gt;
*AG&lt;br /&gt;
*TA&lt;br /&gt;
*TT&lt;br /&gt;
*TC&lt;br /&gt;
*TG&lt;br /&gt;
*CA&lt;br /&gt;
*CT&lt;br /&gt;
*CC&lt;br /&gt;
*GG&lt;br /&gt;
*GA&lt;br /&gt;
*GT&lt;br /&gt;
*GC&lt;br /&gt;
*GG&lt;br /&gt;
&lt;br /&gt;
How many 3-mers are there?  Given a particular k, how many k-mers are there?&lt;br /&gt;
&lt;br /&gt;
===IntArrayKMerCounter===&lt;br /&gt;
{{CodeToImplement|IntArrayKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation will use an int array.  In order to create an array, we will need to know what size it should be.  If we need an element for every possible k-mer we might encounter how many would that be?  Did you just build a method which calculates this number?  Yes, you did.&lt;br /&gt;
&lt;br /&gt;
Note: to convert from a BigInteger to an int, we recommend using [https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/math/BigInteger.html#intValueExact() intValueExact()] as it will throw an [https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/ArithmeticException.html ArithmeticException] if the BigInteger is too big.&lt;br /&gt;
&lt;br /&gt;
Since this implementation is sequential, there is no need to balance the workload.  The continuation task will do all of the work.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
This means that you must keep in mind what size to make the array in order to instantiate it. KMerUtils has a method which will calculate this number for you, but think about which one to use, why you would use it, and how that would differ from simply calculating n - k + 1 yourself. Think of using the int array as similar to using the map, but with ints as the key/value pairs. Use KMerUtils.toPackedInt() in order to convert the sequence into an int for our purposes.&lt;br /&gt;
&lt;br /&gt;
Hint: calculatePossibleKmers and calculateSumOfAllKmers are distinct and take different input parameters. calculateSumOfAllKmers performs the n - k + 1 calculation on a list of arrays of sequences and sums the total. It calculate the total number of Kmers in the list of sequences. calculatePossibleKmers only takes the length of the k-mer (k) as the input parameter, meaning it will calculate all possibilities independent of the sequences. Thus, the n - k + 1 calculation would yield a value ranging from 0 (inclusive) to the result of calculatePossibleKmers (exclusive).&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===AtomicIntegerArrayKMerCounter===&lt;br /&gt;
{{CodeToImplement|AtomicIntegerArrayKMerCounter|parse|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation is simply the parallel equivalent of the int array implementation. To do so, you will be making use of Java’s atomic version of an array: an AtomicIntegerArray. Like before, you will be need to complete the parse method.  Don't forget to balance the workload in this parallel implementation with the specified KMerBalancer.&lt;br /&gt;
&lt;br /&gt;
Make sure to select the most appropriate parallel fork loop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
==ConcurrentBucketHashMapKMerCounter==&lt;br /&gt;
{{CodeToImplement|ConcurrentBucketHashMapKMerCounter|parse|kmer.lab.concurrentbuckethashmap}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This parallel implementation will go a step beyond the previous implementations and divide entries into 1024 buckets. Although a different number of buckets can be used, we will simply stick to 1024. Every time an entry is added to the bucket dictionary, it will create a hash based on the entry's key and place the entry into one of the 1024 buckets. Because we would only need to search one bucket for an entry based on a key's hash, this mainly serves the purpose of cutting down on search time. The compute method of the ConcurrentBucketHashMap should automatically compute the correct bucket for the entry, so this implementation should closely resemble the previous ConcurrentHashMap implementations. When instantiating the ConcurrentBucketHashMap, we recommend making the key/value pairs a Long and an Integer.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=Extra Credit=&lt;br /&gt;
==Open-ended K-mer Counter==&lt;br /&gt;
&lt;br /&gt;
This implementation is worth up to 4.5 extra credit points.&lt;br /&gt;
&lt;br /&gt;
It is intended as an opportunity to build a high-performing, thread-safe data structure.&lt;br /&gt;
&lt;br /&gt;
One possible path was outlined at a high level in class.  However, students are encouraged to think of alternate solutions.&lt;br /&gt;
&lt;br /&gt;
We have explicitly disallowed implementations akin to our matrix map reduce assignment, since we have already done the &amp;quot;give everyone their own data and combine in post&amp;quot; pattern to death.&lt;br /&gt;
&lt;br /&gt;
Partial credit is possible for solutions which demonstrate significant ingenuity.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__KMerTestSuite|kmer.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|kmer}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=String_Map_K_Mer_Assignment&amp;diff=4951</id>
		<title>String Map K Mer Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=String_Map_K_Mer_Assignment&amp;diff=4951"/>
		<updated>2023-04-13T18:24:36Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Group Assignment=&lt;br /&gt;
This is a group assignment.&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
&lt;br /&gt;
==java.util.concurrent==&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html ConcurrentHashMap]&lt;br /&gt;
&lt;br /&gt;
==StringKMers==&lt;br /&gt;
The following method should be useful as you build the assignment.&lt;br /&gt;
&lt;br /&gt;
===String toString(byte[] sequence, int offset, int kMerLength)===&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;	/**&lt;br /&gt;
	 * Stores the information from the given sequence into a String. For example, if&lt;br /&gt;
	 * you had the sequence, &amp;quot;ACCTGTCAAAA&amp;quot; and you called this method with an offset&lt;br /&gt;
	 * of 1 and a k of 4, it would return &amp;quot;CCTG&amp;quot;.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @param sequence the sequence of nucleobases to draw the bytes from&lt;br /&gt;
	 * @param offset   the offset for where to start looking for bytes&lt;br /&gt;
	 * @param k        the length of the k-mer to make a String for&lt;br /&gt;
	 * @return a String representation of the k-mer at the desired position&lt;br /&gt;
	 */&lt;br /&gt;
	public static String toString(byte[] sequence, int offset, int k) {&lt;br /&gt;
		return new String(sequence, offset, k, StandardCharsets.UTF_8);&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==KMerResults==&lt;br /&gt;
When we have completed our k-mer counting, we need to return the results.  Since we will have multiple k-mer counters with several different data structures, we are provided with a common [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/core/KMerResults.html interface KMerResults].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;public interface KMerResults {&lt;br /&gt;
	Iterable&amp;lt;byte[]&amp;gt; foundKMers();&lt;br /&gt;
&lt;br /&gt;
	int getCount(byte[] kMer);&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===StringMapKMerResults===&lt;br /&gt;
For this particular assignment we will be using instances of Map&amp;lt;String, Integer&amp;gt;, so the provided [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/kmer/core/results/StringMapKMerResults.html class StringMapKMerResults] will serve well:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;public final class StringMapKMerResults extends AbstractMapKMerResults&amp;lt;String&amp;gt; {&lt;br /&gt;
	public StringMapKMerResults(int k, Map&amp;lt;String, Integer&amp;gt; map) {&lt;br /&gt;
		super(k, map, StringKMerCodec.INSTANCE);&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
==StringHashMapKMerCounter==&lt;br /&gt;
{{CodeToImplement|StringHashMapKMerCounter|parse|kmer.group}}&lt;br /&gt;
&lt;br /&gt;
===parse===&lt;br /&gt;
{{Sequential|public StringMapKMerResults parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
In this completely sequential implementation, you will have to write the parse method. The method takes in a list of arrays of bytes and a k-mer length. It should return an instance of StringMapKMerResults(which takes in a map), a class provided to you which does exactly what its name suggests.&lt;br /&gt;
&lt;br /&gt;
parse should go through the amount of possible k-mers for every byte array in the list of sequences. As it goes through the bytes in the array, use the [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/kmer/util/StringKMers.html#toString(byte%5B%5D,int,int) StringKMers.toString(sequence, offset, k)] method to create a string to use as a key for the HashMap. The map should take in a String as the key and an Integer as the value. We recommend using the map.compute() method and reviewing how to use lambdas.&lt;br /&gt;
&lt;br /&gt;
==StringConcurrentHashMapKMerCounter==&lt;br /&gt;
{{CodeToImplement|StringConcurrentHashMapKMerCounter|parse|kmer.group}}&lt;br /&gt;
&lt;br /&gt;
===parse===&lt;br /&gt;
{{Parallel|public StringMapKMerResults parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This implementation will make your sequential String HashMap implementation into a parallel one. To do so, you will be making use of Java’s thread-safe version of a Map: [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html ConcurrentHashMap]. Like before, you will be need to complete the parse method but this time in parallel.&lt;br /&gt;
&lt;br /&gt;
Recall that the ConcurrentHashMap will NOT prevent data races.  We need to use a method like compute instead of a get/modify/put pattern to prevent atomicity races.&lt;br /&gt;
&lt;br /&gt;
:: ''Get then put is not atomic.''&lt;br /&gt;
:: ''Call compute. Call compute.''&lt;br /&gt;
:: ''Use ConcurrentHashMap. Use ConcurrentHashMap.&lt;br /&gt;
::  ''Or say shoot.  Or say shoot.''&lt;br /&gt;
&lt;br /&gt;
=Videos=&lt;br /&gt;
&amp;lt;youtube&amp;gt;4M9abyUyzxU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube&amp;gt;Bwv3QMN0Mk4&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube&amp;gt;a9CK1BPzESM&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=ByteArrayRangeConcurrentHashMapKMerCounter=&lt;br /&gt;
{{CodeToImplement|ByteArrayRangeConcurrentHashMapKMerCounter|parse|kmer.group.bytearrayrangemap}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public KMerCount parse(List&amp;lt;byte[]&amp;gt; sequences, int k)}}&lt;br /&gt;
&lt;br /&gt;
This parallel implementation will overlap greatly with your previous two implementations, but it will use ByteArrayRange instead of Strings and use the corresponding [[#KMerCounts |KMerCount]] implementation. Refer to the ByteArrayRange class in &amp;lt;code&amp;gt;kmer.core.bytearrayrange&amp;lt;/code&amp;gt; in order to get a better idea of how to implement this method and instantiate an instance of the class. The class closely resembles the Slice class you worked on earlier in the semester.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__StringKMerTestSuite|kmer.group}}&lt;br /&gt;
==sequential==&lt;br /&gt;
{{TestSuite|_StringSequentialKMerTestSuite|kmer.group}}&lt;br /&gt;
&lt;br /&gt;
==concurrent==&lt;br /&gt;
{{TestSuite|_StringConcurrentKMerTestSuite|kmer.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Ordered_Locks&amp;diff=4898</id>
		<title>Ordered Locks</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Ordered_Locks&amp;diff=4898"/>
		<updated>2023-03-31T00:15:37Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: [http://jcip.net/ Java Concurrency in Practice], Ben Choi, and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
Inspired by X10's isolated construct which provides mutual exclusion while avoiding deadlock, we will learn how to achieve this desirable property of deadlock freedom by ordering locks.&lt;br /&gt;
&lt;br /&gt;
We will gain experience with implicit locks and the synchronized statement.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
In Java, locks are a synchronization tool that exists to ensure whatever is protected by the lock is only accessed one thread at a time, as to avoid a possible data race. We will explore the first of two different types of locks: intrinsic locks.&lt;br /&gt;
&lt;br /&gt;
Every object has an intrinsic lock associated with the object. Intrinsic locks are accessed with the &amp;lt;code&amp;gt;synchronized&amp;lt;/code&amp;gt; keyword. &lt;br /&gt;
&lt;br /&gt;
To demonstrate how to avoid both data races and deadlock issues, we will create a method designed to transfer money between two bank accounts. Two parties should be able to safely transfer money between each other without a data race (courtesy of locks) or deadlock (something you will address).&lt;br /&gt;
&lt;br /&gt;
In this exercise we will use lock ordering to avoid deadlock.&lt;br /&gt;
&lt;br /&gt;
With lock ordering, we will control the order in which locks are acquired for two bank accounts using unique identifying values associated with the bank accounts. In this way, a transfer from bank account A to B paired with a simultaneous transfer from B to A will not lead to a scenario in which A is waiting for B’s lock forever while B is waiting for A’s lock forever, as both calls will always attempt to go for A’s lock before B’s or vice versa. For a general object, we might use the object’s hashcode as the unique identifying value, but for this assignment, we will use the account number associated with the bank account (which is guaranteed to be unique, unlike hashcodes).&lt;br /&gt;
&lt;br /&gt;
Refer to Oracle's official documentation regarding [https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html intrinsic locks/synchronization] for more information.&lt;br /&gt;
&lt;br /&gt;
=Somewhat Dated Video=&lt;br /&gt;
&amp;lt;!-- {{CollapsibleYouTube|Lecture|&amp;lt;youtube&amp;gt;qEbL51Gx3w0&amp;lt;/youtube&amp;gt;}}--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Exercise|&amp;lt;youtube&amp;gt;unkJCm1hqHk&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
{{CodeToImplement|BankAccountLockOrdering|transferMoney|lock.order.studio}}&lt;br /&gt;
&lt;br /&gt;
{{ThreadSafe|public static TransferResult transferMoney(Account sender, Account recipient, int amount)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As mentioned in the background section, we will attempt to prevent deadlock using a lock ordering algorithm of your making. Essentially, whenever an operation needs to use two separate locks, make sure that the locks are always acquired in a fixed order no matter how the operation is called. The general way to do this is to compare the identity hash codes of the two objects and enforce an order based on those values. However, this can lead to a rare issue in which the two objects are unique, but have the same hashcode. &lt;br /&gt;
&lt;br /&gt;
To avoid this issue entirely, however, we have assigned unique bank account numbers to each instance of the bank account object. Thus, you will not need to worry about this edge case.&lt;br /&gt;
&lt;br /&gt;
A couple of notes and common issues:&lt;br /&gt;
&lt;br /&gt;
*While you could create a [https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Lock.html Lock] object for each [https://www.cse.wustl.edu/~cosgroved/courses/cse231/s20/apidocs/locking/core/banking/Account.html Account] instance, we recommend simply using [https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html intrinsic locks] for this method. In other words, use &amp;lt;code&amp;gt;synchronized(sender)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;synchronized(recipient)&amp;lt;/code&amp;gt;.&lt;br /&gt;
*Syntax for synchronized can be found on this [[Reference_Page#Synchronized|reference page]].&lt;br /&gt;
*Invoke the not-thread-safe &amp;lt;code&amp;gt;TransferUtils.checkBalanceAndTransfer()&amp;lt;/code&amp;gt; method. This method will check that the sender and recipient are not the same people and that the sender has enough money in her account to send the specified amount to the recipient.&lt;br /&gt;
*Use the &amp;lt;code&amp;gt;uniqueIdNumber()&amp;lt;/code&amp;gt; method to get the unique account ID of a given bank account.&lt;br /&gt;
*Your implementation will have to make use of a nested &amp;lt;code&amp;gt;synchronized&amp;lt;/code&amp;gt; blocks (one &amp;lt;code&amp;gt;synchronized&amp;lt;/code&amp;gt; call within another).&lt;br /&gt;
&lt;br /&gt;
=Not Required Problem To Contemplate=&lt;br /&gt;
How would you handle the case where every attempt to order two objects ([https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html#compareTo-T- compareTo(other)], [https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#identityHashCode-java.lang.Object- System.identityHashCode(o)], et cetera) failed?&lt;br /&gt;
{{Spoiler|One would synchronize on a shared third object first to account for this rare case.}}&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_LockOrderingTestSuite|lock.order.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|ordered-locks}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=AllOrNothingLocks&amp;diff=4897</id>
		<title>AllOrNothingLocks</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=AllOrNothingLocks&amp;diff=4897"/>
		<updated>2023-03-31T00:00:05Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: [http://jcip.net/ Java Concurrency in Practice], Ben Choi, Miles Cushing, and Dennis Cosgrove&lt;br /&gt;
&lt;br /&gt;
=Motivation=&lt;br /&gt;
In addition to [[Ordered_Locks|Ordered Locks]] we can employ an all-or-nothing strategy for acquiring locks for mutual exclusion.&lt;br /&gt;
&lt;br /&gt;
We gain experience with explicit locks and trying to acquire them and responding appropriately to success and failure.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
Check out the [[Lock_Ordering#Background|lock ordering]] exercise.&lt;br /&gt;
&lt;br /&gt;
In Java, locks are a synchronization tool that exists to ensure whatever is protected by the lock is only accessed one thread at a time, as to avoid a possible data race. In this exercise we will explore the second type of locks: explicitly created &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; objects from the &amp;lt;code&amp;gt;java.util.concurrent.locks&amp;lt;/code&amp;gt; package.&lt;br /&gt;
&lt;br /&gt;
Every object has an intrinsic lock associated with the object, but &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; objects are explicitly defined and instantiated locks which can be called to lock or unlock. Lock objects are acted upon just like any other object, but we are mostly interested in the &amp;lt;code&amp;gt;lock()&amp;lt;/code&amp;gt; method, the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method, and the &amp;lt;code&amp;gt;unlock()&amp;lt;/code&amp;gt; method. For this exercise, we will specifically use the &amp;lt;code&amp;gt;ReentrantLock&amp;lt;/code&amp;gt; object, a class which implements the general &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
To demonstrate how to avoid both data races and deadlock issues, we will create a method designed to transfer money between two bank accounts. Two parties should be able to asynchronously and continuously transfer money between each other without a data race (courtesy of locks) or deadlock (something you will address).&lt;br /&gt;
&lt;br /&gt;
For this approach, we will make use of the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method in order to attempt to acquire an object’s lock. If the object’s lock is not available at the time, we will continue to try to acquire the lock until it finally succeeds, after which we can successfully transfer funds from one bank account to another. In this approach, an asynchronous pair of transfers from A to B and B to A will not lead to deadlock as the two processes will give up on acquiring the lock until it becomes available, at which point it will finally acquire the lock. This approach does not make use of ordering, but simply relies on making lock attempts give up if the desired lock is not immediately available (and then try again later).&lt;br /&gt;
&lt;br /&gt;
==Java Util Concurrent==&lt;br /&gt;
Refer to Oracle's official documentation for more information:&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/essential/concurrency/newlocks.html Lock Objects Tutorial] &lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/package-summary.html package java.util.concurrent.locks]&lt;br /&gt;
&lt;br /&gt;
*[https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html while loops]&lt;br /&gt;
*[https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html finally]&lt;br /&gt;
*[https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#yield-- Thread yield]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html-- Lock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html#tryLock-- tryLock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html#unlock--- unlock]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html--- ReentrantLock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html#isHeldByCurrentThread--- isHeldByCurrentThread ]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html ListIterator&amp;lt;E&amp;gt;]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#hasNext-- boolean hasNext()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#next-- E next()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#hasPrevious-- boolean hasPrevious()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#previous-- E previous()]&lt;br /&gt;
&lt;br /&gt;
=Somewhat Dated Demo Videos=&lt;br /&gt;
{{CollapsibleYouTube|All Or Nothing Locks|&amp;lt;youtube&amp;gt;0MLAdhm1RCA&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Bank Account Try Lock|&amp;lt;youtube&amp;gt;yaB2f8CS5wQ&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|AllOrNothingLockUtils|&amp;lt;youtube&amp;gt;cI_wrhfT7Vw&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Chef|&amp;lt;youtube&amp;gt;rKIEDf1nHVg&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
As mentioned in the background section, this implementation will avoid deadlock by giving up on acquiring a lock if it is not immediately available before coming back to it later (when it might actually be available). This implementation will need to make use of the ReentrantLocks associated with the sender and recipient bank account objects. More specifically, it will have to make use of the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method. For an example of how to format a tryLock, look below:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Lock lock = ...&lt;br /&gt;
if (lock.tryLock()) {&lt;br /&gt;
	try {&lt;br /&gt;
		doSomething();&lt;br /&gt;
	} finally {&lt;br /&gt;
		lock.unlock();&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BankAccountLockTrying===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|BankAccountLockTrying|attemptToTransferMoney|lock.allornothing.bank.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{ThreadSafe|public static TransferResult attemptToTransferMoney(AccountWithReentrantLock sender, AccountWithReentrantLock recipient, int amount)}}&lt;br /&gt;
&lt;br /&gt;
A couple of notes and common issues:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; will grab the lock if it can. There's no need to call &amp;lt;code&amp;gt;lock()&amp;lt;/code&amp;gt; after &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt;.&lt;br /&gt;
*We recommend you call the &amp;lt;code&amp;gt;TransferUtils.checkBalanceAndTransfer(sender, receiver, amount)&amp;lt;/code&amp;gt; method for the sake of simplicity. This method will check that the sender and recipient are not the same people and that the sender has enough money in her account to send the specified amount to the recipient.&lt;br /&gt;
*Anytime you lock a lock object, you should/must use a &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; block to unlock the lock.&lt;br /&gt;
*Your implementation will have to make use of a nested &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; block (one &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; call within another).&lt;br /&gt;
&lt;br /&gt;
===AllOrNothingLockUtils===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|AllOrNothingLockUtils|tryLockAll&amp;lt;br&amp;gt;unlockAll&amp;lt;br&amp;gt;runWithAllLocksOrDontRunAtAll|lock.allornothing.util.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private static boolean tryLockAll(List&amp;lt;ReentrantLock&amp;gt; locks)}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private static void unlockAll(List&amp;lt;ReentrantLock&amp;gt; locks)}}&lt;br /&gt;
&lt;br /&gt;
{{ThreadSafe|public static boolean runWithAllLocksOrDontRunAtAll(List&amp;lt;ReentrantLock&amp;gt; locks, Runnable body)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: in &amp;lt;code&amp;gt;tryLockAll&amp;lt;/code&amp;gt;, you will need to call &amp;lt;code&amp;gt;tryLock&amp;lt;/code&amp;gt; on all of the given locks. However, if one fails, you will need to unlock everything you have currently locked. A lock cannot be unlocked from a thread that doesn't hold the lock. Consider using the [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html ListIterator] interface to move forward and backward through the provided list of ReentrantLocks.&lt;br /&gt;
&lt;br /&gt;
{{Warning | If tryLockAll fails to acquire all of the locks, make sure to unlock any of the locks you did acquire.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | If tryLockAll fails, when rolling back a ListIterator to unlock any locks you acquired, be sure to do an initial prev() to set the iterator in the correct location before looping through to unlock the rest.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | An IllegalMonitorStateException() means that a thread tried to unlock a lock that it was not holding. }}&lt;br /&gt;
&lt;br /&gt;
===Chef===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|Chef|attemptToPrepare|lock.allornothing.kitchen.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static boolean attemptToPrepare(Recipe recipe)}}&lt;br /&gt;
&lt;br /&gt;
A couple of notes:&lt;br /&gt;
&lt;br /&gt;
*An object of class Recipe contains a list of Appliances that it needs in order to complete the item. An object of class Appliance has a lock that you can use to make sure the method remains thread-safe.&lt;br /&gt;
*Use the &amp;lt;code&amp;gt;recipe.prepare()&amp;lt;/code&amp;gt; method in order to actually execute the recipe. Caution: this method will throw an &amp;lt;code&amp;gt;IllegalThreadStateException()&amp;lt;/code&amp;gt; if it is called without all the locks being held by the same thread that called the create method.&lt;br /&gt;
* Since it is unknown how many locks each recipe will need beforehand, make use of the &amp;lt;code&amp;gt;AllOrNothingLockUtils.runWithAllLocksOrDontRunAtAll(List&amp;lt;ReentrantLock&amp;gt; locks, Runnable body)&amp;lt;/code&amp;gt; method you wrote earlier.&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|_TryLockingTestSuite|lock.allornothing.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|all-or-nothing-locks}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=AllOrNothingLocks&amp;diff=4896</id>
		<title>AllOrNothingLocks</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=AllOrNothingLocks&amp;diff=4896"/>
		<updated>2023-03-30T23:54:42Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: [http://jcip.net/ Java Concurrency in Practice], Ben Choi, Miles Cushing, and Dennis Cosgrove&lt;br /&gt;
&lt;br /&gt;
=Motivation=&lt;br /&gt;
In addition to [[Ordered_Locks|Ordered Locks]] we can employ an all-or-nothing strategy for acquiring locks for mutual exclusion.&lt;br /&gt;
&lt;br /&gt;
We gain experience with explicit locks and trying to acquire them and responding appropriately to success and failure.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
Check out the [[Lock_Ordering#Background|lock ordering]] exercise.&lt;br /&gt;
&lt;br /&gt;
In Java, locks are a synchronization tool that exists to ensure whatever is protected by the lock is only accessed one thread at a time, as to avoid a possible data race. In this exercise we will explore the second type of locks: explicitly created &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; objects from the &amp;lt;code&amp;gt;java.util.concurrent.locks&amp;lt;/code&amp;gt; package.&lt;br /&gt;
&lt;br /&gt;
Every object has an intrinsic lock associated with the object, but &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; objects are explicitly defined and instantiated locks which can be called to lock or unlock. Lock objects are acted upon just like any other object, but we are mostly interested in the &amp;lt;code&amp;gt;lock()&amp;lt;/code&amp;gt; method, the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method, and the &amp;lt;code&amp;gt;unlock()&amp;lt;/code&amp;gt; method. For this exercise, we will specifically use the &amp;lt;code&amp;gt;ReentrantLock&amp;lt;/code&amp;gt; object, a class which implements the general &amp;lt;code&amp;gt;Lock&amp;lt;/code&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
To demonstrate how to avoid both data races and deadlock issues, we will create a method designed to transfer money between two bank accounts. Two parties should be able to asynchronously and continuously transfer money between each other without a data race (courtesy of locks) or deadlock (something you will address).&lt;br /&gt;
&lt;br /&gt;
For this approach, we will make use of the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method in order to attempt to acquire an object’s lock. If the object’s lock is not available at the time, we will continue to try to acquire the lock until it finally succeeds, after which we can successfully transfer funds from one bank account to another. In this approach, an asynchronous pair of transfers from A to B and B to A will not lead to deadlock as the two processes will give up on acquiring the lock until it becomes available, at which point it will finally acquire the lock. This approach does not make use of ordering, but simply relies on making lock attempts give up if the desired lock is not immediately available (and then try again later).&lt;br /&gt;
&lt;br /&gt;
==Java Util Concurrent==&lt;br /&gt;
Refer to Oracle's official documentation for more information:&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/essential/concurrency/newlocks.html Lock Objects Tutorial] &lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/package-summary.html package java.util.concurrent.locks]&lt;br /&gt;
&lt;br /&gt;
*[https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html while loops]&lt;br /&gt;
*[https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html finally]&lt;br /&gt;
*[https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#yield-- Thread yield]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html-- Lock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html#tryLock-- tryLock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/Lock.html#unlock--- unlock]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html--- ReentrantLock]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html#isHeldByCurrentThread--- isHeldByCurrentThread ]&lt;br /&gt;
&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html ListIterator&amp;lt;E&amp;gt;]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#hasNext-- boolean hasNext()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#next-- E next()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#hasPrevious-- boolean hasPrevious()]&lt;br /&gt;
** [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html#previous-- E previous()]&lt;br /&gt;
&lt;br /&gt;
=Somewhat Dated Demo Videos=&lt;br /&gt;
{{CollapsibleYouTube|All Or Nothing Locks|&amp;lt;youtube&amp;gt;0MLAdhm1RCA&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Bank Account Try Lock|&amp;lt;youtube&amp;gt;yaB2f8CS5wQ&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|AllOrNothingLockUtils|&amp;lt;youtube&amp;gt;cI_wrhfT7Vw&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|Chef|&amp;lt;youtube&amp;gt;rKIEDf1nHVg&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
As mentioned in the background section, this implementation will avoid deadlock by giving up on acquiring a lock if it is not immediately available before coming back to it later (when it might actually be available). This implementation will need to make use of the ReentrantLocks associated with the sender and recipient bank account objects. More specifically, it will have to make use of the &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; method. For an example of how to format a tryLock, look below:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;Lock lock = ...&lt;br /&gt;
if (lock.tryLock()) {&lt;br /&gt;
	try {&lt;br /&gt;
		doSomething();&lt;br /&gt;
	} finally {&lt;br /&gt;
		lock.unlock();&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BankAccountLockTrying===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|BankAccountLockTrying|attemptToTransferMoney|lock.allornothing.bank.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{ThreadSafe|public static TransferResult attemptToTransferMoney(AccountWithReentrantLock sender, AccountWithReentrantLock recipient, int amount)}}&lt;br /&gt;
&lt;br /&gt;
A couple of notes and common issues:&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; will immediately give up and return false if the lock is not available when it is called. Thus, you will need to construct a loop that will continuously run until the desired lock is available. You can exit out of this loop in two ways: with the break keyword or by returning a valid value for the method. We do this for you so you will not need to write any loops.&lt;br /&gt;
*&amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt; will grab the lock if it can. There's no need to call &amp;lt;code&amp;gt;lock()&amp;lt;/code&amp;gt; after &amp;lt;code&amp;gt;tryLock()&amp;lt;/code&amp;gt;.&lt;br /&gt;
*We recommend you call the &amp;lt;code&amp;gt;TransferUtils.checkBalanceAndTransfer(sender, receiver, amount)&amp;lt;/code&amp;gt; method for the sake of simplicity. This method will check that the sender and recipient are not the same people and that the sender has enough money in her account to send the specified amount to the recipient.&lt;br /&gt;
*Anytime you lock a lock object, you should/must use a &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; block to unlock the lock.&lt;br /&gt;
*Your implementation will have to make use of a nested &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; block (one &amp;lt;code&amp;gt;try/finally&amp;lt;/code&amp;gt; call within another).&lt;br /&gt;
&lt;br /&gt;
===AllOrNothingLockUtils runWithAllLocksOrDontRunAtAll===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|AllOrNothingLockUtils|tryLockAll&amp;lt;br&amp;gt;unlockAllHeldLocks&amp;lt;br&amp;gt;runWithAllLocksOrDontRunAtAll|lock.allornothing.util.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private static boolean tryLockAll(List&amp;lt;ReentrantLock&amp;gt; locks)}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private static void unlockAll(List&amp;lt;ReentrantLock&amp;gt; locks)}}&lt;br /&gt;
&lt;br /&gt;
{{ThreadSafe|public static boolean runWithAllLocksOrDontRunAtAll(List&amp;lt;ReentrantLock&amp;gt; locks, Runnable body)}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: in &amp;lt;code&amp;gt;tryLockAll&amp;lt;/code&amp;gt;, you will need to call &amp;lt;code&amp;gt;tryLock&amp;lt;/code&amp;gt; on all of the given locks. However, if one fails, you will need to unlock everything you have currently locked. A lock cannot be unlocked from a thread that doesn't hold the lock. Consider using the [https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html ListIterator] interface.&lt;br /&gt;
&lt;br /&gt;
{{Warning | If tryLockAll fails to acquire all of the locks, make sure to unlock any of the locks you did acquire.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | If tryLockAll fails, when rolling back a ListIterator to unlock any locks you acquired, be sure to do an initial prev() to set the iterator in the correct location before looping through to unlock the rest.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | An IllegalMonitorStateException() means that a thread tried to unlock a lock that it was not holding. }}&lt;br /&gt;
&lt;br /&gt;
===Chef===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|Chef|attemptToPrepare|lock.allornothing.kitchen.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static boolean attemptToPrepare(Recipe recipe)}}&lt;br /&gt;
&lt;br /&gt;
A couple of notes:&lt;br /&gt;
&lt;br /&gt;
*An object of class Recipe contains a list of Appliances that it needs in order to complete the item. An object of class Appliance has a lock that you can use to make sure the method remains thread-safe.&lt;br /&gt;
*Use the &amp;lt;code&amp;gt;recipe.prepare()&amp;lt;/code&amp;gt; method in order to actually execute the recipe. Caution: this method will throw an &amp;lt;code&amp;gt;IllegalThreadStateException()&amp;lt;/code&amp;gt; if it is called without all the locks being held by the same thread that called the create method.&lt;br /&gt;
* Since it is unknown how many locks each recipe will need beforehand, make use of the &amp;lt;code&amp;gt;AllOrNothingLockUtils.runWithAllLocksOrDontRunAtAll(List&amp;lt;ReentrantLock&amp;gt; locks, Runnable body)&amp;lt;/code&amp;gt; method you wrote earlier.&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|_TryLockingTestSuite|lock.allornothing.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|all-or-nothing-locks}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Matrix_MapReduce_Framework_Assignment&amp;diff=4878</id>
		<title>Matrix MapReduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Matrix_MapReduce_Framework_Assignment&amp;diff=4878"/>
		<updated>2023-03-28T01:05:52Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: Finn Voichick and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
Dealing with [https://en.wikipedia.org/wiki/Big_data big data] is Hansel-level hot right now.  We will build two implementations to better understand the inner workings of Hadoop and Spark-like frameworks.  Your frameworks will actually be more general than just MapReduce.&lt;br /&gt;
&lt;br /&gt;
The Matrix implementation gives us experience with dividing the work up into thread confined tasks whose results are then combined together.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://en.wikipedia.org/wiki/MapReduce wikipedia article on MapReduce]&lt;br /&gt;
&lt;br /&gt;
As the name suggests, MapReduce refers to the process of mapping then reducing some stream of data. At its core, all a MapReduce algorithm entails is transforming a list of one kind of item before collecting those items and reducing them down to a single values per key using some computation. As you can probably tell, the concept of MapReduce is extremely general and can apply to a wide berth of problems. In this assignment, we will use MapReduce to simulate the Facebook mutual friends algorithm (finding the mutual friends between all friend pairs) as well as pinpointing the offending well in the 1854 Soho Cholera Outbreak.&lt;br /&gt;
&lt;br /&gt;
For more information on the general concept of MapReduce, refer to [https://stackoverflow.com/questions/28982/simple-explanation-of-mapreduce this] article.&lt;br /&gt;
&lt;br /&gt;
=Java Advice=&lt;br /&gt;
==Parameterized Type Array Tip==&lt;br /&gt;
We need to create an array of Maps in this assignment, but creating arrays of parameterized types in Java is madness inducing.  Some details are available in [https://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays Java Generics Restrictions].&lt;br /&gt;
&lt;br /&gt;
The example below creates an array of List&amp;lt;String&amp;gt;.  Creating Map&amp;lt;K, V&amp;gt; follows a similar syntax. The &amp;lt;code&amp;gt;@SuppressWarnings&amp;lt;/code&amp;gt; annotation is optional.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;@SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
List&amp;lt;String&amp;gt;[] result = new List[length];&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use map.entrySet()==&lt;br /&gt;
Prefer the use of [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet-- map.entrySet()] over map.keySet() followed by looking up the value with map.get(key).&lt;br /&gt;
&lt;br /&gt;
==Use the appropriate version of join_fork_loop==&lt;br /&gt;
there are many overloaded versions of join_fork_loop including:&lt;br /&gt;
&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(int,int,fj.api.TaskIntFunction) range of ints from min to maxExclusive]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) array]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Iterable,fj.api.TaskFunction) Iterable]&lt;br /&gt;
&lt;br /&gt;
choose the correct one for each situation where &amp;quot;correct&amp;quot; is often the one that produces the cleanest code.&lt;br /&gt;
&lt;br /&gt;
=Mistakes To Avoid=&lt;br /&gt;
{{Warning | Arrays (and Matrices) are initially filled with null.  You must fill them with instances before you act on individual elements.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Ensure that your [[Ranges|Ranges exercise]] is conforming to spec.}}&lt;br /&gt;
&lt;br /&gt;
=Code To Use=&lt;br /&gt;
==Mapper&amp;lt;E,K,V&amp;gt;==&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/mapreduce/core/Mapper.html Mapper]&lt;br /&gt;
&lt;br /&gt;
recall your [[MapReduce_Mapper_Assignment|Mapper]] exercise.&lt;br /&gt;
&lt;br /&gt;
==AccumulatorCombinerReducer&amp;lt;V,A,R&amp;gt;==&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/mapreduce/core/AccumulatorCombinerReducer.html AccumulatorCombinerReducer]&lt;br /&gt;
&lt;br /&gt;
recall your [[MapReduce_Reducer_Assignment|AccumulatorCombinerReducer]] exercise.&lt;br /&gt;
&lt;br /&gt;
==Ranges==&lt;br /&gt;
&lt;br /&gt;
recall your [[Ranges|Ranges]] exercise.&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/range/exercise/Range.html class Range]&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/range/exercise/Range.html#min() min()]&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/range/exercise/Range.html#maxExclusive() maxExclusive()]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/range/exercise/Ranges.html class Ranges]&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/range/exercise/Ranges.html#slice(int,int,int) &amp;lt;nowiki&amp;gt;static Range[] slice​(int min, int maxExclusive, int numRanges)&amp;lt;/nowiki&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
==MultiWrapMap==&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/util/MultiWrapMap.html class MultiWrapMap&amp;lt;K,V&amp;gt;] extends [https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/util/AbstractMap.html AbstractMap&amp;lt;K, V&amp;gt;]&lt;br /&gt;
: constructor [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/util/MultiWrapMap.html#%3Cinit%3E(java.util.Map%5B%5D,java.util.function.ToIntFunction) MultiWrapMap(maps, hashFunction)]&lt;br /&gt;
&lt;br /&gt;
=A Path To Victory=&lt;br /&gt;
* [[Int_Sum_MapReduce_Apps_Studio|Int Sum MR App Exercise]]&lt;br /&gt;
* [[Collector_MapReduce_Studio|Reducer Exercise]]&lt;br /&gt;
* [[Mutual_Friends_MapReduce_Application|Mutual Friends MR App Exercise]]&lt;br /&gt;
* [[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework Warm Up]]&lt;br /&gt;
* [[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework Warm Up]]&lt;br /&gt;
* [[Bottleneck_MapReduce_Framework_Assignment|Bottlenecked MapReduce Framework Exercise]]&lt;br /&gt;
* '''This Exercise'''&lt;br /&gt;
&lt;br /&gt;
==Matrix MapReduce Framework==&lt;br /&gt;
{{CodeToImplement|MatrixMapReduceFramework|mapper&amp;lt;br/&amp;gt;accumulatorCombinerReducer&amp;lt;br/&amp;gt; mapAndAccumulateTaskCount&amp;lt;br/&amp;gt;mapAndAccumulateTaskCount&amp;lt;br/&amp;gt;combineAndReduceTaskCount&amp;lt;br/&amp;gt;hashFunction&amp;lt;br/&amp;gt;mapAndAccumulateAll&amp;lt;br&amp;gt;combineAndFinishAll|mapreduce.framework.matrix.exercise}}&lt;br /&gt;
&lt;br /&gt;
Navigate to the &amp;lt;code&amp;gt;MatrixMapReduceFramework.java&amp;lt;/code&amp;gt; class and there will be several drawing your attention to instance variables you should be keeping methods and two interesting methods for you to complete: mapAndAccumulateAll and combineAndFinishAll. These frameworks are meant to be extremely general and applied to more specific uses of MapReduce.&lt;br /&gt;
&lt;br /&gt;
The matrix framework is much more complex than the bottlenecked framework, but it boosts performance by grouping the map and accumulate stages so that everything can run in parallel. It does so by slicing up the given data into the specified mapTaskCount number of slices and assigns a reduce task number to each entry using the HashUtils arrayIndexForKey() method. This, in effect, creates a matrix of dictionaries, hence the name of the framework. In the combineAndFinishAll stage, the matrix comes in handy by allowing us to go directly down the columns of the matrix (as each key is essentially grouped into a bucket), combining and reducing elements all-in-one. This concept was explained in more depth during class.&lt;br /&gt;
&lt;br /&gt;
===constructor===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
	public MatrixMapReduceFramework(Mapper&amp;lt;E, K, V&amp;gt; mapper,&lt;br /&gt;
			AccumulatorCombinerReducer&amp;lt;V, A, R&amp;gt; accumulatorCombinerReducer,&lt;br /&gt;
			int mapAndAccumulateTaskCount,&lt;br /&gt;
			int combineAndReduceTaskCount,&lt;br /&gt;
			ToIntFunction&amp;lt;K&amp;gt; hashFunction) {&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Hang onto each parameter value in an instance variable.&lt;br /&gt;
&lt;br /&gt;
===mapper===&lt;br /&gt;
This method exists to remind you to use the mapper. &lt;br /&gt;
&lt;br /&gt;
===accumulatorCombinerReducer===&lt;br /&gt;
This method exists to remind you to use the accumulatorCombinerReducer. &lt;br /&gt;
&lt;br /&gt;
===mapAndAccumulateTaskCount===&lt;br /&gt;
This method exists to remind you to use the mapAndAccumulateTaskCount.&lt;br /&gt;
&lt;br /&gt;
Create a row in your matrix for each mapAndAccumulate task.&lt;br /&gt;
&lt;br /&gt;
===combineAndReduceTaskCount===&lt;br /&gt;
This method exists to remind you to use the combineAndReduceTaskCount. &lt;br /&gt;
&lt;br /&gt;
Create a column in your matrix for each combineAndReduc task.&lt;br /&gt;
&lt;br /&gt;
===hashFunction===&lt;br /&gt;
This method exists to remind you to use the hashFunction. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===mapAndAccumulateAll===&lt;br /&gt;
{{Parallel|Map&amp;lt;K, A&amp;gt;[][] mapAndAccumulateAll(E[] input)}}&lt;br /&gt;
&lt;br /&gt;
In this stage, you will map and accumulate a given array of data into a matrix of dictionaries. This method should run in parallel while performing the map and accumulate portions of the bottlenecked framework (which we recommend you complete prior to embarking on this mission). As mentioned previously, the input should be sliced into a mapTaskCount number of IndexedRanges and then mapped/accumulated into its appropriate dictionary in the matrix. Although you could slice up the data into chunks yourself, we require using an identical algorithm as performed the &amp;lt;code&amp;gt;Range&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Ranges&amp;lt;/code&amp;gt; classes introduced earlier in the course.  This will allow us to provide better feedback to allow you to pinpoint bugs sooner.  What is the best way to perform an identical algorithm to your Ranges exercise?  Use your Ranges exercise, of course.&lt;br /&gt;
&lt;br /&gt;
For each slice, the mapper should map the input into its appropriate cell in the matrix and accumulate it into that specific dictionary. Essentially, you will need to nestle the actions of the accumulate method into the mapper. In order to find where the input should go in the matrix, remember that you can either pass &amp;lt;code&amp;gt;Map[].class&amp;lt;/code&amp;gt; to [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Class,T%5B%5D,fj.api.TaskFunction) &amp;lt;code&amp;gt;join_fork_loop&amp;lt;/code&amp;gt;] or use [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_void_fork_loop_with_index(T%5B%5D,fj.api.TaskConsumerWithIndex) &amp;lt;code&amp;gt;join_void_fork_loop_with_index&amp;lt;/code&amp;gt;] and HashUtils has a toIndex method.  Which is applicable to the row and which is applicable to the column?&lt;br /&gt;
&lt;br /&gt;
Hint: The number of rows should match the number of Ranges.&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do NOT copy over the Bottlenecked approach.  Perform accumulation live}}&lt;br /&gt;
&lt;br /&gt;
[[File:Matrix map accumulate all.png|400px]] [https://docs.google.com/presentation/d/1bSLKsI5u2e_tFc0d-RSb0BIDwA-kD75U6yXfxvpMf6Y/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ebdc248f6_0_347 slide]&lt;br /&gt;
&lt;br /&gt;
[[File:Matrix map accumulate art.png|400px]] [https://docs.google.com/presentation/d/1bSLKsI5u2e_tFc0d-RSb0BIDwA-kD75U6yXfxvpMf6Y/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ebdc248f6_0_388 slide]&lt;br /&gt;
&amp;lt;!-- [[File:Matrix map accumulate death.png]]--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===combineAndReduceAll===&lt;br /&gt;
{{Parallel|Map&amp;lt;K, R&amp;gt; combineAndReduceAll(Map&amp;lt;K, A&amp;gt;[][] input)}}&lt;br /&gt;
&lt;br /&gt;
In this stage, you will take the matrix you just completed and combine all of the separate rows down to one array. Afterward, you will convert this combined array of maps into one final map. This method should run in parallel.&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, you should go directly down the matrix to access the same bucket across the different slices you created in the mapAndAccumulateAll step. For all of the maps in a column, you should go through each entry and combine it down into one row. You will need to make use of the Reducer’s reduce() method again, but you will also need to make use of the combine() method.  Although a combine step was unnecessary for the bottlenecked framework, the reduce() step should mirror what you did previously.&lt;br /&gt;
&lt;br /&gt;
[[File:Matrix combine finish all.png|400px]] [https://docs.google.com/presentation/d/1bSLKsI5u2e_tFc0d-RSb0BIDwA-kD75U6yXfxvpMf6Y/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ebdc248f6_0_425 slide]&lt;br /&gt;
====return value====&lt;br /&gt;
{{Requirement|You must use the provided [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/util/MultiWrapMap.html MultiWrapMap] class to collect the output and return it as a valid output. (MultiWrapMap implements Map.)}}&lt;br /&gt;
&lt;br /&gt;
To understand how to use MultiWrapMap, we can investigate an snippet of its code:&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|MultiWrapMap|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MultiWrapMap&amp;lt;K, V&amp;gt; extends AbstractMap&amp;lt;K, V&amp;gt; {&lt;br /&gt;
	private final Map&amp;lt;K, V&amp;gt;[] maps;&lt;br /&gt;
	private final ToIntFunction&amp;lt;K&amp;gt; toArrayIndexFuntion;&lt;br /&gt;
	public MultiWrapMap(Map&amp;lt;K, V&amp;gt;[] maps, ToIntFunction&amp;lt;K&amp;gt; toArrayIndexFuntion) {&lt;br /&gt;
		this.maps = maps;&lt;br /&gt;
		this.toArrayIndexFuntion = toArrayIndexFuntion;&lt;br /&gt;
	}&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
	private Map&amp;lt;K, V&amp;gt; getMap(Object key) {&lt;br /&gt;
		int index = toArrayIndexFuntion.applyAsInt((K) key);&lt;br /&gt;
		return maps[index];&lt;br /&gt;
	}&lt;br /&gt;
	@Override&lt;br /&gt;
	public V get(Object key) {&lt;br /&gt;
		return this.getMap(key).get(key);&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The constructor requires an array of Maps and a toArrayIndexFuntion.  What should you pass in as the toArrayIndexFuntion?&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__MatrixFrameworkTestSuite|mapreduce.framework.matrix.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|mapreduce-matrix-framework}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4769</id>
		<title>Bottleneck MapReduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4769"/>
		<updated>2023-02-28T21:46:42Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: /* Bottlenecked MapReduce Framework */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: Finn Voichick and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
Dealing with [https://en.wikipedia.org/wiki/Big_data big data] is Hansel-level hot right now.  We will build two implementations to better understand the inner workings of Hadoop and Spark-like frameworks.  Your frameworks will actually be more general than just MapReduce.&lt;br /&gt;
&lt;br /&gt;
This framework will help prepare you for building the [[Matrix_MapReduce_Framework_Assignment|Matrix Framework]] next.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://en.wikipedia.org/wiki/MapReduce wikipedia article on MapReduce]&lt;br /&gt;
&lt;br /&gt;
As the name suggests, MapReduce refers to the process of mapping then reducing some stream of data. At its core, all a MapReduce algorithm entails is transforming a list of one kind of item before collecting those items and reducing them down to a single values per key using some computation. As you can probably tell, the concept of MapReduce is extremely general and can apply to a wide berth of problems. In this assignment, we will build a MapReduce framework which can be used to to simulate the Facebook mutual friends algorithm (finding the mutual friends between all friend pairs) as well as pinpointing the offending well in the 1854 Soho Cholera Outbreak.&lt;br /&gt;
&lt;br /&gt;
For more information on the general concept of MapReduce, refer to [https://stackoverflow.com/questions/28982/simple-explanation-of-mapreduce this] article.&lt;br /&gt;
&lt;br /&gt;
=Java Advice=&lt;br /&gt;
==Use map.entrySet()==&lt;br /&gt;
Prefer the use of [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet-- map.entrySet()] over map.keySet() followed by looking up the value with map.get(key).&lt;br /&gt;
&lt;br /&gt;
==Use the appropriate version of join_fork_loop==&lt;br /&gt;
there are many overloaded versions of join_fork_loop including:&lt;br /&gt;
&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(int,int,fj.api.TaskIntFunction) range of ints from min to maxExclusive]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) array]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Iterable,fj.api.TaskFunction) Iterable]&lt;br /&gt;
&lt;br /&gt;
choose the correct one for each situation where &amp;quot;correct&amp;quot; is often the one that produces the cleanest code.&lt;br /&gt;
&lt;br /&gt;
=A Path To Victory=&lt;br /&gt;
* [[MapReduce_Mapper_Assignment|MapReduce Mapper Assignment]]&lt;br /&gt;
* [[MapReduce_Reducer_Assignment|MapReduce Reducer Assignment]]&lt;br /&gt;
* [[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework Warm Up]]&lt;br /&gt;
* [[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework Warm Up]]&lt;br /&gt;
* [[Mutual_Friends_MapReduce_Application|Mutual Friends MR App Exercise]]&lt;br /&gt;
* '''This Exercise'''&lt;br /&gt;
&lt;br /&gt;
=Warm Ups=&lt;br /&gt;
[[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework]]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==WordCountOnlyParallelMapReduceFramework==&lt;br /&gt;
You will build each of the three methods mapReduceAll(input) invokes.  Much can be gleaned from the parameters and return values of these methods.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|mapReduceAll(TextSection[] input)|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Override&lt;br /&gt;
public Map&amp;lt;K, R&amp;gt; mapReduceAll(E[] input) throws InterruptedException, ExecutionException {&lt;br /&gt;
	List&amp;lt;List&amp;lt;Map.Entry&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAllResult = mapAll(input);&lt;br /&gt;
	Map&amp;lt;K, A&amp;gt; accumulateAllResult = accumulateAll(mapAllResult);&lt;br /&gt;
	return reduceAll(accumulateAllResult);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
&lt;br /&gt;
For Account[] input:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| input[0] || Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[1] || Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A, C, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[2] || Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A, B, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[3] || Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A, B, C, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[4] || Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends MapAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends AccumulateAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
[[File:MutualFriends_ReduceAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
{{Client|WordCountOnlyParallelMapReduceFrameworkClient|mapreduce.framework.parallel.client|main}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|WordCountOnlyParallelMapReduceFrameworkClient|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// credit: https://web.archive.org/web/20201109035737/http://stevekrenzel.com/finding-friends-with-mapreduce&lt;br /&gt;
Account[] input = {&lt;br /&gt;
		Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B,C,D&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A,C,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A,B,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A,B,C,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B,C,D&amp;quot;)&lt;br /&gt;
};&lt;br /&gt;
MapReduceFramework&amp;lt;Account, // E&lt;br /&gt;
		OrderedPair&amp;lt;AccountId&amp;gt;, // K&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt;, // V&lt;br /&gt;
		List&amp;lt;Set&amp;lt;AccountId&amp;gt;&amp;gt;, // A&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt; // R&lt;br /&gt;
&amp;gt; framework = new BottleneckedMapReduceFramework&amp;lt;&amp;gt;(&lt;br /&gt;
		new MutualFriendsMapper(),&lt;br /&gt;
		new MutualFriendsClassicReducer());&lt;br /&gt;
Map&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; map = framework.mapReduceAll(input);&lt;br /&gt;
for (Map.Entry&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; entry : map.entrySet()) {&lt;br /&gt;
	System.out.println(entry);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|CardOnlySequentialMapReduceFrameworkClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;(A, B)=[C, D]&lt;br /&gt;
(A, C)=[B, D]&lt;br /&gt;
(D, E)=[B, C]&lt;br /&gt;
(A, D)=[B, C]&lt;br /&gt;
(B, C)=[A, D, E]&lt;br /&gt;
(B, D)=[A, C, E]&lt;br /&gt;
(B, E)=[C, D]&lt;br /&gt;
(C, D)=[A, B, E]&lt;br /&gt;
(C, E)=[B, D]&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
&lt;br /&gt;
==Bottlenecked MapReduce Framework==&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|BottleneckedMapReduceFramework|constructor&amp;lt;br/&amp;gt;mapper&amp;lt;br/&amp;gt;accumulatorCombinerReducer&amp;lt;br/&amp;gt;mapAll&amp;lt;br/&amp;gt;accumulateAll&amp;lt;br/&amp;gt;toReductions&amp;lt;br/&amp;gt;toReductionMap|mapreduce.framework.bottlenecked.exercise}}&lt;br /&gt;
&lt;br /&gt;
Navigate to the &amp;lt;code&amp;gt;BottleneckedMapReduceFramework.java&amp;lt;/code&amp;gt; class and there will be three methods for you to complete: mapAll, accumulateAll, and finishAll. These frameworks are meant to be extremely general and applied to more specific uses of MapReduce.  Whereas the warm ups for this lab serve to prepare you to build this required section of the lab, this bottlenecked framework is in many ways a warm up for the matrix implementation.&lt;br /&gt;
&lt;br /&gt;
===constructor, mapper, accumulatorCombinerReducer===&lt;br /&gt;
As usual, store the values passed into the constructor in instance variables and implement the getter methods to retrieve their values.&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
NOTE: If you struggle to get through this method, you are strongly encouraged to try the warm-ups.&lt;br /&gt;
&lt;br /&gt;
{{Parallel|List&amp;lt;List&amp;lt;Map.Entry&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAll(E[] input)}}&lt;br /&gt;
&lt;br /&gt;
With this method, you will map all of the elements of an array of data into a new array of equivalent size consisting of Lists of key value pairs.  We will leverage the Mapper which is a field/instance variable on this BottleneckedFramework instance.  When invoking the mapper's map method with an element of the input array and a BiConsumer which will  accept each key and value passed to it, adding a KeyValuePair to its List. This list should then be added to the array of lists you previously defined, therefore completing the mapping stage of MapReduce. This should all be done in parallel.&lt;br /&gt;
&lt;br /&gt;
Hint: you should create a List of Lists equivalent in size to the original array. Each inner list will contain all of the emitted (key,value) pairs for its item.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked map all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_130 slide]&lt;br /&gt;
&lt;br /&gt;
{{Tip|Think about which verion of the [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) '''join_fork_loop'''] would be the best to use here.}}&lt;br /&gt;
&lt;br /&gt;
====Example: Mutual Friends====&lt;br /&gt;
=====Input=====&lt;br /&gt;
[[File:Mutual_Friends_Input.svg]]&lt;br /&gt;
=====Result of mapAll(input)=====&lt;br /&gt;
[[File:Mutual_Friends_Bottlenecked_Map_All_Result.svg|1024px]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
{{Sequential|Map&amp;lt;K, A&amp;gt; accumulateAll(List&amp;lt;List&amp;lt;Map.Entry&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAllResults)}}&lt;br /&gt;
&lt;br /&gt;
This middle step is often excluded in more advanced MapReduce applications. This step introduces a long sequential strand. In the matrix framework implementation, we will do away with this step altogether for the sake of performance.&lt;br /&gt;
&lt;br /&gt;
You will make use of the Reducer provided to you.&lt;br /&gt;
&lt;br /&gt;
In this method, you will take in the list of lists you previously created in mapAll.  You probably noticed that the method must return a map of &amp;lt;K, A&amp;gt;, which differs from the &amp;lt;K, V&amp;gt; lists fed into the method.  The framework is designed this way as the data originally fed into the mapping stage can be collected into a mutable container before reaching the reduction stage.  You will need to create a mutable container of type A for each unique key encountered and associate the key with that mutable container in a Map.  Whether it is the first time a key has been encountered or not, the value must be accumulated into the mutable container.&lt;br /&gt;
&lt;br /&gt;
{{Tip| Look into the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function- computeIfAbsent(key, remappingFunction)] method on [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map]}}&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked accumulate all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_165 slide]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private Map&amp;lt;K, R&amp;gt; reduceAll(Map&amp;lt;K, A&amp;gt; accumulateAllResult) throws InterruptedException, ExecutionException {&lt;br /&gt;
        Entry&amp;lt;K, A&amp;gt;[] entries = toArrayOfEntries(accumulateAllResult);&lt;br /&gt;
        List&amp;lt;R&amp;gt; reductions = toReductions(entries);&lt;br /&gt;
        return toReductionMap(entries, reductions);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toArrayOfEntries====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private static &amp;lt;K, A&amp;gt; Entry&amp;lt;K, A&amp;gt;[] toArrayOfEntries(Map&amp;lt;K, A&amp;gt; accumulateAllResult) {&lt;br /&gt;
        return accumulateAllResult.entrySet().toArray(Entry[]::new);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toReductions and toReductionMap====&lt;br /&gt;
{{Parallel|List&amp;lt;R&amp;gt; toReductions(Entry&amp;lt;K, A&amp;gt;[] entries)}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|Map&amp;lt;K, R&amp;gt; toReductionMap(Entry&amp;lt;K, A&amp;gt;[] entries, List&amp;lt;R&amp;gt; reductions)}}&lt;br /&gt;
&lt;br /&gt;
This final step reduces the accumulated data and returns the final map in its reduced form. Again, you may notice that the method returns a map of &amp;lt;K, R&amp;gt; instead of the &amp;lt;K, A&amp;gt; which was returned in the accumulateAll method. This happens for the exact same reason as the accumulateAll method, as the framework is designed to handle cases in which the reduced data differs in type from the accumulated data.&lt;br /&gt;
&lt;br /&gt;
To reduce the data down, use the map returned from the accumulateAll stage and put the results of the reduction into a new map. The provided Reducer will come in extremely handy for this stage, more specifically the finisher which can be called using the &amp;lt;code&amp;gt;reduce()&amp;lt;/code&amp;gt; method. This step should run in parallel and will probably be the easiest of the three methods.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked finish all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_221 slide]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__BottleneckedFrameworkTestSuite|mapreduce.framework.bottlenecked.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|mapreduce-bottleneck-framework}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4768</id>
		<title>Bottleneck MapReduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4768"/>
		<updated>2023-02-28T21:29:45Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: /* A Path To Victory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: Finn Voichick and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
Dealing with [https://en.wikipedia.org/wiki/Big_data big data] is Hansel-level hot right now.  We will build two implementations to better understand the inner workings of Hadoop and Spark-like frameworks.  Your frameworks will actually be more general than just MapReduce.&lt;br /&gt;
&lt;br /&gt;
This framework will help prepare you for building the [[Matrix_MapReduce_Framework_Assignment|Matrix Framework]] next.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://en.wikipedia.org/wiki/MapReduce wikipedia article on MapReduce]&lt;br /&gt;
&lt;br /&gt;
As the name suggests, MapReduce refers to the process of mapping then reducing some stream of data. At its core, all a MapReduce algorithm entails is transforming a list of one kind of item before collecting those items and reducing them down to a single values per key using some computation. As you can probably tell, the concept of MapReduce is extremely general and can apply to a wide berth of problems. In this assignment, we will build a MapReduce framework which can be used to to simulate the Facebook mutual friends algorithm (finding the mutual friends between all friend pairs) as well as pinpointing the offending well in the 1854 Soho Cholera Outbreak.&lt;br /&gt;
&lt;br /&gt;
For more information on the general concept of MapReduce, refer to [https://stackoverflow.com/questions/28982/simple-explanation-of-mapreduce this] article.&lt;br /&gt;
&lt;br /&gt;
=Java Advice=&lt;br /&gt;
==Use map.entrySet()==&lt;br /&gt;
Prefer the use of [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet-- map.entrySet()] over map.keySet() followed by looking up the value with map.get(key).&lt;br /&gt;
&lt;br /&gt;
==Use the appropriate version of join_fork_loop==&lt;br /&gt;
there are many overloaded versions of join_fork_loop including:&lt;br /&gt;
&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(int,int,fj.api.TaskIntFunction) range of ints from min to maxExclusive]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) array]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Iterable,fj.api.TaskFunction) Iterable]&lt;br /&gt;
&lt;br /&gt;
choose the correct one for each situation where &amp;quot;correct&amp;quot; is often the one that produces the cleanest code.&lt;br /&gt;
&lt;br /&gt;
=A Path To Victory=&lt;br /&gt;
* [[MapReduce_Mapper_Assignment|MapReduce Mapper Assignment]]&lt;br /&gt;
* [[MapReduce_Reducer_Assignment|MapReduce Reducer Assignment]]&lt;br /&gt;
* [[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework Warm Up]]&lt;br /&gt;
* [[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework Warm Up]]&lt;br /&gt;
* [[Mutual_Friends_MapReduce_Application|Mutual Friends MR App Exercise]]&lt;br /&gt;
* '''This Exercise'''&lt;br /&gt;
&lt;br /&gt;
=Warm Ups=&lt;br /&gt;
[[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework]]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==WordCountOnlyParallelMapReduceFramework==&lt;br /&gt;
You will build each of the three methods mapReduceAll(input) invokes.  Much can be gleaned from the parameters and return values of these methods.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|mapReduceAll(TextSection[] input)|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Override&lt;br /&gt;
public Map&amp;lt;K, R&amp;gt; mapReduceAll(E[] input) throws InterruptedException, ExecutionException {&lt;br /&gt;
	List&amp;lt;List&amp;lt;Map.Entry&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAllResult = mapAll(input);&lt;br /&gt;
	Map&amp;lt;K, A&amp;gt; accumulateAllResult = accumulateAll(mapAllResult);&lt;br /&gt;
	return reduceAll(accumulateAllResult);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
&lt;br /&gt;
For Account[] input:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| input[0] || Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[1] || Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A, C, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[2] || Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A, B, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[3] || Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A, B, C, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[4] || Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends MapAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends AccumulateAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
[[File:MutualFriends_ReduceAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
{{Client|WordCountOnlyParallelMapReduceFrameworkClient|mapreduce.framework.parallel.client|main}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|WordCountOnlyParallelMapReduceFrameworkClient|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// credit: https://web.archive.org/web/20201109035737/http://stevekrenzel.com/finding-friends-with-mapreduce&lt;br /&gt;
Account[] input = {&lt;br /&gt;
		Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B,C,D&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A,C,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A,B,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A,B,C,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B,C,D&amp;quot;)&lt;br /&gt;
};&lt;br /&gt;
MapReduceFramework&amp;lt;Account, // E&lt;br /&gt;
		OrderedPair&amp;lt;AccountId&amp;gt;, // K&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt;, // V&lt;br /&gt;
		List&amp;lt;Set&amp;lt;AccountId&amp;gt;&amp;gt;, // A&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt; // R&lt;br /&gt;
&amp;gt; framework = new BottleneckedMapReduceFramework&amp;lt;&amp;gt;(&lt;br /&gt;
		new MutualFriendsMapper(),&lt;br /&gt;
		new MutualFriendsClassicReducer());&lt;br /&gt;
Map&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; map = framework.mapReduceAll(input);&lt;br /&gt;
for (Map.Entry&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; entry : map.entrySet()) {&lt;br /&gt;
	System.out.println(entry);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|CardOnlySequentialMapReduceFrameworkClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;(A, B)=[C, D]&lt;br /&gt;
(A, C)=[B, D]&lt;br /&gt;
(D, E)=[B, C]&lt;br /&gt;
(A, D)=[B, C]&lt;br /&gt;
(B, C)=[A, D, E]&lt;br /&gt;
(B, D)=[A, C, E]&lt;br /&gt;
(B, E)=[C, D]&lt;br /&gt;
(C, D)=[A, B, E]&lt;br /&gt;
(C, E)=[B, D]&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
&lt;br /&gt;
==Bottlenecked MapReduce Framework==&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|BottleneckedMapReduceFramework|mapAll&amp;lt;br/&amp;gt;accumulateAll&amp;lt;br/&amp;gt;toArrayOfReductions&amp;lt;br/&amp;gt;toReductionMap|mapreduce.framework.lab.bottlenecked}}&lt;br /&gt;
&lt;br /&gt;
Navigate to the &amp;lt;code&amp;gt;BottleneckedMapReduceFramework.java&amp;lt;/code&amp;gt; class and there will be three methods for you to complete: mapAll, accumulateAll, and finishAll. These frameworks are meant to be extremely general and applied to more specific uses of MapReduce.  Whereas the warm ups for this lab serve to prepare you to build this required section of the lab, this bottlenecked framework is in many ways a warm up for the matrix implementation.&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
NOTE: If you struggle to get through this method, you are strongly encouraged to try the warm-ups.&lt;br /&gt;
&lt;br /&gt;
{{Parallel|List&amp;lt;List&amp;lt;KeyValuePair&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAll(E[] input)}}&lt;br /&gt;
&lt;br /&gt;
With this method, you will map all of the elements of an array of data into a new array of equivalent size consisting of Lists of key value pairs.  We will leverage the Mapper which is a field/instance variable on this BottleneckedFramework instance.  When invoking the mapper's map method with an element of the input array and a BiConsumer which will  accept each key and value passed to it, adding a KeyValuePair to its List. This list should then be added to the array of lists you previously defined, therefore completing the mapping stage of MapReduce. This should all be done in parallel.&lt;br /&gt;
&lt;br /&gt;
Hint: you should create a List of Lists equivalent in size to the original array. Each inner list will contain all of the emitted (key,value) pairs for its item.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked map all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_130 slide]&lt;br /&gt;
&lt;br /&gt;
{{Tip|Think about which verion of the [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) '''join_fork_loop'''] would be the best to use here.}}&lt;br /&gt;
&lt;br /&gt;
====Example: Mutual Friends====&lt;br /&gt;
=====Input=====&lt;br /&gt;
[[File:Mutual_Friends_Input.svg]]&lt;br /&gt;
=====Result of mapAll(input)=====&lt;br /&gt;
[[File:Mutual_Friends_Bottlenecked_Map_All_Result.svg|1024px]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
{{Sequential|Map&amp;lt;K, A&amp;gt; accumulateAll(List&amp;lt;KeyValuePair&amp;lt;K, V&amp;gt;&amp;gt;[] mapAllResults)}}&lt;br /&gt;
&lt;br /&gt;
This middle step is often excluded in more advanced MapReduce applications. This step introduces a long sequential strand. In the matrix framework implementation, we will do away with this step altogether for the sake of performance.&lt;br /&gt;
&lt;br /&gt;
You will make use of the Reducer provided to you.&lt;br /&gt;
&lt;br /&gt;
In this method, you will take in the list of lists you previously created in mapAll.  You probably noticed that the method must return a map of &amp;lt;K, A&amp;gt;, which differs from the &amp;lt;K, V&amp;gt; lists fed into the method.  The framework is designed this way as the data originally fed into the mapping stage can be collected into a mutable container before reaching the reduction stage.  You will need to create a mutable container of type A for each unique key encountered and associate the key with that mutable container in a Map.  Whether it is the first time a key has been encountered or not, the value must be accumulated into the mutable container.&lt;br /&gt;
&lt;br /&gt;
{{Tip| Look into the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function- computeIfAbsent(key, remappingFunction)] method on [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map]}}&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked accumulate all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_165 slide]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private Map&amp;lt;K, R&amp;gt; reduceAll(Map&amp;lt;K, A&amp;gt; accumulateAllResult) throws InterruptedException, ExecutionException {&lt;br /&gt;
        Entry&amp;lt;K, A&amp;gt;[] entries = toArrayOfEntries(accumulateAllResult);&lt;br /&gt;
        List&amp;lt;R&amp;gt; reductions = toReductions(entries);&lt;br /&gt;
        return toReductionMap(entries, reductions);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toArrayOfEntries====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private static &amp;lt;K, A&amp;gt; Entry&amp;lt;K, A&amp;gt;[] toArrayOfEntries(Map&amp;lt;K, A&amp;gt; accumulateAllResult) {&lt;br /&gt;
        return accumulateAllResult.entrySet().toArray(Entry[]::new);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toReductions and toReductionMap====&lt;br /&gt;
{{Parallel|List&amp;lt;R&amp;gt; toReductions(Entry&amp;lt;K, A&amp;gt;[] entries)}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|Map&amp;lt;K, R&amp;gt; toReductionMap(Entry&amp;lt;K, A&amp;gt;[] entries, R[] reductions)}}&lt;br /&gt;
&lt;br /&gt;
This final step reduces the accumulated data and returns the final map in its reduced form. Again, you may notice that the method returns a map of &amp;lt;K, R&amp;gt; instead of the &amp;lt;K, A&amp;gt; which was returned in the accumulateAll method. This happens for the exact same reason as the accumulateAll method, as the framework is designed to handle cases in which the reduced data differs in type from the accumulated data.&lt;br /&gt;
&lt;br /&gt;
To reduce the data down, use the map returned from the accumulateAll stage and put the results of the reduction into a new map. The provided Reducer will come in extremely handy for this stage, more specifically the finisher which can be called using the &amp;lt;code&amp;gt;reduce()&amp;lt;/code&amp;gt; method. This step should run in parallel and will probably be the easiest of the three methods.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked finish all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_221 slide]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__BottleneckedFrameworkTestSuite|mapreduce.framework.bottlenecked.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|mapreduce-bottleneck-framework}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4767</id>
		<title>Bottleneck MapReduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Bottleneck_MapReduce_Framework_Assignment&amp;diff=4767"/>
		<updated>2023-02-28T21:26:31Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;credit for this assignment: Finn Voichick and Dennis Cosgrove&lt;br /&gt;
=Motivation=&lt;br /&gt;
Dealing with [https://en.wikipedia.org/wiki/Big_data big data] is Hansel-level hot right now.  We will build two implementations to better understand the inner workings of Hadoop and Spark-like frameworks.  Your frameworks will actually be more general than just MapReduce.&lt;br /&gt;
&lt;br /&gt;
This framework will help prepare you for building the [[Matrix_MapReduce_Framework_Assignment|Matrix Framework]] next.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://en.wikipedia.org/wiki/MapReduce wikipedia article on MapReduce]&lt;br /&gt;
&lt;br /&gt;
As the name suggests, MapReduce refers to the process of mapping then reducing some stream of data. At its core, all a MapReduce algorithm entails is transforming a list of one kind of item before collecting those items and reducing them down to a single values per key using some computation. As you can probably tell, the concept of MapReduce is extremely general and can apply to a wide berth of problems. In this assignment, we will build a MapReduce framework which can be used to to simulate the Facebook mutual friends algorithm (finding the mutual friends between all friend pairs) as well as pinpointing the offending well in the 1854 Soho Cholera Outbreak.&lt;br /&gt;
&lt;br /&gt;
For more information on the general concept of MapReduce, refer to [https://stackoverflow.com/questions/28982/simple-explanation-of-mapreduce this] article.&lt;br /&gt;
&lt;br /&gt;
=Java Advice=&lt;br /&gt;
==Use map.entrySet()==&lt;br /&gt;
Prefer the use of [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#entrySet-- map.entrySet()] over map.keySet() followed by looking up the value with map.get(key).&lt;br /&gt;
&lt;br /&gt;
==Use the appropriate version of join_fork_loop==&lt;br /&gt;
there are many overloaded versions of join_fork_loop including:&lt;br /&gt;
&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(int,int,fj.api.TaskIntFunction) range of ints from min to maxExclusive]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) array]&lt;br /&gt;
* [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(java.lang.Iterable,fj.api.TaskFunction) Iterable]&lt;br /&gt;
&lt;br /&gt;
choose the correct one for each situation where &amp;quot;correct&amp;quot; is often the one that produces the cleanest code.&lt;br /&gt;
&lt;br /&gt;
=A Path To Victory=&lt;br /&gt;
* [[Int_Sum_MapReduce_Apps_Studio|Int Sum MR App Exercise]]&lt;br /&gt;
* [[Collector_MapReduce_Studio|Reducer Exercise]]&lt;br /&gt;
* [[Mutual_Friends_MapReduce_Application|Mutual Friends MR App Exercise]]&lt;br /&gt;
* [[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework Warm Up]]&lt;br /&gt;
* [[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework Warm Up]]&lt;br /&gt;
* '''This Exercise'''&lt;br /&gt;
&lt;br /&gt;
=Warm Ups=&lt;br /&gt;
[[Card_Only_Sequential_Map_Reduce_Framework_Assignment|Card Only Sequential Map Reduce Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|Word Count Only Parallel MapReduce Framework]]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==WordCountOnlyParallelMapReduceFramework==&lt;br /&gt;
You will build each of the three methods mapReduceAll(input) invokes.  Much can be gleaned from the parameters and return values of these methods.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|mapReduceAll(TextSection[] input)|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Override&lt;br /&gt;
public Map&amp;lt;K, R&amp;gt; mapReduceAll(E[] input) throws InterruptedException, ExecutionException {&lt;br /&gt;
	List&amp;lt;List&amp;lt;Map.Entry&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAllResult = mapAll(input);&lt;br /&gt;
	Map&amp;lt;K, A&amp;gt; accumulateAllResult = accumulateAll(mapAllResult);&lt;br /&gt;
	return reduceAll(accumulateAllResult);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
&lt;br /&gt;
For Account[] input:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| input[0] || Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[1] || Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A, C, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[2] || Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A, B, D, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[3] || Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A, B, C, E&amp;quot;)&lt;br /&gt;
|-&lt;br /&gt;
| input[4] || Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B, C, D&amp;quot;)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends MapAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
&lt;br /&gt;
[[File:MutualFriends AccumulateAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
[[File:MutualFriends_ReduceAllResult.svg]]&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
{{Client|WordCountOnlyParallelMapReduceFrameworkClient|mapreduce.framework.parallel.client|main}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|WordCountOnlyParallelMapReduceFrameworkClient|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// credit: https://web.archive.org/web/20201109035737/http://stevekrenzel.com/finding-friends-with-mapreduce&lt;br /&gt;
Account[] input = {&lt;br /&gt;
		Account.parse(&amp;quot;A&amp;quot;, &amp;quot;B,C,D&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;B&amp;quot;, &amp;quot;A,C,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;C&amp;quot;, &amp;quot;A,B,D,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;D&amp;quot;, &amp;quot;A,B,C,E&amp;quot;),&lt;br /&gt;
		Account.parse(&amp;quot;E&amp;quot;, &amp;quot;B,C,D&amp;quot;)&lt;br /&gt;
};&lt;br /&gt;
MapReduceFramework&amp;lt;Account, // E&lt;br /&gt;
		OrderedPair&amp;lt;AccountId&amp;gt;, // K&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt;, // V&lt;br /&gt;
		List&amp;lt;Set&amp;lt;AccountId&amp;gt;&amp;gt;, // A&lt;br /&gt;
		Set&amp;lt;AccountId&amp;gt; // R&lt;br /&gt;
&amp;gt; framework = new BottleneckedMapReduceFramework&amp;lt;&amp;gt;(&lt;br /&gt;
		new MutualFriendsMapper(),&lt;br /&gt;
		new MutualFriendsClassicReducer());&lt;br /&gt;
Map&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; map = framework.mapReduceAll(input);&lt;br /&gt;
for (Map.Entry&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; entry : map.entrySet()) {&lt;br /&gt;
	System.out.println(entry);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|CardOnlySequentialMapReduceFrameworkClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;(A, B)=[C, D]&lt;br /&gt;
(A, C)=[B, D]&lt;br /&gt;
(D, E)=[B, C]&lt;br /&gt;
(A, D)=[B, C]&lt;br /&gt;
(B, C)=[A, D, E]&lt;br /&gt;
(B, D)=[A, C, E]&lt;br /&gt;
(B, E)=[C, D]&lt;br /&gt;
(C, D)=[A, B, E]&lt;br /&gt;
(C, E)=[B, D]&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
&lt;br /&gt;
==Bottlenecked MapReduce Framework==&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|BottleneckedMapReduceFramework|mapAll&amp;lt;br/&amp;gt;accumulateAll&amp;lt;br/&amp;gt;toArrayOfReductions&amp;lt;br/&amp;gt;toReductionMap|mapreduce.framework.lab.bottlenecked}}&lt;br /&gt;
&lt;br /&gt;
Navigate to the &amp;lt;code&amp;gt;BottleneckedMapReduceFramework.java&amp;lt;/code&amp;gt; class and there will be three methods for you to complete: mapAll, accumulateAll, and finishAll. These frameworks are meant to be extremely general and applied to more specific uses of MapReduce.  Whereas the warm ups for this lab serve to prepare you to build this required section of the lab, this bottlenecked framework is in many ways a warm up for the matrix implementation.&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
NOTE: If you struggle to get through this method, you are strongly encouraged to try the warm-ups.&lt;br /&gt;
&lt;br /&gt;
{{Parallel|List&amp;lt;List&amp;lt;KeyValuePair&amp;lt;K, V&amp;gt;&amp;gt;&amp;gt; mapAll(E[] input)}}&lt;br /&gt;
&lt;br /&gt;
With this method, you will map all of the elements of an array of data into a new array of equivalent size consisting of Lists of key value pairs.  We will leverage the Mapper which is a field/instance variable on this BottleneckedFramework instance.  When invoking the mapper's map method with an element of the input array and a BiConsumer which will  accept each key and value passed to it, adding a KeyValuePair to its List. This list should then be added to the array of lists you previously defined, therefore completing the mapping stage of MapReduce. This should all be done in parallel.&lt;br /&gt;
&lt;br /&gt;
Hint: you should create a List of Lists equivalent in size to the original array. Each inner list will contain all of the emitted (key,value) pairs for its item.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked map all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_130 slide]&lt;br /&gt;
&lt;br /&gt;
{{Tip|Think about which verion of the [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/fj/FJ.html#join_fork_loop(T%5B%5D,fj.api.TaskFunction) '''join_fork_loop'''] would be the best to use here.}}&lt;br /&gt;
&lt;br /&gt;
====Example: Mutual Friends====&lt;br /&gt;
=====Input=====&lt;br /&gt;
[[File:Mutual_Friends_Input.svg]]&lt;br /&gt;
=====Result of mapAll(input)=====&lt;br /&gt;
[[File:Mutual_Friends_Bottlenecked_Map_All_Result.svg|1024px]]&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
{{Sequential|Map&amp;lt;K, A&amp;gt; accumulateAll(List&amp;lt;KeyValuePair&amp;lt;K, V&amp;gt;&amp;gt;[] mapAllResults)}}&lt;br /&gt;
&lt;br /&gt;
This middle step is often excluded in more advanced MapReduce applications. This step introduces a long sequential strand. In the matrix framework implementation, we will do away with this step altogether for the sake of performance.&lt;br /&gt;
&lt;br /&gt;
You will make use of the Reducer provided to you.&lt;br /&gt;
&lt;br /&gt;
In this method, you will take in the list of lists you previously created in mapAll.  You probably noticed that the method must return a map of &amp;lt;K, A&amp;gt;, which differs from the &amp;lt;K, V&amp;gt; lists fed into the method.  The framework is designed this way as the data originally fed into the mapping stage can be collected into a mutable container before reaching the reduction stage.  You will need to create a mutable container of type A for each unique key encountered and associate the key with that mutable container in a Map.  Whether it is the first time a key has been encountered or not, the value must be accumulated into the mutable container.&lt;br /&gt;
&lt;br /&gt;
{{Tip| Look into the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function- computeIfAbsent(key, remappingFunction)] method on [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map]}}&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked accumulate all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_165 slide]&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private Map&amp;lt;K, R&amp;gt; reduceAll(Map&amp;lt;K, A&amp;gt; accumulateAllResult) throws InterruptedException, ExecutionException {&lt;br /&gt;
        Entry&amp;lt;K, A&amp;gt;[] entries = toArrayOfEntries(accumulateAllResult);&lt;br /&gt;
        List&amp;lt;R&amp;gt; reductions = toReductions(entries);&lt;br /&gt;
        return toReductionMap(entries, reductions);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toArrayOfEntries====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    private static &amp;lt;K, A&amp;gt; Entry&amp;lt;K, A&amp;gt;[] toArrayOfEntries(Map&amp;lt;K, A&amp;gt; accumulateAllResult) {&lt;br /&gt;
        return accumulateAllResult.entrySet().toArray(Entry[]::new);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
====toReductions and toReductionMap====&lt;br /&gt;
{{Parallel|List&amp;lt;R&amp;gt; toReductions(Entry&amp;lt;K, A&amp;gt;[] entries)}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|Map&amp;lt;K, R&amp;gt; toReductionMap(Entry&amp;lt;K, A&amp;gt;[] entries, R[] reductions)}}&lt;br /&gt;
&lt;br /&gt;
This final step reduces the accumulated data and returns the final map in its reduced form. Again, you may notice that the method returns a map of &amp;lt;K, R&amp;gt; instead of the &amp;lt;K, A&amp;gt; which was returned in the accumulateAll method. This happens for the exact same reason as the accumulateAll method, as the framework is designed to handle cases in which the reduced data differs in type from the accumulated data.&lt;br /&gt;
&lt;br /&gt;
To reduce the data down, use the map returned from the accumulateAll stage and put the results of the reduction into a new map. The provided Reducer will come in extremely handy for this stage, more specifically the finisher which can be called using the &amp;lt;code&amp;gt;reduce()&amp;lt;/code&amp;gt; method. This step should run in parallel and will probably be the easiest of the three methods.&lt;br /&gt;
&lt;br /&gt;
[[File:Bottlenecked finish all.png|400px]] [https://docs.google.com/presentation/d/1Gtpj6_5_8imUMccpwxmfrOxKSED791OKl4lZR6G2Bm4/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000&amp;amp;slide=id.g7ea283730e_0_221 slide]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__BottleneckedFrameworkTestSuite|mapreduce.framework.bottlenecked.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|mapreduce-bottleneck-framework}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Mutual_Friends_MapReduce_Application&amp;diff=4766</id>
		<title>Mutual Friends MapReduce Application</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Mutual_Friends_MapReduce_Application&amp;diff=4766"/>
		<updated>2023-02-28T20:08:04Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: /* MutualFriendsMapper */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
Finding mutual friends is a compelling MapReduce App and has a nice write up on the web.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://web.archive.org/web/20201109035737/http://stevekrenzel.com/finding-friends-with-mapreduce Steve Krenzel Finding Friends]&lt;br /&gt;
&lt;br /&gt;
Be sure to complete the [[Set_Intersector_Assignment|SetIntersector&amp;lt;E&amp;gt;] warmup before starting this exercise.&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==Account==&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/mapreduce/apps/friends/core/Account.html class Account]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/s20/apidocs/mapreduce/apps/friends/core/Account.html#getId() getId()]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/mapreduce/apps/friends/core/Account.html#getFriendIds() getFriendIds()]&lt;br /&gt;
&lt;br /&gt;
==AccountId==&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/s20/apidocs/mapreduce/apps/friends/core/AccountId.html class AccountId]&lt;br /&gt;
&lt;br /&gt;
==SetIntersector&amp;lt;E&amp;gt;==&lt;br /&gt;
class [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html SetIntersector&amp;lt;E&amp;gt;]&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html#accept(java.util.Set) accept(friendIds)]&lt;br /&gt;
&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html#currentIntersection() currentIntersection()]&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
==MutualFriendsMapper==&lt;br /&gt;
{{CodeToImplement|MutualFriendsMapper|map|mapreduce.apps.friends.exercise}}&lt;br /&gt;
{{Sequential|public List&amp;lt;Map.Entry&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt;&amp;gt; map(Account account)}}&lt;br /&gt;
&lt;br /&gt;
The only method you will need to alter (and the only method in this class) is the map method. In this method, you will need to map every combination of the account holder to their friends. In order to do this, create OrderedPairs of the given account’s ID and the IDs of the account holder’s friends. For each ordered pair, you should provide the pair along with the full set of IDs of the account holder's friends.&lt;br /&gt;
&lt;br /&gt;
Hint: check out the methods in the Account class for help.&lt;br /&gt;
&lt;br /&gt;
==MutualFriendsReducer==&lt;br /&gt;
{{CodeToImplement|MutualFriendsClassicReducer|reduce|mapreduce.apps.friends.exercise}}&lt;br /&gt;
{{Sequential|public Set&amp;lt;AccountId&amp;gt; reduce(List&amp;lt;Set&amp;lt;AccountId&amp;gt;&amp;gt; container)}}&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/mapreduce/apps/friends/core/SetIntersector.html SetIntersector] can be used to calculate the set intersection.  Invoke &amp;lt;code&amp;gt;accept(set)&amp;lt;/code&amp;gt; for each set in the &amp;lt;container&amp;gt; parameter, then invoke &amp;lt;code&amp;gt;currentIntersection()&amp;lt;/code&amp;gt; to get the result.&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_MutualFriendsTestSuite|mapreduce}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Mutual_Friends_MapReduce_Application&amp;diff=4765</id>
		<title>Mutual Friends MapReduce Application</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Mutual_Friends_MapReduce_Application&amp;diff=4765"/>
		<updated>2023-02-28T20:01:00Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: /* MutualFriendsReducer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
Finding mutual friends is a compelling MapReduce App and has a nice write up on the web.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
[https://web.archive.org/web/20201109035737/http://stevekrenzel.com/finding-friends-with-mapreduce Steve Krenzel Finding Friends]&lt;br /&gt;
&lt;br /&gt;
Be sure to complete the [[Set_Intersector_Assignment|SetIntersector&amp;lt;E&amp;gt;] warmup before starting this exercise.&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==Account==&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/mapreduce/apps/friends/core/Account.html class Account]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/s20/apidocs/mapreduce/apps/friends/core/Account.html#getId() getId()]&lt;br /&gt;
: [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/mapreduce/apps/friends/core/Account.html#getFriendIds() getFriendIds()]&lt;br /&gt;
&lt;br /&gt;
==AccountId==&lt;br /&gt;
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/s20/apidocs/mapreduce/apps/friends/core/AccountId.html class AccountId]&lt;br /&gt;
&lt;br /&gt;
==SetIntersector&amp;lt;E&amp;gt;==&lt;br /&gt;
class [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html SetIntersector&amp;lt;E&amp;gt;]&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html#accept(java.util.Set) accept(friendIds)]&lt;br /&gt;
&lt;br /&gt;
: [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/fall22/apidocs/edu/wustl/cse231s/util/SetIntersector.html#currentIntersection() currentIntersection()]&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
==MutualFriendsMapper==&lt;br /&gt;
{{CodeToImplement|MutualFriendsMapper|map|mapreduce.apps.friends.exercise}}&lt;br /&gt;
{{Sequential|public void map(Account account, BiConsumer&amp;lt;OrderedPair&amp;lt;AccountId&amp;gt;, Set&amp;lt;AccountId&amp;gt;&amp;gt; keyValuePairConsumer)}}&lt;br /&gt;
&lt;br /&gt;
The only method you will need to alter is the map method. In this method, you will need to map every combination of the account holder to their friends. In order to do this, create ordered pairs of the given account’s ID and the IDs of the account holder’s friends. For each ordered pair, you feed the pair along with the full set of IDs of the account holder's friends into the keyValuePairConsumer.&lt;br /&gt;
&lt;br /&gt;
Hint: check out the methods in the Account class for help.&lt;br /&gt;
&lt;br /&gt;
==MutualFriendsReducer==&lt;br /&gt;
{{CodeToImplement|MutualFriendsClassicReducer|reduce|mapreduce.apps.friends.exercise}}&lt;br /&gt;
{{Sequential|public Set&amp;lt;AccountId&amp;gt; reduce(List&amp;lt;Set&amp;lt;AccountId&amp;gt;&amp;gt; container)}}&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/mapreduce/apps/friends/core/SetIntersector.html SetIntersector] can be used to calculate the set intersection.  Invoke &amp;lt;code&amp;gt;accept(set)&amp;lt;/code&amp;gt; for each set in the &amp;lt;container&amp;gt; parameter, then invoke &amp;lt;code&amp;gt;currentIntersection()&amp;lt;/code&amp;gt; to get the result.&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_MutualFriendsTestSuite|mapreduce}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Card_Only_Sequential_Map_Reduce_Framework_Assignment&amp;diff=4698</id>
		<title>Card Only Sequential Map Reduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Card_Only_Sequential_Map_Reduce_Framework_Assignment&amp;diff=4698"/>
		<updated>2023-02-23T19:35:02Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: Undo revision 4697 by Mroitblat (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
Building a parallel MapReduce framework with five generic types can be challenging.  This warmup takes the [[Bottleneck_MapReduce_Framework_Assignment|bottlenecked]] approach to MapReduce, but sequentially and with specific types- the ones from the [[MapReduce_Mapper_Assignment#CardMapper|Card Counting application]].  We will later build a [[#Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|parallel framework with specific types]], followed by a [[Bottleneck_MapReduce_Framework_Assignment|parallel generic framework]].&lt;br /&gt;
&lt;br /&gt;
=Java Utilities=&lt;br /&gt;
{{ListDoc}}, implementations: {{ArrayListDoc}}, {{LinkedListDoc}}&lt;br /&gt;
: {{ListAddLink}}&lt;br /&gt;
&lt;br /&gt;
{{MapLink}}, implementations: {{HashMapLink}}, {{EnumMapLink}}&lt;br /&gt;
: {{MapComputeIfAbsentLink}}&lt;br /&gt;
: {{MapEntrySetLink}}&lt;br /&gt;
&lt;br /&gt;
=Building On Previous Exercises=&lt;br /&gt;
Be sure to complete the [[Int_Sum_MapReduce_Apps_Studio#Card_Mapper|Card Mapper]] and [[Int_Sum_MapReduce_Apps_Studio#IntSumListAccumulatingReducer|Summing Int Classic Reducer]] exercises first.&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==CardOnlySequentialMapReduceFramework==&lt;br /&gt;
You will build each of the three methods mapReduceAll(input) invokes.  Much can be gleaned from the parameters and return values of these methods.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|mapReduceAll(Deck[] input)|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Override&lt;br /&gt;
public java.util.Map&amp;lt;Suit, Integer&amp;gt; mapReduceAll(Deck[] input) {&lt;br /&gt;
	List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAllResult = mapAll(input);&lt;br /&gt;
	Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAllResult = accumulateAll(mapAllResult);&lt;br /&gt;
	return reduceAll(accumulateAllResult);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
==CardOnlySequentialMapReduceFramework==&lt;br /&gt;
{{CodeToImplement|CardOnlySequentialMapReduceFramework|mapper&amp;lt;br/&amp;gt;accumulatorCombinerReducer&amp;lt;br/&amp;gt;mapAll&amp;lt;br/&amp;gt;accumulateAll&amp;lt;br/&amp;gt;reduceAll|mapreduce.framework.sequential.group}}&lt;br /&gt;
&lt;br /&gt;
===mapper===&lt;br /&gt;
{{Sequential|public Mapper&amp;lt;Deck, Suit, Integer&amp;gt; mapper()}}&lt;br /&gt;
&lt;br /&gt;
This method exists to remind you to use the mapper.  The type is a perfect match for the CardMapper:&lt;br /&gt;
&lt;br /&gt;
===accumulatorCombinerReducer===&lt;br /&gt;
{{Sequential|public Reducer&amp;lt;Integer, List&amp;lt;Integer&amp;gt;, Integer&amp;gt; reducer()}}&lt;br /&gt;
&lt;br /&gt;
This method exists to remind you to use the accumulatorCombinerReducer.  The type is a perfect match for the SummingIntClassicReducer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public abstract class ClassicReducer&amp;lt;V, R&amp;gt; implements AccumulatorCombinerReducer&amp;lt;V, List&amp;lt;V&amp;gt;, R&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SummingIntClassicReducer extends ClassicReducer&amp;lt;Integer, Integer&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
{{Sequential|private List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAll(Deck[] input)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the mapper's map method}}&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAll(List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAllResults)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the accumulatorCombinerReducer's createMutableContainer and accumulate methods}}&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
{{Sequential|private Map&amp;lt;Suit, Integer&amp;gt; reduceAll(Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAllResult)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the accumulatorCombinerReducer's reduce method}}&lt;br /&gt;
&lt;br /&gt;
=Client=&lt;br /&gt;
{{Client|CardOnlySequentialMapReduceFrameworkClient|mapreduce.framework.sequential.client|main}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|CardOnlySequentialMapReduceFrameworkClient|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Deck[] decks = new Deck[] {&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
};&lt;br /&gt;
MapReduceFramework&amp;lt;Deck, Suit, Integer, List&amp;lt;Integer&amp;gt;, Integer&amp;gt; framework = new CardOnlySequentialMapReduceFramework(&lt;br /&gt;
		new CardMapper(), new SummingIntClassicReducer());&lt;br /&gt;
Map&amp;lt;Suit, Integer&amp;gt; map = framework.mapReduceAll(decks);&lt;br /&gt;
for (Entry&amp;lt;Suit, Integer&amp;gt; entry : map.entrySet()) {&lt;br /&gt;
	System.out.println(entry);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|CardOnlySequentialMapReduceFrameworkClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;DIAMONDS=216&lt;br /&gt;
SPADES=216&lt;br /&gt;
CLUBS=216&lt;br /&gt;
HEARTS=216&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|_CardOnlySequentialMapReduceFrameworkTestSuite|mapreduce.framework.sequential.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Card_Only_Sequential_Map_Reduce_Framework_Assignment&amp;diff=4697</id>
		<title>Card Only Sequential Map Reduce Framework Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Card_Only_Sequential_Map_Reduce_Framework_Assignment&amp;diff=4697"/>
		<updated>2023-02-23T19:00:36Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
Building a parallel MapReduce framework with five generic types can be challenging.  This warmup takes the [[Bottleneck_MapReduce_Framework_Assignment|bottlenecked]] approach to MapReduce, but sequentially and with specific types- the ones from the [[MapReduce_Mapper_Assignment#CardMapper|Card Counting application]].  We will later build a [[#Word_Count_Only_Parallel_Map_Reduce_Framework_Assignment|parallel framework with specific types]], followed by a [[Bottleneck_MapReduce_Framework_Assignment|parallel generic framework]].&lt;br /&gt;
&lt;br /&gt;
=Java Utilities=&lt;br /&gt;
{{ListDoc}}, implementations: {{ArrayListDoc}}, {{LinkedListDoc}}&lt;br /&gt;
: {{ListAddLink}}&lt;br /&gt;
&lt;br /&gt;
{{MapLink}}, implementations: {{HashMapLink}}, {{EnumMapLink}}&lt;br /&gt;
: {{MapComputeIfAbsentLink}}&lt;br /&gt;
: {{MapEntrySetLink}}&lt;br /&gt;
&lt;br /&gt;
=Building On Previous Exercises=&lt;br /&gt;
Be sure to complete the [[Int_Sum_MapReduce_Apps_Studio#Card_Mapper|Card Mapper]] exercise first.&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==CardOnlySequentialMapReduceFramework==&lt;br /&gt;
You will build each of the three methods mapReduceAll(input) invokes.  Much can be gleaned from the parameters and return values of these methods.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|mapReduceAll(Deck[] input)|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
@Override&lt;br /&gt;
public java.util.Map&amp;lt;Suit, Integer&amp;gt; mapReduceAll(Deck[] input) {&lt;br /&gt;
	List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAllResult = mapAll(input);&lt;br /&gt;
	Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAllResult = accumulateAll(mapAllResult);&lt;br /&gt;
	return reduceAll(accumulateAllResult);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
==CardOnlySequentialMapReduceFramework==&lt;br /&gt;
{{CodeToImplement|CardOnlySequentialMapReduceFramework|mapper&amp;lt;br/&amp;gt;accumulatorCombinerReducer&amp;lt;br/&amp;gt;mapAll&amp;lt;br/&amp;gt;accumulateAll&amp;lt;br/&amp;gt;reduceAll|mapreduce.framework.sequential.group}}&lt;br /&gt;
&lt;br /&gt;
===mapper===&lt;br /&gt;
{{Sequential|public Mapper&amp;lt;Deck, Suit, Integer&amp;gt; mapper()}}&lt;br /&gt;
&lt;br /&gt;
This method exists to remind you to use the mapper.  The type is a perfect match for the CardMapper:&lt;br /&gt;
&lt;br /&gt;
===accumulatorCombinerReducer===&lt;br /&gt;
{{Sequential|public Reducer&amp;lt;Integer, List&amp;lt;Integer&amp;gt;, Integer&amp;gt; reducer()}}&lt;br /&gt;
&lt;br /&gt;
This method exists to remind you to use the accumulatorCombinerReducer.  The type is a perfect match for the SummingIntClassicReducer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public abstract class ClassicReducer&amp;lt;V, R&amp;gt; implements AccumulatorCombinerReducer&amp;lt;V, List&amp;lt;V&amp;gt;, R&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class SummingIntClassicReducer extends ClassicReducer&amp;lt;Integer, Integer&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===mapAll===&lt;br /&gt;
{{Sequential|private List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAll(Deck[] input)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the mapper's map method}}&lt;br /&gt;
&lt;br /&gt;
===accumulateAll===&lt;br /&gt;
&lt;br /&gt;
{{Sequential|private Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAll(List&amp;lt;List&amp;lt;Map.Entry&amp;lt;Suit, Integer&amp;gt;&amp;gt;&amp;gt; mapAllResults)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the accumulatorCombinerReducer's createMutableContainer and accumulate methods}}&lt;br /&gt;
&lt;br /&gt;
===reduceAll===&lt;br /&gt;
{{Sequential|private Map&amp;lt;Suit, Integer&amp;gt; reduceAll(Map&amp;lt;Suit, List&amp;lt;Integer&amp;gt;&amp;gt; accumulateAllResult)}}&lt;br /&gt;
&lt;br /&gt;
{{Requirement|Use the accumulatorCombinerReducer's reduce method}}&lt;br /&gt;
&lt;br /&gt;
=Client=&lt;br /&gt;
{{Client|CardOnlySequentialMapReduceFrameworkClient|mapreduce.framework.sequential.client|main}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|CardOnlySequentialMapReduceFrameworkClient|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
Deck[] decks = new Deck[] {&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
		Deck.createFull(),&lt;br /&gt;
};&lt;br /&gt;
MapReduceFramework&amp;lt;Deck, Suit, Integer, List&amp;lt;Integer&amp;gt;, Integer&amp;gt; framework = new CardOnlySequentialMapReduceFramework(&lt;br /&gt;
		new CardMapper(), new SummingIntClassicReducer());&lt;br /&gt;
Map&amp;lt;Suit, Integer&amp;gt; map = framework.mapReduceAll(decks);&lt;br /&gt;
for (Entry&amp;lt;Suit, Integer&amp;gt; entry : map.entrySet()) {&lt;br /&gt;
	System.out.println(entry);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|CardOnlySequentialMapReduceFrameworkClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;DIAMONDS=216&lt;br /&gt;
SPADES=216&lt;br /&gt;
CLUBS=216&lt;br /&gt;
HEARTS=216&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|_CardOnlySequentialMapReduceFrameworkTestSuite|mapreduce.framework.sequential.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Functions_Map_And_Reduce_Assignment&amp;diff=4600</id>
		<title>Higher-order Functions Map And Reduce Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Functions_Map_And_Reduce_Assignment&amp;diff=4600"/>
		<updated>2023-02-21T01:37:02Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Java=&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html interface Function&amp;lt;T,R&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
=Code to Investigate=&lt;br /&gt;
==VolleyballMapClient==&lt;br /&gt;
 &amp;lt;pre&amp;gt;List&amp;lt;Player&amp;gt; roster = VolleyballRoster.WASHU_2021.players();&lt;br /&gt;
List&amp;lt;Integer&amp;gt; heights = MapUtils.map((player) -&amp;gt; {&lt;br /&gt;
	return player.height();&lt;br /&gt;
}, roster);&lt;br /&gt;
heights.forEach((height) -&amp;gt; {&lt;br /&gt;
	System.out.println(height);&lt;br /&gt;
});&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Code to Implement=&lt;br /&gt;
==map==&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|MapUtils|map|hof.map.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|&amp;lt;T, R&amp;gt; List&amp;lt;R&amp;gt; map(Function&amp;lt;T, R&amp;gt; f, List&amp;lt;T&amp;gt; list))}}&lt;br /&gt;
&lt;br /&gt;
==clients==&lt;br /&gt;
{{CodeToImplement|MapClients|mapToLengths&amp;lt;br&amp;gt;mapToStrictlyLessThan|hof.map.exercise}}&lt;br /&gt;
&lt;br /&gt;
We created a couple of utility methods which invoke map with a custom lambda.&lt;br /&gt;
&lt;br /&gt;
===mapToLengths===&lt;br /&gt;
{{Sequential|List&amp;lt;Integer&amp;gt; mapToLengths(List&amp;lt;String&amp;gt; texts)}}&lt;br /&gt;
&lt;br /&gt;
===mapToStrictlyLessThan===&lt;br /&gt;
{{Sequential|List&amp;lt;Boolean&amp;gt; mapToStrictlyLessThan(List&amp;lt;Integer&amp;gt; xs, int threshold)}}&lt;br /&gt;
&lt;br /&gt;
=Test=&lt;br /&gt;
{{TestSuite|_MapTestSuite|hof.map.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Function_Filter_Assignment&amp;diff=4599</id>
		<title>Higher-order Function Filter Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Function_Filter_Assignment&amp;diff=4599"/>
		<updated>2023-02-21T01:20:19Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
In this studio you will be building the first ballot inductee to the [https://homes.cs.washington.edu/~djg/ Dan Grossman] [https://courses.cs.washington.edu/courses/cse341/13wi/videos/unit3/47_map_and_filter.mp4 Hall of Fame of Higher Order Functions]: filter.&lt;br /&gt;
&lt;br /&gt;
This studio will give us the opportunity to work with the standard [https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html Java for-each loop], [https://docs.oracle.com/javase/tutorial/java/generics/types.html generics], [https://docs.oracle.com/javase/tutorial/java/concepts/interface.html interfaces], and [https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html lambda expressions]. &lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt; we get to use the for each loop and invoke a method on a generic type interface.&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;filterEvens&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;filterWordsWhichContainAll5Vowels&amp;lt;/code&amp;gt; we get to invoke filter with lambda expressions.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html Java for-each loop]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/generics/types.html generics]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/concepts/interface.html interfaces]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html lambda expressions]&lt;br /&gt;
&lt;br /&gt;
=Mistakes To Avoid=&lt;br /&gt;
{{warning | In implementing filter, do NOT mutate the list passed in as a parameter.  Return a new list with the items which pass the predicate's test.}}&lt;br /&gt;
&lt;br /&gt;
{{warning | Do NOT re-implement the filter functionality in filterWordsWhichContainAllVowels and filterEvens.  Invoke the filter method you just wrote.}}&lt;br /&gt;
&lt;br /&gt;
=Code to Implement=&lt;br /&gt;
==filter==&lt;br /&gt;
{{CodeToImplement|FilterUtils|filter|hof.filter.group}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static &amp;lt;E&amp;gt; List&amp;lt;E&amp;gt; filter(Predicate&amp;lt;E&amp;gt; predicate, List&amp;lt;E&amp;gt; list)}}&lt;br /&gt;
&lt;br /&gt;
This classic high level function returns a list with the elements of list for which predicate's test method returns true. The predicate's test method is applied to each element in order.&lt;br /&gt;
&lt;br /&gt;
==clients==&lt;br /&gt;
{{CodeToImplement|FilterClients|filterEvens&amp;lt;br&amp;gt;filterWordsWhichContainAll5Vowels|hof.filter.group}}&lt;br /&gt;
&lt;br /&gt;
We created a couple of utility methods which invoke filter with a custom lambda.&lt;br /&gt;
&lt;br /&gt;
===filterWordsWhichContainAll5Vowels===&lt;br /&gt;
{{Sequential|public static List&amp;lt;String&amp;gt; filterWordsWhichContainAll5Vowels(List&amp;lt;String&amp;gt; words)}}&lt;br /&gt;
&lt;br /&gt;
[[File:Filter_contains_all_five_vowels.svg]]&lt;br /&gt;
&lt;br /&gt;
Useful method: [https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int- str.indexOf(ch)]&lt;br /&gt;
&lt;br /&gt;
===filterEvens===&lt;br /&gt;
{{Sequential|public static List&amp;lt;Integer&amp;gt; filterEvens(List&amp;lt;Integer&amp;gt; xs)}}&lt;br /&gt;
&lt;br /&gt;
[[File:Filter_is_even.svg]]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_FilterTestSuite|hof.filter.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Function_Filter_Assignment&amp;diff=4598</id>
		<title>Higher-order Function Filter Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Higher-order_Function_Filter_Assignment&amp;diff=4598"/>
		<updated>2023-02-21T01:14:23Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
In this studio you will be building the first ballot inductee to the [https://homes.cs.washington.edu/~djg/ Dan Grossman] [https://courses.cs.washington.edu/courses/cse341/13wi/videos/unit3/47_map_and_filter.mp4 Hall of Fame of Higher Order Functions]: filter.&lt;br /&gt;
&lt;br /&gt;
This studio will give us the opportunity to work with the standard [https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html Java for-each loop], [https://docs.oracle.com/javase/tutorial/java/generics/types.html generics], [https://docs.oracle.com/javase/tutorial/java/concepts/interface.html interfaces], and [https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html lambda expressions]. &lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt; we get to use the for each loop and invoke a method on a generic type interface.&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;filterEvens&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;filterWordsWhichContainAll5Vowels&amp;lt;/code&amp;gt; we get to invoke filter with lambda expressions.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
* [https://docs.oracle.com/javase/8/docs/technotes/guides/language/foreach.html Java for-each loop]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/generics/types.html generics]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/concepts/interface.html interfaces]&lt;br /&gt;
* [https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html lambda expressions]&lt;br /&gt;
&lt;br /&gt;
=Mistakes To Avoid=&lt;br /&gt;
{{warning | In implementing filter, do NOT mutate the list passed in as a parameter.  Return a new list with the items which pass the predicate's test.}}&lt;br /&gt;
&lt;br /&gt;
{{warning | Do NOT re-implement the filter functionality in filterWordsWhichContainAllVowels and filterEvens.  Invoke the filter method you just wrote.}}&lt;br /&gt;
&lt;br /&gt;
=Code to Implement=&lt;br /&gt;
==filter==&lt;br /&gt;
{{CodeToImplement|FilterUtils|filter|hof.filter.group}}&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static &amp;lt;E&amp;gt; List&amp;lt;E&amp;gt; filter(Predicate&amp;lt;E&amp;gt; predicate, List&amp;lt;E&amp;gt; list)}}&lt;br /&gt;
&lt;br /&gt;
This classic high level function returns a list with the elements of list for which predicate's test method returns true. The predicate's test method is applied to each element in order.&lt;br /&gt;
&lt;br /&gt;
==clients==&lt;br /&gt;
{{CodeToImplement|FilterClients|filterEvens&amp;lt;br&amp;gt;filterWordsWhichContainAll5Vowels|hof.filter.group}}&lt;br /&gt;
&lt;br /&gt;
We created a couple of utility methods which invoke filter with a custom lambda.&lt;br /&gt;
&lt;br /&gt;
===filterEvens===&lt;br /&gt;
[[File:Filter_is_even.svg]]&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static List&amp;lt;Integer&amp;gt; filterEvens(List&amp;lt;Integer&amp;gt; xs)}}&lt;br /&gt;
&lt;br /&gt;
===filterWordsWhichContainAll5Vowels===&lt;br /&gt;
[[File:Filter_contains_all_five_vowels.svg]]&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public static List&amp;lt;String&amp;gt; filterWordsWhichContainAll5Vowels(List&amp;lt;String&amp;gt; words)}}&lt;br /&gt;
&lt;br /&gt;
Useful method: [https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int- str.indexOf(ch)]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_FilterTestSuite|hof.filter.group}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Not_Thread_Safe_Hash_Table_Assignment&amp;diff=4597</id>
		<title>Not Thread Safe Hash Table Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Not_Thread_Safe_Hash_Table_Assignment&amp;diff=4597"/>
		<updated>2023-02-21T01:11:12Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
We gain experience implementing an abstract data type.  Specifically, we will build a {{NotThreadSafeLink}} class which implements the java.util.Map&amp;lt;K,V&amp;gt; interface.  Later in the semester, we will implement a {{ThreadSafeLink}} version: [[Concurrent_Hash_Table_Assignment|ConcurrentHashTable]].&lt;br /&gt;
&lt;br /&gt;
We gain experience with generics since the Map interface is parameterized with multiple generic types: K for the key type and V for the value type.&lt;br /&gt;
&lt;br /&gt;
We will build some utilities to support hashing and key-value pairs which we will use throughout the semester.&lt;br /&gt;
&lt;br /&gt;
Finally, the selection of methods we will implement includes two which you may not be familiar with: compute() and computeIfAbsent().  Each of these methods have special roles to play throughout the semester.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
== Hash Tables==&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Hash_table Wikipedia Hash Table]&lt;br /&gt;
* [https://visualgo.net/en/hashtable VisuAlgo Hash Table]&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|How To Use java.util.Map|&amp;lt;youtube&amp;gt;MwPrMAG4bLg&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|CS50 Shorts: Hash Tables|&amp;lt;youtube&amp;gt;nvzVHwrrub0&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleYouTube|HackerRank Hash Tables|&amp;lt;youtube&amp;gt;shs0KM3wKv8&amp;lt;/youtube&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==Java Utilities To Use==&lt;br /&gt;
===Map.Entry&amp;lt;K,V&amp;gt;===&lt;br /&gt;
{{MapEntryWithMethodLinks}}&lt;br /&gt;
===Map&amp;lt;K,V&amp;gt;===&lt;br /&gt;
{{MapWithMethodLinks}}&lt;br /&gt;
===Optional&amp;lt;T&amp;gt;===&lt;br /&gt;
{{OptionalWithMethodsLinks}}&lt;br /&gt;
===ToIntFunction&amp;lt;T&amp;gt;===&lt;br /&gt;
{{ToIntFunctionWithMethodLinks}}&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
Each of the example clients operate on the words of the [https://rmc.library.cornell.edu/gettysburg/good_cause/transcript.htm Gettysburg Address].&lt;br /&gt;
&lt;br /&gt;
==PutClient==&lt;br /&gt;
{{Client|PutClient|hashtable.notthreadsafe.client|main}}&lt;br /&gt;
&lt;br /&gt;
This client uses repeated calls to {{MapPutLink}}.&lt;br /&gt;
&lt;br /&gt;
Each word is processed by taking its first letter (converted to lower case) and associating that letter with the word.  Since put replaces a previous association, if it exists, the last word starting with a particular letter wins.&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|PutClient|&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
int chainCount = 8;&lt;br /&gt;
Map&amp;lt;Character, String&amp;gt; mapFirstCharacterToLastEncounteredWord = new NotThreadSafeHashTable&amp;lt;&amp;gt;(chainCount, Objects::hashCode);&lt;br /&gt;
&lt;br /&gt;
for (TextSection textSection : TextSectionResource.GETTYSBURG_ADDRESS.textSections()) {&lt;br /&gt;
    for (String word : textSection.words()) {&lt;br /&gt;
        if (word.length() &amp;gt; 0) {&lt;br /&gt;
            char firstCharacterLowerCased = Character.toLowerCase(word.charAt(0));&lt;br /&gt;
            mapFirstCharacterToLastEncounteredWord.put(firstCharacterLowerCased, word);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
for (char ch = 'a'; ch &amp;lt;= 'z'; ++ch) {&lt;br /&gt;
    String value = mapFirstCharacterToLastEncounteredWord.get(ch);&lt;br /&gt;
    System.out.println(ch + &amp;quot;: &amp;quot; + toString(value));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|PutClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;a: and&lt;br /&gt;
b: by&lt;br /&gt;
c: cause&lt;br /&gt;
d: died&lt;br /&gt;
e: earth&lt;br /&gt;
f: from&lt;br /&gt;
g: government&lt;br /&gt;
h: have&lt;br /&gt;
i: in&lt;br /&gt;
j: &lt;br /&gt;
k: &lt;br /&gt;
l: last&lt;br /&gt;
m: measure&lt;br /&gt;
n: not&lt;br /&gt;
o: of&lt;br /&gt;
p: perish&lt;br /&gt;
q: &lt;br /&gt;
r: resolve&lt;br /&gt;
s: shall&lt;br /&gt;
t: the&lt;br /&gt;
u: under&lt;br /&gt;
v: vain&lt;br /&gt;
w: we&lt;br /&gt;
x: &lt;br /&gt;
y: years&lt;br /&gt;
z: &amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==ComputeIfAbsentClient==&lt;br /&gt;
{{Client|ComputeIfAbsentClient|hashtable.notthreadsafe.client|main}}&lt;br /&gt;
This client uses repeated calls to {{MapComputeIfAbsentLink}}. &lt;br /&gt;
&lt;br /&gt;
Each word is processed by taking its first letter (converted to lower case) and associating that letter with a list.  The first time a letter is encountered the mappingFunction will be invoked which returns the new list to associate with the letter.  Conveniently, whether it has been associated before or the current iteration, the List associated with the letter is returned from computeIfAbsent.  The current word is then added to that list.  Since the returned list is a reference to mutable data there is no need to re-associate the list with the letter.  When the loops are completed, each letter holds a list of all the encountered words (including any duplicates). &lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|ComputeIfAbsentClient|&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
int chainCount = 8;&lt;br /&gt;
Map&amp;lt;Character, List&amp;lt;String&amp;gt;&amp;gt; mapFirstCharacterToListOfWords = new NotThreadSafeHashTable&amp;lt;&amp;gt;(chainCount, Objects::hashCode);&lt;br /&gt;
&lt;br /&gt;
for (TextSection textSection : TextSectionResource.GETTYSBURG_ADDRESS.textSections()) {&lt;br /&gt;
    for (String word : textSection.words()) {&lt;br /&gt;
        if (word.length() &amp;gt; 0) {&lt;br /&gt;
            char firstCharacterLowerCased = Character.toLowerCase(word.charAt(0));&lt;br /&gt;
            List&amp;lt;String&amp;gt; list = mapFirstCharacterToListOfWords.computeIfAbsent(firstCharacterLowerCased,&lt;br /&gt;
                    (unusedKey) -&amp;gt; {&lt;br /&gt;
                        return new LinkedList&amp;lt;&amp;gt;();&lt;br /&gt;
                    });&lt;br /&gt;
            list.add(word);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
for (char ch = 'a'; ch &amp;lt;= 'z'; ++ch) {&lt;br /&gt;
    List&amp;lt;String&amp;gt; value = mapFirstCharacterToListOfWords.get(ch);&lt;br /&gt;
    System.out.println(ch + &amp;quot;: &amp;quot; + toString(value));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|ComputeIfAbsentClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;a: [and, ago, a, and, all, are, are, a, any, and, are, a, a, as, a, altogether, and, a, and, above, add, advanced, a, and]&lt;br /&gt;
b: [brought, battle, But, brave, but, be, be, before, birth, by]&lt;br /&gt;
c: [continent, conceived, created, civil, conceived, can, come, can, can, consecrate, can, consecrated, can, cause]&lt;br /&gt;
d: [dedicated, dedicated, dedicate, do, dedicate, dead, detract, did, dedicated, dedicated, dead, devotion, devotion, dead, died]&lt;br /&gt;
e: [equal, engaged, endure, earth]&lt;br /&gt;
f: [Four, fathers, forth, field, field, final, for, fitting, far, forget, for, fought, far, for, from, for, full, freedom, for, from]&lt;br /&gt;
g: [great, great, gave, ground, great, gave, God, government]&lt;br /&gt;
h: [have, here, hallow, here, have, here, here, here, here, have, here, honored, here, highly, have, have]&lt;br /&gt;
i: [in, in, It, is, in, it, it, It, is, It, is, increased, in]&lt;br /&gt;
j: &lt;br /&gt;
k: &lt;br /&gt;
l: [Liberty, long, lives, live, larger, living, little, long, living, last]&lt;br /&gt;
m: [men, met, might, men, measure]&lt;br /&gt;
n: [new, nation, Now, nation, nation, nation, not, not, not, note, nor, never, nobly, not, nation, new, not]&lt;br /&gt;
o: [our, on, or, on, of, of, our, or, of, of, of]&lt;br /&gt;
p: [proposition, portion, place, proper, poor, power, people, people, people, perish]&lt;br /&gt;
q: &lt;br /&gt;
r: [resting, remember, rather, rather, remaining, resolve]&lt;br /&gt;
s: [score, seven, so, so, should, sense, struggled, say, so, shall, shall, shall]&lt;br /&gt;
t: [this, to, the, that, testing, that, that, to, that, those, their, that, that, that, this, this, The, to, The, they, the, to, to, the, they, thus, to, to, the, task, that, these, take, to, that, they, the, that, that, these, that, this, that, the, the, the, the]&lt;br /&gt;
u: [us, unfinished, us, us, under]&lt;br /&gt;
v: [vain]&lt;br /&gt;
w: [we, war, whether, We, war, We, who, we, we, we, we, who, world, will, what, we, what, work, which, who, we, which, we]&lt;br /&gt;
x: &lt;br /&gt;
y: [years]&lt;br /&gt;
z: &amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==ComputeClient==&lt;br /&gt;
{{Client|ComputeClient|hashtable.notthreadsafe.client|main}}&lt;br /&gt;
&lt;br /&gt;
This client uses repeated calls to {{MapComputeLink}}. &lt;br /&gt;
&lt;br /&gt;
Each word is processed by computing the number of times the (lower case version of the) word has been encountered.  Each time compute is called the remappingFunction is passed the key (which is (as is often the case) unused) and the previous value associated with the key, or null if has no association.  The remapping function returns the value to associate with the key.  Since we are counting the occurrences, we add 1 to the previous value, or simply return 1 if that previous value is null.&lt;br /&gt;
&lt;br /&gt;
When the loops are completed, each word holds the number of times it was encountered.. &lt;br /&gt;
&lt;br /&gt;
{{CollapsibleCode|ComputeClient|&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
int chainCount = 8;&lt;br /&gt;
Map&amp;lt;String, Integer&amp;gt; mapWordToCount = new NotThreadSafeHashTable&amp;lt;&amp;gt;(chainCount, Objects::hashCode);&lt;br /&gt;
&lt;br /&gt;
for (TextSection textSection : TextSectionResource.GETTYSBURG_ADDRESS.textSections()) {&lt;br /&gt;
	for(String word : textSection.words()) {&lt;br /&gt;
		if (word.length() &amp;gt; 0) {&lt;br /&gt;
			String lowerCaseWord = word.toLowerCase();&lt;br /&gt;
			mapWordToCount.compute(lowerCaseWord, (unusedKey, prevValue) -&amp;gt; {&lt;br /&gt;
				if (prevValue != null) {&lt;br /&gt;
					return prevValue + 1;&lt;br /&gt;
				} else {&lt;br /&gt;
					return 1;&lt;br /&gt;
				}&lt;br /&gt;
			});&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
System.out.println(toString(mapWordToCount));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CollapsibleConsole|ComputeClient Output|&amp;lt;pre style=&amp;quot;border: 0px; background: #000; color:#fff;&amp;quot;&amp;gt;that =&amp;gt; 13&lt;br /&gt;
the =&amp;gt; 11&lt;br /&gt;
we =&amp;gt; 10&lt;br /&gt;
here =&amp;gt; 8&lt;br /&gt;
to =&amp;gt; 8&lt;br /&gt;
a =&amp;gt; 7&lt;br /&gt;
and =&amp;gt; 6&lt;br /&gt;
can =&amp;gt; 5&lt;br /&gt;
have =&amp;gt; 5&lt;br /&gt;
for =&amp;gt; 5&lt;br /&gt;
it =&amp;gt; 5&lt;br /&gt;
not =&amp;gt; 5&lt;br /&gt;
nation =&amp;gt; 5&lt;br /&gt;
of =&amp;gt; 5&lt;br /&gt;
in =&amp;gt; 4&lt;br /&gt;
this =&amp;gt; 4&lt;br /&gt;
dedicated =&amp;gt; 4&lt;br /&gt;
they =&amp;gt; 3&lt;br /&gt;
is =&amp;gt; 3&lt;br /&gt;
are =&amp;gt; 3&lt;br /&gt;
so =&amp;gt; 3&lt;br /&gt;
dead =&amp;gt; 3&lt;br /&gt;
shall =&amp;gt; 3&lt;br /&gt;
great =&amp;gt; 3&lt;br /&gt;
who =&amp;gt; 3&lt;br /&gt;
us =&amp;gt; 3&lt;br /&gt;
people =&amp;gt; 3&lt;br /&gt;
new =&amp;gt; 2&lt;br /&gt;
conceived =&amp;gt; 2&lt;br /&gt;
war =&amp;gt; 2&lt;br /&gt;
rather =&amp;gt; 2&lt;br /&gt;
gave =&amp;gt; 2&lt;br /&gt;
but =&amp;gt; 2&lt;br /&gt;
living =&amp;gt; 2&lt;br /&gt;
field =&amp;gt; 2&lt;br /&gt;
from =&amp;gt; 2&lt;br /&gt;
or =&amp;gt; 2&lt;br /&gt;
be =&amp;gt; 2&lt;br /&gt;
these =&amp;gt; 2&lt;br /&gt;
our =&amp;gt; 2&lt;br /&gt;
long =&amp;gt; 2&lt;br /&gt;
what =&amp;gt; 2&lt;br /&gt;
dedicate =&amp;gt; 2&lt;br /&gt;
which =&amp;gt; 2&lt;br /&gt;
men =&amp;gt; 2&lt;br /&gt;
devotion =&amp;gt; 2&lt;br /&gt;
on =&amp;gt; 2&lt;br /&gt;
far =&amp;gt; 2&lt;br /&gt;
created =&amp;gt; 1&lt;br /&gt;
testing =&amp;gt; 1&lt;br /&gt;
battle =&amp;gt; 1&lt;br /&gt;
proper =&amp;gt; 1&lt;br /&gt;
brave =&amp;gt; 1&lt;br /&gt;
vain =&amp;gt; 1&lt;br /&gt;
under =&amp;gt; 1&lt;br /&gt;
ago =&amp;gt; 1&lt;br /&gt;
all =&amp;gt; 1&lt;br /&gt;
hallow =&amp;gt; 1&lt;br /&gt;
add =&amp;gt; 1&lt;br /&gt;
nor =&amp;gt; 1&lt;br /&gt;
work =&amp;gt; 1&lt;br /&gt;
honored =&amp;gt; 1&lt;br /&gt;
cause =&amp;gt; 1&lt;br /&gt;
government =&amp;gt; 1&lt;br /&gt;
perish =&amp;gt; 1&lt;br /&gt;
score =&amp;gt; 1&lt;br /&gt;
as =&amp;gt; 1&lt;br /&gt;
their =&amp;gt; 1&lt;br /&gt;
poor =&amp;gt; 1&lt;br /&gt;
world =&amp;gt; 1&lt;br /&gt;
will =&amp;gt; 1&lt;br /&gt;
note =&amp;gt; 1&lt;br /&gt;
thus =&amp;gt; 1&lt;br /&gt;
advanced =&amp;gt; 1&lt;br /&gt;
increased =&amp;gt; 1&lt;br /&gt;
earth =&amp;gt; 1&lt;br /&gt;
engaged =&amp;gt; 1&lt;br /&gt;
civil =&amp;gt; 1&lt;br /&gt;
should =&amp;gt; 1&lt;br /&gt;
do =&amp;gt; 1&lt;br /&gt;
detract =&amp;gt; 1&lt;br /&gt;
say =&amp;gt; 1&lt;br /&gt;
unfinished =&amp;gt; 1&lt;br /&gt;
continent =&amp;gt; 1&lt;br /&gt;
equal =&amp;gt; 1&lt;br /&gt;
any =&amp;gt; 1&lt;br /&gt;
met =&amp;gt; 1&lt;br /&gt;
come =&amp;gt; 1&lt;br /&gt;
live =&amp;gt; 1&lt;br /&gt;
never =&amp;gt; 1&lt;br /&gt;
resolve =&amp;gt; 1&lt;br /&gt;
died =&amp;gt; 1&lt;br /&gt;
god =&amp;gt; 1&lt;br /&gt;
seven =&amp;gt; 1&lt;br /&gt;
brought =&amp;gt; 1&lt;br /&gt;
forth =&amp;gt; 1&lt;br /&gt;
whether =&amp;gt; 1&lt;br /&gt;
endure =&amp;gt; 1&lt;br /&gt;
those =&amp;gt; 1&lt;br /&gt;
altogether =&amp;gt; 1&lt;br /&gt;
consecrated =&amp;gt; 1&lt;br /&gt;
above =&amp;gt; 1&lt;br /&gt;
power =&amp;gt; 1&lt;br /&gt;
remember =&amp;gt; 1&lt;br /&gt;
forget =&amp;gt; 1&lt;br /&gt;
task =&amp;gt; 1&lt;br /&gt;
four =&amp;gt; 1&lt;br /&gt;
years =&amp;gt; 1&lt;br /&gt;
proposition =&amp;gt; 1&lt;br /&gt;
now =&amp;gt; 1&lt;br /&gt;
final =&amp;gt; 1&lt;br /&gt;
resting =&amp;gt; 1&lt;br /&gt;
sense =&amp;gt; 1&lt;br /&gt;
little =&amp;gt; 1&lt;br /&gt;
nobly =&amp;gt; 1&lt;br /&gt;
remaining =&amp;gt; 1&lt;br /&gt;
last =&amp;gt; 1&lt;br /&gt;
measure =&amp;gt; 1&lt;br /&gt;
freedom =&amp;gt; 1&lt;br /&gt;
fathers =&amp;gt; 1&lt;br /&gt;
liberty =&amp;gt; 1&lt;br /&gt;
portion =&amp;gt; 1&lt;br /&gt;
place =&amp;gt; 1&lt;br /&gt;
lives =&amp;gt; 1&lt;br /&gt;
might =&amp;gt; 1&lt;br /&gt;
fitting =&amp;gt; 1&lt;br /&gt;
larger =&amp;gt; 1&lt;br /&gt;
consecrate =&amp;gt; 1&lt;br /&gt;
ground =&amp;gt; 1&lt;br /&gt;
struggled =&amp;gt; 1&lt;br /&gt;
did =&amp;gt; 1&lt;br /&gt;
fought =&amp;gt; 1&lt;br /&gt;
before =&amp;gt; 1&lt;br /&gt;
take =&amp;gt; 1&lt;br /&gt;
full =&amp;gt; 1&lt;br /&gt;
highly =&amp;gt; 1&lt;br /&gt;
birth =&amp;gt; 1&lt;br /&gt;
by =&amp;gt; 1 &amp;lt;/pre&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=Code to Implement=&lt;br /&gt;
{{ Tip | It is good practice to declare variables, parameters, and fields to be of the least specific type possible (but no less specific :). This is commonly an interface. }}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Do NOT use &amp;lt;nowiki&amp;gt;==&amp;lt;/nowiki&amp;gt; when comparing Objects (except when comparing to null).  Use [https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#equals-java.lang.Object-java.lang.Object- Objects.equals(a,b)]. }}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Do NOT use % which can return a negative number.  Use [https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorMod-int-int- Math.floorMod(x,y)]. }}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Do NOT parallelize. }}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Do NOT simply remove and add for put on a Map.  Look for the entry and set its value if you find it.  Otherwise add it. }}&lt;br /&gt;
&lt;br /&gt;
==DefaultHashFunction==&lt;br /&gt;
{{CodeToImplement|DefaultHashFunction|applyAsInt|hash.exercise}}&lt;br /&gt;
&lt;br /&gt;
Hashing is a powerful tool.  We will use it to build our NotThreadSafeHashTable, as well as the [[Matrix_MapReduce_Framework_Assignment|MatrixMapReduceFramework]] later in the semester.  Hashing relies on evenly distributing keys to provide performance improvements.  As such, it will be useful to specify a particular hash function for our Hash Table (and MatrixMapReduceFramework later) as they will want to be different.&lt;br /&gt;
&lt;br /&gt;
Here we create a default hash function which implements {{ToIntFunctionLink}} which can serve as the hash function for our NotThreadSafeHashTable or wherever we need one.&lt;br /&gt;
&lt;br /&gt;
We will just use the standard mechanism for acquiring a hashCode for an Object.  Investigate [[SmearHashFunction|SmearHashFunction]] which [https://github.com/mraad/dbscan-spark/blob/master/src/main/java/com/esri/dbscan/Smear.java smears] the hash code to provide a different result.&lt;br /&gt;
&lt;br /&gt;
===applyAsInt(key)===&lt;br /&gt;
{{Sequential|public int applyAsInt(K key)}}&lt;br /&gt;
&lt;br /&gt;
Return the result of calling [https://docs.oracle.com/javase/8/docs/api/java/util/Objects.html#hashCode-java.lang.Object- Objects.hashCode(key)] which nicely handles null.&lt;br /&gt;
&lt;br /&gt;
==HashUtils==&lt;br /&gt;
{{CodeToImplement|HashUtils|hashCodeOf&amp;lt;br/&amp;gt;arrayIndexForKey&amp;lt;br/&amp;gt;itemInArrayForKey|hash.exercise}}&lt;br /&gt;
&lt;br /&gt;
=== hashCodeOf(key, hashFunction) ===&lt;br /&gt;
{{Sequential|public static &amp;lt;K&amp;gt; int hashCodeOf(K key, ToIntFunction&amp;lt;K&amp;gt; hashFunction)}}&lt;br /&gt;
&lt;br /&gt;
Invoke the hashFunction's [https://docs.oracle.com/javase/8/docs/api/java/util/function/ToIntFunction.html#applyAsInt-T- applyAsInt(value)] method and return the result.&lt;br /&gt;
&lt;br /&gt;
=== arrayIndexForKey(key, arrayLength, hashFunction) ===&lt;br /&gt;
{{Sequential|public static &amp;lt;K&amp;gt; int arrayIndexForKey(K key, int arrayLength, ToIntFunction&amp;lt;K&amp;gt; hashFunction)}}&lt;br /&gt;
&lt;br /&gt;
Using [[Not_Thread_Safe_Hash_Table_Assignment#hashCodeOf.28key.2C_hashFunction.29|hashCodeOf]] with the provided key will return an int value between (inclusive) Integer.MIN_VALUE and Integer.MAX_VALUE, that is: between (inclusive) -2147483648 and 2147483647.&lt;br /&gt;
&lt;br /&gt;
To convert this to a suitable array index, we would like to take the positive remainder of the value and the arrayLength.&lt;br /&gt;
&lt;br /&gt;
Simply using the % operator will not do, as a negative hashCode would result in a negative array index (which would, of course, produce an array [https://docs.oracle.com/javase/8/docs/api/java/lang/IndexOutOfBoundsException.html IndexOutOfBoundsException]).&lt;br /&gt;
&lt;br /&gt;
Using [https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorMod-int-int- Math.floorMod(dividend,divisor)] solves this problem by always returning a remainder with the sign of the divisor.&lt;br /&gt;
&lt;br /&gt;
=== itemInArrayForKey(key, array, hashFunction) ===&lt;br /&gt;
{{Sequential|public static &amp;lt;K, E&amp;gt; E itemInArrayForKey(K key, E[] array, ToIntFunction&amp;lt;K&amp;gt; hashFunction)}}&lt;br /&gt;
&lt;br /&gt;
Leverage [[Not_Thread_Safe_Hash_Table_Assignment#arrayIndexForKey.28key.2C_arrayLength.2C_hashFunction.29|arrayIndexForKey]] to find the index in the array, then return the item at that index.&lt;br /&gt;
&lt;br /&gt;
==DefaultEntry&amp;lt;K,V&amp;gt;==&lt;br /&gt;
{{Warning | This is in student-pre-aspect!!!}} &lt;br /&gt;
Whatever language you happen to be programming in there will be a way to associate keys with values.  Whether the data structure is called a [https://docs.python.org/3/tutorial/datastructures.html#dictionaries Dictionary] in Python, a [https://ruby-doc.org/core-3.1.2/Hash.html Hash] in Ruby, an [https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node153.html Association List] in Lisp, or a [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map&amp;lt;K,V&amp;gt;] in Java, there will be a way to store the (key, value) pairs.&lt;br /&gt;
&lt;br /&gt;
Java provides the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.Entry.html interface Entry&amp;lt;K, V&amp;gt;] which is used on all of its Maps.  We will implement this interface in class DefaultEntry&amp;lt;K,V&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|DefaultEntry|constructor&amp;lt;br&amp;gt;getKey&amp;lt;br&amp;gt;getValue&amp;lt;br&amp;gt;setValue|entry.exercise|student-pre-aspect}}&lt;br /&gt;
&lt;br /&gt;
===constructor DefaultEntry(key, value)===&lt;br /&gt;
{{Sequential|public DefaultEntry(K key, V value)}}&lt;br /&gt;
&lt;br /&gt;
Hang onto the key and value specified as parameters in instance variables to be returned (and perhaps mutated in the case of value) later.&lt;br /&gt;
&lt;br /&gt;
===getKey()===&lt;br /&gt;
{{Sequential|public K getKey()}}&lt;br /&gt;
&lt;br /&gt;
{{MapEntryGetKeyLink}} specification&lt;br /&gt;
&lt;br /&gt;
===getValue()===&lt;br /&gt;
{{Sequential|public V getValue()}}&lt;br /&gt;
&lt;br /&gt;
{{MapEntryGetValueLink}} specification&lt;br /&gt;
&lt;br /&gt;
===setValue()===&lt;br /&gt;
{{Sequential|public V setValue(V value)}}&lt;br /&gt;
&lt;br /&gt;
{{MapEntrySetValueLink}} specification&lt;br /&gt;
&lt;br /&gt;
==NotThreadSafeHashTable==&lt;br /&gt;
NotThreadSafeHashTable will use an entry’s key to place an entry into one of several buckets.  Each bucket will hold a chain of entries.  We maintain a chain of entries for when collisions naturally occur when multiple keys want to be placed in the same bucket.&lt;br /&gt;
&lt;br /&gt;
HashTables are a popular data structure because we can cut down the runtime of searching for entries within the map by adding more buckets/chains.  The time required to search for a particular entry drops to roughly 1/total_number_of_buckets (in comparison to one long chain which contains every entry).&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Hash_table hash table on wikipedia]&lt;br /&gt;
&lt;br /&gt;
[[File:Hash_table_5_0_1_1_1_1_1_LL.svg|frame|[https://commons.wikimedia.org/wiki/File:Hash_table_5_0_1_1_1_1_1_LL.svg mediawiki hash table image]]]&lt;br /&gt;
&lt;br /&gt;
In this class, you will use the entry’s key’s hashcode to determine which of the buckets it should fall into. In order to calculate the index of the bucket that the entry belongs in, we will make use of the hash function, which in turn uses Math.floorMod to calculate a modulo (remainder or % in Java) based on the number of buckets and the key’s hashcode. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
A Map (also sometimes referred to as a Dictionary or a Hashtable) is an abstract data structure which has the capabilities of associating a value with a key: &amp;lt;code&amp;gt;map.put(key, value)&amp;lt;/code&amp;gt;, looking up the associated value with a key: &amp;lt;code&amp;gt;map.get(key)&amp;lt;/code&amp;gt;, and removing &amp;lt;code&amp;gt;map.remove(key)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The standard Java Collections Framework [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map] provides a number of other nice methods, but put, get, and remove are the core of any Map in any programming language.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since your class will implement Map&amp;lt;K,V&amp;gt;.  We will leave many of the methods as &amp;lt;code&amp;gt;throw new NotRequiredForTheAssignmentException();&amp;lt;/code&amp;gt; while we focus on some critical methods of import. Specifications for these methods can be found in the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html Map&amp;lt;K,V&amp;gt; javadocs]&lt;br /&gt;
&lt;br /&gt;
{{Warning | Note the specifications of the return values.}}&lt;br /&gt;
&lt;br /&gt;
Further, the standard interface for a key value pair is [https://docs.oracle.com/javase/8/docs/api/java/util/Map.Entry.html Map's Entry] with the critical methods:&lt;br /&gt;
&lt;br /&gt;
* K getKey()&lt;br /&gt;
* V getValue()&lt;br /&gt;
* V setValue(V value)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
We have provided an implementation of Entry for you called [https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/util/KeyMutableValuePair.html KeyMutableValuePair&amp;lt;K,V&amp;gt;].&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|NotThreadSafeHashTable|constructor&amp;lt;br/&amp;gt;hashFunction&amp;lt;br/&amp;gt;chains&amp;lt;br/&amp;gt;entryOf&amp;lt;br/&amp;gt;put&amp;lt;br/&amp;gt;get&amp;lt;br/&amp;gt;computeIfAbsent&amp;lt;br/&amp;gt;compute|NotThreadSafeHashTable.notthreadsafe.exercise}}&lt;br /&gt;
&lt;br /&gt;
===constructor: NotThreadSafeHashTable(chainCount, hashFunction)===&lt;br /&gt;
{{Sequential|public NotThreadSafeHashTable(int chainCount, ToIntFunction&amp;lt;K&amp;gt; hashFunction)}}&lt;br /&gt;
&lt;br /&gt;
Initialize &amp;lt;code&amp;gt;chainCount&amp;lt;/code&amp;gt; chains in the form of an array of Collections of entries.  Additionally, hang onto the &amp;lt;code&amp;gt;hashFunction&amp;lt;/code&amp;gt; for later use.&lt;br /&gt;
&lt;br /&gt;
{{Requirement | In order to facilitate testing and debugging, create instances of either [https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/ArrayList.html java.util.ArrayList] or [https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/LinkedList.html java.util.LinkedList] to fill your array with.}}&lt;br /&gt;
&lt;br /&gt;
{{Warning | Initializing the contents of an array is one of the few cases where the indexing for loop is superior to the for-each loop.}}&lt;br /&gt;
&lt;br /&gt;
Use: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;for (int i = 0; i &amp;lt; buckets.length; ++i)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
in this case.&lt;br /&gt;
&lt;br /&gt;
Implementing the constructor has a couple of tricky parts.&lt;br /&gt;
&lt;br /&gt;
====Parameterized Type Array Tip====&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Creating arrays of parameterized types in Java is madness inducing.  Some details are available in [https://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays Java Generics Restrictions].&lt;br /&gt;
&lt;br /&gt;
The example below creates an array of List&amp;lt;String&amp;gt;.  The &amp;lt;code&amp;gt;@SuppressWarnings&amp;lt;/code&amp;gt; annotation is optional.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;@SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
List&amp;lt;String&amp;gt;[] result = new List[length];&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First, you will encounter a much dreaded problem in Java.  One cannot instantiate a new generic array.  While there is [https://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays a reason for this limitation], it is still frustrating.&lt;br /&gt;
&lt;br /&gt;
So while you might think you should enter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
buckets = new Collection&amp;lt;Entry&amp;lt;K, V&amp;gt;&amp;gt;[capacity]; // NOTE: this will not compile&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the error reported says it all &amp;quot;Cannot create a generic array of Collection&amp;lt;Map.Entry&amp;lt;K,V&amp;gt;&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
You must instead create the array without the generic type parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
buckets = new Collection[capacity];&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This results in a warning which the @SuppressWarnings(&amp;quot;unchecked&amp;quot;) annotation we added to the constructor takes care of.&lt;br /&gt;
&lt;br /&gt;
===hashFunction()===&lt;br /&gt;
{{Sequential|public ToIntFunction&amp;lt;K&amp;gt; hashFunction()}}&lt;br /&gt;
&lt;br /&gt;
Return the hashFunction provided to the constructor.&lt;br /&gt;
&lt;br /&gt;
===chains()===&lt;br /&gt;
{{Sequential|private Collection&amp;lt;Entry&amp;lt;K, V&amp;gt;&amp;gt;[] chains()}}&lt;br /&gt;
&lt;br /&gt;
Return the chains created in the constructor.  This method is required for the provided entrySet() method and provides the additional benefit of allowing the creation of the chains to be tested before moving on to the public methods (get, put, computeIfAbsent, compute) which have little hope of working correctly if the chains are not correct.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
===chainIndexOf(key)===&lt;br /&gt;
{{Sequential|private int chainIndexOf(K key)}}&lt;br /&gt;
&lt;br /&gt;
For a given key return the index into the array of buckets.  The correct implementation should leverage the [https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode-- key's hash code] to generate a [https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorMod-int-int- valid index of the bucket array].&lt;br /&gt;
&lt;br /&gt;
{{Tip | You should have just built a utility method which should be useful here.}}&lt;br /&gt;
&lt;br /&gt;
===chainOf(key)===&lt;br /&gt;
{{Sequential|private Collection&amp;lt;Entry&amp;lt;K, V&amp;gt;&amp;gt; chainOf(Object key)}}&lt;br /&gt;
&lt;br /&gt;
chainIndexOf(key) returns the index.  chainOf(key) returns the chain at that index.&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===entryOf(chain, key)===&lt;br /&gt;
{{Sequential|private static &amp;lt;K, V&amp;gt; Optional&amp;lt;Entry&amp;lt;K, V&amp;gt;&amp;gt; entryOf(Collection&amp;lt;Entry&amp;lt;K, V&amp;gt;&amp;gt; chain, K key)}}&lt;br /&gt;
&lt;br /&gt;
Many of the methods listed above exist solely for the purpose of testing to assist in debugging.  It can be argued that the abstraction is past any point of reasonable abstraction.  Not so for entryOf(chain, key).  It is perfectly reasonable and useful to build this method as it will be well used by get, put, computeIfAbsent, compute, and many other methods on Map.&lt;br /&gt;
&lt;br /&gt;
{{Tip|Use the sequential for each loop to iterate through the chain.  This is both good style and necessary for the testing.}}&lt;br /&gt;
&lt;br /&gt;
===put(key, value)===&lt;br /&gt;
{{Sequential|public V put(K key, V value)}}&lt;br /&gt;
&lt;br /&gt;
Note the required return value in the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#put-K-V- put(key,value) specification].&lt;br /&gt;
&lt;br /&gt;
{{Tip | Only the lone correct chain of entries should be searched (and searched only once). }}&lt;br /&gt;
&lt;br /&gt;
{{Tip | When you find an already existing Entry for a key, do not create a new Entry.  Simply set the value of the existing Entry.}}&lt;br /&gt;
&lt;br /&gt;
{{Tip | Do not call any of the methods on interface Map (for example get(key)).  Your utility functions should be all that you need.}}&lt;br /&gt;
&lt;br /&gt;
===get(key)===&lt;br /&gt;
{{Sequential|public V get(Object key)}}&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#get-java.lang.Object- get(key) spec]&lt;br /&gt;
&lt;br /&gt;
{{Tip | Only the lone correct chain of entries should be searched (and searched only once). }}&lt;br /&gt;
&lt;br /&gt;
===computeIfAbsent(key, mappingFunction)===&lt;br /&gt;
While the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function- computeIfAbsent(key, mappingFunction) specification] uses invocations of get and put, you should do neither.  You must achieve the computeIfAbsent specification, but do so akin to the approach taken by put: finding the chain for a key, finding the entry for the key (if it exists) in that chain, and so on.&lt;br /&gt;
&lt;br /&gt;
'''!!! NOTE: you do NOT need to handle any cases involving remove.'''&lt;br /&gt;
&lt;br /&gt;
{{Tip | Only the lone correct chain of entries should be searched (and searched only once). }}&lt;br /&gt;
&lt;br /&gt;
{{Tip | When you find an already existing Entry for a key, do not create a new Entry.  Simply set the value of the existing Entry.}}&lt;br /&gt;
&lt;br /&gt;
{{Tip | Do not call any of the methods on interface Map (for example get(key)).  Your utility functions should be all that you need.}}&lt;br /&gt;
&lt;br /&gt;
===compute(key, remappingFunction)===&lt;br /&gt;
While the [https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#compute-K-java.util.function.BiFunction- compute(key, remappingFunction) specification] uses invocations of get, put, and remove, you should do none of those things.  You must achieve the compute specification, but do so akin to the approach taken by put: finding the chain for a key, finding the entry for the key (if it exists) in that chain, and so on.&lt;br /&gt;
&lt;br /&gt;
'''!!! NOTE: you do NOT need to handle any cases involving remove.'''&lt;br /&gt;
&lt;br /&gt;
{{Tip | Only the lone correct chain of entries should be searched (and searched only once). }}&lt;br /&gt;
&lt;br /&gt;
{{Tip | When you find an already existing Entry for a key, do not create a new Entry.  Simply set the value of the existing Entry.}}&lt;br /&gt;
&lt;br /&gt;
{{Tip | Do not call any of the methods on interface Map (for example get(key)).  Your utility functions should be all that you need.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
===remove(key)===&lt;br /&gt;
{{Sequential|public V remove(Object key)}}&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#remove-java.lang.Object- remove(key) spec]&lt;br /&gt;
&lt;br /&gt;
{{Warning | For an efficient solution (and to avoid a possible ConcurrentModificationException) you will want to use the bucket's iterator directly and leverage its remove method.}}&lt;br /&gt;
&lt;br /&gt;
{{Tip | Only a single bucket's collection should be iterated over once via the iterator() method on appropriate bucket. }}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
===size()===&lt;br /&gt;
{{Sequential|public int size()}}&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#size-- size() spec]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
{{TestSuite|__NotThreadSafeHashTableTestSuite|hashtable.notthreadsafe.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|exercise-hash-table}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:CollapsibleCode&amp;diff=4578</id>
		<title>Template:CollapsibleCode</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:CollapsibleCode&amp;diff=4578"/>
		<updated>2023-02-16T20:38:06Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;mw-collapsible wikitable&amp;quot; style=&amp;quot;width: 95%;&amp;quot;&lt;br /&gt;
! style=&amp;quot;text-align:left;&amp;quot; | {{{msg|{{{1|}}}}}} &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;padding: 1px&amp;quot; |{{{msg|{{{2|}}}}}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:CollapsibleCode&amp;diff=4577</id>
		<title>Template:CollapsibleCode</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:CollapsibleCode&amp;diff=4577"/>
		<updated>2023-02-16T20:19:45Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: Collapse code by default&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;mw-collapsible mw-collapsed wikitable&amp;quot; style=&amp;quot;width: 95%;&amp;quot;&lt;br /&gt;
! style=&amp;quot;text-align:left;&amp;quot; | {{{msg|{{{1|}}}}}} &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;padding: 1px&amp;quot; |{{{msg|{{{2|}}}}}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=MatrixMultiply&amp;diff=4504</id>
		<title>MatrixMultiply</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=MatrixMultiply&amp;diff=4504"/>
		<updated>2023-02-14T00:21:03Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: Added note about auto-coarsening&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Motivation=&lt;br /&gt;
We gain experience using the parallel for loop constructs.&lt;br /&gt;
&lt;br /&gt;
=Background=&lt;br /&gt;
&lt;br /&gt;
Matrix multiplication is a simple mathematical operation which we will replicate in this studio. For our purposes, we will only deal with square matrices (same number of rows and columns). However, we will approach this problem with several different parallel constructs and approaches.&lt;br /&gt;
&lt;br /&gt;
For those unfamiliar on how to multiply two matrices, take a look at these overviews:&lt;br /&gt;
* [https://www.mathsisfun.com/algebra/matrix-multiplying.html Math Is Fun]&lt;br /&gt;
* [http://mathworld.wolfram.com/MatrixMultiplication.html Wolfram MathWorld]&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Matrix_multiplication Wikipedia]&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;\mathbf{A}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n \times m&amp;lt;/math&amp;gt; matrix and &amp;lt;math&amp;gt;\mathbf{B}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;m  \times p&amp;lt;/math&amp;gt; matrix&lt;br /&gt;
&lt;br /&gt;
for each i=[0..n) and for each j=[0..p)&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;(\mathbf{A}\mathbf{B})_{ij} = \sum_{k=1}^m A_{ik}B_{kj}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{C}=\begin{pmatrix}&lt;br /&gt;
 a_{11}b_{11} +\cdots + a_{1n}b_{n1} &amp;amp; a_{11}b_{12} +\cdots + a_{1n}b_{n2} &amp;amp; \cdots &amp;amp; a_{11}b_{1p} +\cdots + a_{1n}b_{np} \\&lt;br /&gt;
 a_{21}b_{11} +\cdots + a_{2n}b_{n1} &amp;amp; a_{21}b_{12} +\cdots + a_{2n}b_{n2} &amp;amp; \cdots &amp;amp; a_{21}b_{1p} +\cdots + a_{2n}b_{np} \\&lt;br /&gt;
\vdots &amp;amp; \vdots &amp;amp; \ddots &amp;amp; \vdots \\&lt;br /&gt;
 a_{m1}b_{11} +\cdots + a_{mn}b_{n1} &amp;amp; a_{m1}b_{12} +\cdots + a_{mn}b_{n2} &amp;amp; \cdots &amp;amp; a_{m1}b_{1p} +\cdots + a_{mn}b_{np} \\&lt;br /&gt;
\end{pmatrix} &lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
source: [https://en.wikipedia.org/wiki/Matrix_multiplication#General_definition_of_the_matrix_product Matrix Multiplication on Wikipedia]&lt;br /&gt;
&lt;br /&gt;
=Code To Investigate=&lt;br /&gt;
==Demo Video==&lt;br /&gt;
&amp;lt;youtube&amp;gt;iEuYiy1Bx2A&amp;lt;/youtube&amp;gt;&lt;br /&gt;
==SequentialMatrixMultiplier==&lt;br /&gt;
{{CodeToInvestigate|SequentialMatrixMultiplier|multiply|matrixmultiply.demo|demo}}&lt;br /&gt;
&lt;br /&gt;
==SequentialMatrixMultiplierClient==&lt;br /&gt;
{{CodeToInvestigate|SequentialMatrixMultiplierClient|main|matrixmultiply.client|demo}}&lt;br /&gt;
&lt;br /&gt;
==MatrixMultiplyApp==&lt;br /&gt;
{{Viz|MatrixMultiplyApp|matrixmultiply.viz|demo}}&lt;br /&gt;
&lt;br /&gt;
[[File:Martix multiply app 3x5 X 5x4.png|800px]]&lt;br /&gt;
&lt;br /&gt;
=The Core Questions=&lt;br /&gt;
*What are the tasks?&lt;br /&gt;
*What is the data?&lt;br /&gt;
*Is the data mutable?&lt;br /&gt;
*If so, how is it shared?&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
&lt;br /&gt;
There are three methods you will need to implement, all of which are different ways to use parallel for loops to solve the problem. To assist you, the [https://classes.engineering.wustl.edu/cse231/core/index.php?title=MatrixMultiply#SequentialMatrixMultiplier sequential implementation] has been implemented in a [[#Demo_Video|demo video]].&lt;br /&gt;
&lt;br /&gt;
==LoopLoopMatrixMultiplier==&lt;br /&gt;
{{CodeToImplement|LoopLoopMatrixMultiplier|multiply|matrixmultiply.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public double[][] multiply(double[][] a, double[][] b)}}&lt;br /&gt;
&lt;br /&gt;
In this implementation, you will simply convert the sequential solution into a parallel one using two nested [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/spring22/apidocs/fj/FJ.html#join_void_fork_loop(int,int,fj.api.TaskIntConsumer) parallel fork loops].&lt;br /&gt;
&lt;br /&gt;
=== Computation Graph ===&lt;br /&gt;
&lt;br /&gt;
For 3x3 Matrix X 3x3 Matrix:&lt;br /&gt;
&lt;br /&gt;
[[File:LoopLoopMatrixMultiplier_Computation_Graph.svg|800px]]&lt;br /&gt;
&lt;br /&gt;
==Loop2dMatrixMultiplier==&lt;br /&gt;
{{CodeToImplement|Loop2dMatrixMultiplier|multiply|matrixmultiply.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public double[][] multiply(double[][] a, double[][] b)}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
In this implementation, we will cut down the syntax of the two forall implementation with the use of V5’s &amp;lt;code&amp;gt;forall2d&amp;lt;/code&amp;gt; method. Functionally, this method serves the purpose of using two forall loops. [[Reference_Page#Forall_2d|Take a look at the reference page]] if you have questions on how to utilize this loop.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/spring22/apidocs/fj/FJ.html#join_void_fork_loop_2d(int,int,int,int,fj.api.TaskBiIntConsumer) join_void_fork_loop_2d]&lt;br /&gt;
&lt;br /&gt;
=== Computation Graph ===&lt;br /&gt;
&lt;br /&gt;
For 3x3 Matrix X 3x3 Matrix:&lt;br /&gt;
&lt;br /&gt;
[[File:Loop2dMatrixMultiplier_Computation_Graph.svg|800px]]&lt;br /&gt;
&lt;br /&gt;
==Loop2dAutoCoarsenMatrixMultiplier==&lt;br /&gt;
{{CodeToImplement|Loop2dAutoCoarsenMatrixMultiplier|multiply|matrixmultiply.exercise}}&lt;br /&gt;
&lt;br /&gt;
{{Parallel|public double[][] multiply(double[][] a, double[][] b)}}&lt;br /&gt;
&lt;br /&gt;
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/spring22/apidocs/fj/FJ.html#join_void_fork_loop_2d_auto_coarsen(int,int,int,int,fj.api.TaskBiIntConsumer) join_void_fork_loop_2d_auto_coarsen]&lt;br /&gt;
&lt;br /&gt;
This implementation will look very similar to the previous one, so don't overthink it! The real benefit can be seen in the performance difference between the two based on the coarsening being done behind the scenes.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
In this implementation, we will add a minor performance boost to the process by using the forall-chunked construct. Although similar to the traditional forall loop, it increases performance using iteration grouping/chunking. This topic is discussed in detail in this [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/6349730bb2a149a0b33fa23db7afddee/?activate_block_id=i4x%3A%2F%2FRiceX%2FCOMP322%2Fsequential%2F6349730bb2a149a0b33fa23db7afddee Rice video] and explained in the [[Reference_Page#Parallel_Loops|V5 documentation]]. There is no need to specify anything, allow the runtime to determine the chunking.&lt;br /&gt;
&lt;br /&gt;
NOTE: we contemplated also assigning building a 1D forall chunked version.  We deemed this more work that it was worth given that you are already building the 2d version.  Just know that forall(chunked(), ...) exists for 1d loops as well.  &lt;br /&gt;
&lt;br /&gt;
Use chunking.  It is a nice feature.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Extra Credit Challege Divide and Conquer=&lt;br /&gt;
[[Matrix_Multiply_Divide_and_Conquer_Assignment|Divide and Conquer Matrix Multiplication]]&lt;br /&gt;
&lt;br /&gt;
=Testing Your Solution=&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|__MatrixMultiplyTestSuite|matrixmultiply.studio}}&lt;br /&gt;
&lt;br /&gt;
==Performance==&lt;br /&gt;
{{Performance|MatrixMultiplicationTiming|matrixmultiply.performance}}&lt;br /&gt;
&lt;br /&gt;
Investigate the performance difference for your different implementations.  When you run MatrixMultiplicationTiming it will put a CSV of the timings into your copy buffer.  You can then paste them into a spreadsheet and chart the performance.  Feel free to tune the parameters of the test to see the impacts of, for example, different matrix sizes.&lt;br /&gt;
&lt;br /&gt;
[[File:Matrix multiply performance.png]]&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|matrix-multiply}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Coarsening_Nucleobase_Count_Assignment&amp;diff=4350</id>
		<title>Coarsening Nucleobase Count Assignment</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Coarsening_Nucleobase_Count_Assignment&amp;diff=4350"/>
		<updated>2023-02-02T01:29:28Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Building On Previous Exercises=&lt;br /&gt;
Be sure to complete the [[Half_And_Half_Nucleobase_Count_Assignment|Half &amp;amp; Half]] and [[Ranges|Ranges]] exercises first.&lt;br /&gt;
&lt;br /&gt;
=Code To Implement=&lt;br /&gt;
{{Warning | Invoke NucleobaseUtils.countRange where appropriate.}}&lt;br /&gt;
&lt;br /&gt;
==CoarseningNucleobaseCounter==&lt;br /&gt;
{{CodeToImplement|CoarseningNucleobaseCounter|constructor&amp;lt;br/&amp;gt;numRanges&amp;lt;br/&amp;gt;count|count.exercise}}&lt;br /&gt;
&lt;br /&gt;
===constructor===&lt;br /&gt;
{{Sequential|public CoarseningNucleobaseCounter(int numRanges)}}&lt;br /&gt;
&lt;br /&gt;
To support the required count method below, we will need to hang onto the number of ranges as an instance variable.&lt;br /&gt;
&lt;br /&gt;
===numRanges===&lt;br /&gt;
&lt;br /&gt;
{{Sequential|public int numRanges()}}&lt;br /&gt;
&lt;br /&gt;
Getter method for numRanges.&lt;br /&gt;
&lt;br /&gt;
===count===&lt;br /&gt;
{{Parallel|public int count(byte[] chromosome, Nucleobase targetNucleobase)}}&lt;br /&gt;
&lt;br /&gt;
To coarsen our parallel counting of an array of nucleobases, we must use our previously created Ranges slice method and count each Range in parallel.&lt;br /&gt;
&lt;br /&gt;
In the computation graph below, we depict a chromosome of length 42 sliced into 4 Ranges:&lt;br /&gt;
&lt;br /&gt;
[[File:CoarseningNucleobaseCounter Computation Graph.svg|400px]]&lt;br /&gt;
&lt;br /&gt;
There are many incantations of the join_fork_loop to choose from.  Be sure to select the correct one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube&amp;gt;LZ8Gorqj9ZU&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;spoiler show=&amp;quot;spoiler&amp;quot; hide=&amp;quot;spoiler&amp;quot;&amp;gt;Choose the one which iterates over your array of Ranges.&amp;lt;/spoiler&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Correctness==&lt;br /&gt;
{{TestSuite|_CoarseningNucleobaseCounterTestSuite|count.exercise}}&lt;br /&gt;
&lt;br /&gt;
=Pledge, Acknowledgments, Citations=&lt;br /&gt;
{{Pledge|nucleobase-count-coarsen}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Office_hours&amp;diff=4318</id>
		<title>Office hours</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Office_hours&amp;diff=4318"/>
		<updated>2023-01-31T01:12:06Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
If you arrive at office hours but do not find a TA, come to Prof. Cosgrove's office Jolley 412.&lt;br /&gt;
&lt;br /&gt;
If the door is locked you can either come to Prof. Cosgrove's office or the CS main office: Jolley 304.&lt;br /&gt;
&lt;br /&gt;
{{OfficeHourWithPassword|Peyton Gozon|91442081240|TE9jb2h4SWlTUS8vL0lnVk53TlhVUT09}}&lt;br /&gt;
&lt;br /&gt;
{{OfficeHour|Prof. Cosgrove|6088142021}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
Be sure to commit and push your code to [https://bitbucket.org BitBucket] before initiating a request on [https://piazza.com/class/lcqelxfqsrh4vu Piazza] or during Office Hours.&lt;br /&gt;
{| class=&amp;quot;wikitable mw-collapsible&amp;quot;&lt;br /&gt;
|+nowrap|Schedule&lt;br /&gt;
|-&lt;br /&gt;
! !! Sunday !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday&lt;br /&gt;
|-&lt;br /&gt;
|9:00 - 9:30 || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|9:30 - 10:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|10:00 - 10:30 || || || {{OfficeHour|Jaz Choi|98704367276}} || || {{OfficeHour|Jaz Choi|98704367276}} || {{OfficeHour|Kenichi Matsuo|95754282937}} ||  &lt;br /&gt;
|-&lt;br /&gt;
|10:30 - 11:00 || || || {{OfficeHour|Jaz Choi|98704367276}} || || {{OfficeHour|Jaz Choi|98704367276}} || {{OfficeHour|Kenichi Matsuo|95754282937}} ||  &lt;br /&gt;
|-&lt;br /&gt;
|11:00 - 11:30 || || || {{OfficeHour|Jaz Choi|98704367276}} || || {{OfficeHour|Jaz Choi|98704367276}} || {{OfficeHour|Kenichi Matsuo|95754282937}} || &lt;br /&gt;
|-&lt;br /&gt;
|11:30 - 12:00 || || || {{OfficeHour|Kenichi Matsuo|95754282937}} || {{OfficeHour|Linus Dannull|2848728376}} || {{OfficeHour|Kenichi Matsuo|95754282937}} || {{OfficeHour|Kenichi Matsuo|95754282937}} || &lt;br /&gt;
|-&lt;br /&gt;
|12:00 - 12:30 || || || {{OfficeHour|Kenichi Matsuo|95754282937}} || {{OfficeHour|Linus Dannull|2848728376}} || {{OfficeHour|Kenichi Matsuo|95754282937}} || || &lt;br /&gt;
|-&lt;br /&gt;
|12:30 - 1:00 || || || {{OfficeHour|Kenichi Matsuo|95754282937}} || {{OfficeHour|Linus Dannull|2848728376}} || {{OfficeHour|Kenichi Matsuo|95754282937}} || ||&lt;br /&gt;
|-&lt;br /&gt;
|1:00 - 1:30 || || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || {{ClassTime|Eads 016}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|1:30 - 2:00 || || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || {{ClassTime|Eads 016}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|2:00 - 2:30 || {{OfficeHour|Evin Jaff|250653820}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || {{ClassTime|Eads 016}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|2:30 - 3:00 || {{OfficeHour|Evin Jaff|250653820}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || {{ClassTime|Eads 016}} || {{OfficeHourWithPassword|Anton Dmitriev|7558192704|cE93aHF3NmVQZFlJdlNteDBKMnFTdz09}} || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|3:00 - 3:30 || {{OfficeHour|Evin Jaff|250653820}} || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|3:30 - 4:00 || {{OfficeHour|Evin Jaff|250653820}} || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || {{OfficeHour|Andrew Zuo|3589915173}} ||&lt;br /&gt;
|-&lt;br /&gt;
|4:00 - 4:30 || || || Luke Rowen, Eads 016 || || || || &lt;br /&gt;
|-&lt;br /&gt;
|4:30 - 5:00 || || || Luke Rowen, Eads 016 || || {{OfficeHour|Kai Ang|9277140609}} || || &lt;br /&gt;
|-&lt;br /&gt;
|5:00 - 5:30 || || || || || {{OfficeHour|Kai Ang|9277140609}} || || &lt;br /&gt;
|-&lt;br /&gt;
|5:30 - 6:00 || || || || || {{OfficeHour|Kai Ang|9277140609}} || || &lt;br /&gt;
|-&lt;br /&gt;
|6:00 - 6:30 || || {{OfficeHourWithPassword|Max Roitblat|98162215450|Wk82dTBEQkhyMDFxeGtqS2VqK0h5UT09}} || || || {{OfficeHour|Kai Ang|9277140609}} || || &lt;br /&gt;
|-&lt;br /&gt;
|6:30 - 7:00 || || {{OfficeHourWithPassword|Max Roitblat|98162215450|Wk82dTBEQkhyMDFxeGtqS2VqK0h5UT09}} || || || {{OfficeHour|Kai Ang|9277140609}} || ||&lt;br /&gt;
|-&lt;br /&gt;
|7:00 - 7:30 || || {{OfficeHourWithPassword|Max Roitblat|98162215450|Wk82dTBEQkhyMDFxeGtqS2VqK0h5UT09}} || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Kai Ang|9277140609}} and &amp;lt;b&amp;gt; [https://wustl.zoom.us/j/8309341089 Mason Kelber zoom] &amp;lt;/b&amp;gt; || || &lt;br /&gt;
|-&lt;br /&gt;
|7:30 - 8:00 || || {{OfficeHourWithPassword|Max Roitblat|98162215450|Wk82dTBEQkhyMDFxeGtqS2VqK0h5UT09}} || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Kai Ang|9277140609}} and &amp;lt;b&amp;gt; [https://wustl.zoom.us/j/8309341089 Mason Kelber zoom] &amp;lt;/b&amp;gt; || || &lt;br /&gt;
|-&lt;br /&gt;
|8:00 - 8:30 || || || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Kai Ang|9277140609}} and &amp;lt;b&amp;gt; [https://wustl.zoom.us/j/8309341089 Mason Kelber zoom] &amp;lt;/b&amp;gt; || || &lt;br /&gt;
|-&lt;br /&gt;
|8:30 - 9:00 || || || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Kai Ang|9277140609}} and &amp;lt;b&amp;gt; [https://wustl.zoom.us/j/8309341089 Mason Kelber zoom] &amp;lt;/b&amp;gt; || || &lt;br /&gt;
|-&lt;br /&gt;
|9:00 - 9:30 || || || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Mason Kelber|8309341089}} || || &lt;br /&gt;
|-&lt;br /&gt;
|9:30 - 10:00 || || || {{OfficeHour|Mason Kelber|8309341089}} || || {{OfficeHour|Mason Kelber|8309341089}} || ||&lt;br /&gt;
|-&lt;br /&gt;
|10:00 - 10:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|10:30 - 11:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:00 - 11:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:30 - 12:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Office_hours&amp;diff=4191</id>
		<title>Office hours</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Office_hours&amp;diff=4191"/>
		<updated>2023-01-09T18:26:50Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: Reset schedule for SP2023&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
If you arrive at office hours but do not find a TA, come to Prof. Cosgrove's office Jolley 412.&lt;br /&gt;
&lt;br /&gt;
If the door is locked you can either come to Prof. Cosgrove's office or the CS main office: Jolley 304.&lt;br /&gt;
&lt;br /&gt;
{{OfficeHourWithPassword|Peyton Gozon|91442081240|TE9jb2h4SWlTUS8vL0lnVk53TlhVUT09}}&lt;br /&gt;
&lt;br /&gt;
{{OfficeHour|Prof. Cosgrove|6088142021}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
Be sure to commit and push your code to [https://bitbucket.org BitBucket] before initiating a request on [https://piazza.com/class/l7g6evl04y43w1 Piazza] or during Office Hours.&lt;br /&gt;
{| class=&amp;quot;wikitable mw-collapsible&amp;quot;&lt;br /&gt;
|+nowrap|Schedule&lt;br /&gt;
|-&lt;br /&gt;
! !! Sunday !! Monday !! Tuesday !! Wednesday !! Thursday !! Friday !! Saturday&lt;br /&gt;
|-&lt;br /&gt;
|9:00 - 9:30 || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|9:30 - 10:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|10:00 - 10:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|10:30 - 11:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:00 - 11:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:30 - 12:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|12:00 - 12:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|12:30 - 1:00 || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|1:00 - 1:30 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|1:30 - 2:00 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|2:00 - 2:30 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|2:30 - 3:00 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|3:00 - 3:30 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|3:30 - 4:00 || || || {{ClassTime|Eads 016}} || || style=&amp;quot;background-color:#95d9ed;|Class Eads 016 || ||&lt;br /&gt;
|-&lt;br /&gt;
|4:00 - 4:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|4:30 - 5:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|5:00 - 5:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|5:30 - 6:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|6:00 - 6:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|6:30 - 7:00 || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|7:00 - 7:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|7:30 - 8:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|8:00 - 8:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|8:30 - 9:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|9:00 - 9:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|9:30 - 10:00 || || || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
|10:00 - 10:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|10:30 - 11:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:00 - 11:30 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|11:30 - 12:00 || || || || || || || &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:ClassTime&amp;diff=4190</id>
		<title>Template:ClassTime</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Template:ClassTime&amp;diff=4190"/>
		<updated>2023-01-09T18:24:28Z</updated>

		<summary type="html">&lt;p&gt;Mroitblat: Created Class Template for Calendar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;style=&amp;quot;background-color:#95d9ed;&amp;quot; | Class {{{1}}}&lt;/div&gt;</summary>
		<author><name>Mroitblat</name></author>
		
	</entry>
</feed>