C # MapReduce

Source: Internet
Author: User

If you do not know how MapReduce works, please refer to here. If you do not know what MapReduce is, please google!

Today, there is nothing to do with "idle". I suddenly remember that there is no MapReduce method in C #. I think about it, coding:

 IEnumerable<T>.MapReduce          Dictionary<TKey, TResult> MapReduce<TInput, TKey, TValue, TResult> IEnumerable<TInput><TInput, IEnumerable<KeyValuePair<TKey, TValue>>><TKey, IEnumerable<TValue>, TResult><TKey, List<TValue>> mapResult =  Dictionary<TKey, List<TValue>> ( item  ( one <TValue> (!mapResult.TryGetValue(one.Key, =  List<TValue> result =  Dictionary<TKey, TResult> ( m 

Note: Because emit can be performed multiple times in the map method, IEnumerable is returned here. yield return is used in the following example.

Example:

       ID { ;   Name { ;   Age { ; 

 

          Main(<Person> list= List<Person> Person { ID=, Name=, Age= Person { ID = , Name = , Age =  Person { ID = , Name = , Age =  Person { ID = , Name = , Age =  Person { ID = , Name = , Age =  result = list.MapReduce<Person, , , >=> .Join( ( d +  +  IEnumerable<KeyValuePair<, >> (p.Age >    KeyValuePair<, >

What the above program did is to count the people of all ages who are older than 22, as shown in:

23: user1, user3
24: user2
25: user4
Press any key to continue...

(It is too troublesome to upload images. I have made an html console. Thank you !)

Some may ask why map does not use lambda expressions like reduce, because yield return cannot be in anonymous and lambda expressions! MS indicates that you already know the problem, but it takes a lot of money to rewrite yield. It will definitely be solved in the future!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.