08/02/15 11:56:08
次に前処理を行って高速化したバージョン
// 処理を高速化するため、ファイルサイズでグループ化しておく
// (ファイルサイズはファイルを読み込まなくても取得できるので)
var sizeGroupQuery = from filesize in
(from filename in files
let fileinfo = new System.IO.FileInfo(filename)
let size = fileinfo.Length
select new { Filename = filename, Size = size })
group filesize by filesize.Size into sizeGroup
where sizeGroup.Count() >= 2
select sizeGroup;
foreach (var sizeGroup in sizeGroupQuery)
{
// ハッシュ値でグループ化する
var hashGroupQuery2 = from filehash in
(from filesize in sizeGroup
let hash = GetMD5String(filesize.Filename)
select new { Filename = filesize.Filename, Hash = hash })
group filehash by filehash.Hash into hashGroup
where hashGroup.Count() >= 2
select hashGroup;
foreach (var hashGroup in hashGroupQuery2)
{
// (行数オーバーのため略 >>39と同じです)
}
}