?????????????????????????????С????????? (???????????????)??
?????????????С?????????????????
????С??ο?MapReduce???????Map??Reduce???£?
????Map???
????Mapping
????Mapping???????????????key??value?????С???????<????????????(1)>??<word??1>??
????public IEnumerable<Tuple<T?? int>> Mapping(IEnumerable<T> list)
????{
????foreach (T sourceVal in list)
????yield return Tuple.Create(sourceVal?? 1);
????}
????????????(brow?? 1)?? (brow?? 1)?? (sorrow?? 1)?? (sorrow?? 1):
????var spit = hamlet.Split(new[] { " "?? Environment.NewLine }?? StringSplitOptions.RemoveEmptyEntries);
????var mp = new MicroMapReduce<string>(new Master<string>());
????var result= mp.Mapping(spit);
????Combine
??????????????????????mapping???????????????????????reduce??????????????????????????????????????????????????????? ???????(brow?? 2)?? (sorrow?? 2):
public Dictionary<T?? int> Combine(IEnumerable<Tuple<T?? int>> list)
{
Dictionary<T?? int> dt = new Dictionary<T?? int>();
foreach (var val in list)
{
if (dt.ContainsKey(val.Item1))
dt[val.Item1] += val.Item2;
else
dt.Add(val.Item1?? val.Item2);
}
return dt;
}
????Partitioner
????Partitioner??????????黮?????????????????????key???з??顣
??????????????? (brow?? {(brow??2)}??(brow??3))?? (sorrow?? {(sorrow??10)}??(brow??11)):
????public IEnumerable<Group<T?? int>> Partitioner(Dictionary<T?? int> list)
????{
????var dict = new Dictionary<T?? Group<T?? int>>();
????foreach (var val in list)
????{
????if (!dict.ContainsKey(val.Key))
????dict[val.Key] = new Group<T?? int>(val.Key);
????dict[val.Key].Values.Add(val.Value);
????}
????return dict.Values;
????}
????Group????:
public class Group<TKey?? TValue> : Tuple<TKey?? List<TValue>>
{
public Group(TKey key)
: base(key?? new List<TValue>())
{
}
public TKey Key
{
get
{
return base.Item1;
}
}
public List<TValue> Values
{
get
{
return base.Item2;
}
}
}
????Reduce???
????Reducing?????????????????????к????????
????public Dictionary<T?? int> Reducing(IEnumerable<Group<T?? int>> groups)
????{
????Dictionary<T?? int> result=new Dictionary<T?? int>();
????foreach (var sourceVal in groups)
????{
????result.Add(sourceVal.Key?? sourceVal.Values.Sum());
????}
????return result;
????}
??????????????£?
????public IEnumerable<Group<T?? int>> Map(IEnumerable<T> list)
????{
????var step1 = Mapping(list);
????var step2 = Combine(step1);
????var step3 = Partitioner(step2);
????return step3;
????}
????public Dictionary<T?? int> Reduce(IEnumerable<Group<T?? int>> groups)
????{
????var step1 = Reducing(groups);
????return step1;
????}
????public  Dictionary<T?? int> MapReduce(IEnumerable<T> list)
????{
????var map = Map(list);
????var reduce = Reduce(map);
????return reduce;
????}