public IDictionary <string, int> GetWordCount() { var wordFrequency = new Dictionary <string, int>(_comparer); using (var wordEnumerator = new WordEnumerator(_reader)) { while (wordEnumerator.MoveNext()) { var word = wordEnumerator.Current; int value; wordFrequency.TryGetValue(word, out value); wordFrequency[word] = ++value; } } return(wordFrequency); }
public IDictionary <string, int> GetWordCount() { var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; Parallel.ForEach(_readers, options, reader => // producers { using (var wordEnumerator = new WordEnumerator(reader)) { while (wordEnumerator.MoveNext()) { var word = wordEnumerator.Current; _combinedWordCount.AddOrUpdate(word, 1, (key, value) => value + 1); } } }); return(_combinedWordCount); }