08/02/15 11:52:51
まずは単純だけど遅いバージョンから
// ファイルをハッシュ値でグループ化する
// 全ファイルを読み込んでハッシュ値を計算するので遅いです
var hashGroupQuery = from filehash in
(from filename in files
let hash = GetMD5String(filename)
select new { Filename = filename, Hash = hash })
group filehash by filehash.Hash into hashGroup
where hashGroup.Count() >= 2
select hashGroup;
foreach (var hashGroup in hashGroupQuery)
{
Console.WriteLine("Hash: {0}, Count: {1}", hashGroup.Key, hashGroup.Count());
foreach (var filehash in hashGroup)
{
Console.WriteLine("\t{0}", filehash.Filename);
}
}