문제

어떤 시나리오가매핑하고 줄입니다"알고리즘?


이 알고리즘의 .NET 구현이 있습니까?

도움이 되었습니까?

해결책

LINQ 동등한지도 및 감소 : LINQ를 갖기에 운이 좋으면 자신의지도를 작성하고 기능을 줄일 필요가 없습니다. C# 3.5 및 LINQ는 이미 다른 이름 아래에 있지만 이미 가지고 있습니다.

Map = Select | Enumerable.Range(1, 10).Select(x => x + 2);
Reduce = Aggregate | Enumerable.Range(1, 10).Aggregate(0, (acc, x) => acc + x);
Filter = Where | Enumerable.Range(1, 10).Where(x => x % 2 == 0);

https://www.justinshield.com/2011/06/mapreduce-in-c/

다른 팁

MapReduce 스타일 솔루션에 적합한 문제의 클래스는 집계 문제입니다. 데이터 세트에서 데이터 추출 C#에서는 LINQ를 활용 하여이 스타일로 프로그래밍 할 수 있습니다.

다음 기사에서 :http://codecube.net/2009/02/mapreduce-in-c-using-linq/

GroupBY 메소드는 맵 역할을하는 반면, SELECT 메소드는 중간 결과를 최종 결과 목록으로 줄이는 작업을 수행합니다.

var wordOccurrences = words
                .GroupBy(w => w)
                .Select(intermediate => new
                {
                    Word = intermediate.Key,
                    Frequency = intermediate.Sum(w => 1)
                })
                .Where(w => w.Frequency > 10)
                .OrderBy(w => w.Frequency);

분산 부분의 경우 dryadlinq를 확인할 수 있습니다. http://research.microsoft.com/en-us/projects/dryadlinq/default.aspx

나는 LINQ가 그것을 부르는 것을 기억할 수 없기 때문에 Where, Select 그리고 Aggregate 대신에 Filter, Map 그리고 Reduce 그래서 사용할 수있는 몇 가지 확장 방법을 만들었습니다.

IEnumerable<string> myStrings = new List<string>() { "1", "2", "3", "4", "5" };
IEnumerable<int> convertedToInts = myStrings.Map(s => int.Parse(s));
IEnumerable<int> filteredInts = convertedToInts.Filter(i => i <= 3); // Keep 1,2,3
int sumOfAllInts = filteredInts.Reduce((sum, i) => sum + i); // Sum up all ints
Assert.Equal(6, sumOfAllInts); // 1+2+3 is 6

다음은 세 가지 방법입니다 ( https://github.com/cs-util-com/cscore/blob/mas ):

public static IEnumerable<R> Map<T, R>(this IEnumerable<T> self, Func<T, R> selector) {
    return self.Select(selector);
}

public static T Reduce<T>(this IEnumerable<T> self, Func<T, T, T> func) {
    return self.Aggregate(func);
}

public static IEnumerable<T> Filter<T>(this IEnumerable<T> self, Func<T, bool> predicate) {
    return self.Where(predicate);
}

몇 가지 자세한 내용 https://github.com/cs-util-com/cscore#ienumerable-extensions :

enter image description here

자신의 Google 버전을 작성하려고한다면 보증 할 수 있습니다. !!!

진지하게, 당신이 몇 가지 작은 문제로 분해 할 수있는 문제가 있다면 맵 레디스 솔루션이 작동합니다. Google 문서 Mapreduce 수천 개의 웹 페이지를 처리하는 방법, 문서에 단어 계산 등을 포함하여 여러 가지 좋은 예가 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top