-
Notifications
You must be signed in to change notification settings - Fork 0
к/р 1 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| public static IEnumerable<TestCaseData> TestCases() | ||
| { | ||
| foreach (var testFile in Directory.GetFileSystemEntries(TestFilesPath)) | ||
| { | ||
| yield return new TestCaseData(testFile); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public static IEnumerable<TestCaseData> TestCases() | |
| { | |
| foreach (var testFile in Directory.GetFileSystemEntries(TestFilesPath)) | |
| { | |
| yield return new TestCaseData(testFile); | |
| } | |
| } | |
| public static IEnumerable<TestCaseData> TestCases() | |
| => Directory.GetFileSystemEntries(TestFilesPath).Select(e => new TestCaseData(e)); |
Если проходите по коллекции, чтобы сделать yield, это сразу знак, что делаете что-то не так, коллекция ведь и так коллекция, а yield нужен, чтобы по набору значений коллекцию сделать
| using System.Security.Cryptography; | ||
| using System.Text; | ||
|
|
||
| namespace CheckSum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace лучше перед using
|
|
||
| private static byte[] GetFileCheckSumSequentially(string path) | ||
| { | ||
| var content = File.ReadAllBytes(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если файл в память не лезет, быть беде
| result.AddRange(GetCheckSumSequentially(entry)); | ||
| } | ||
|
|
||
| return result.ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так это не чексумма, а конкатенированный набор чексумм. Надо было это ещё в MD5 запихать.
| { | ||
| var content = await File.ReadAllBytesAsync(path); | ||
| return MD5.HashData(content); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вы не поверите, но и в однопоточном случае стоило так с файлом и поступать. Синхронный ввод-вывод в современном мире, я бы сказал, вообще не нужен. Тут оно асинхронное, но не параллельное, так что не противоречит условию.
| var tasks = new List<Task<byte[]>>(); | ||
| var name = Path.GetFileName(path); | ||
| var nameHash = MD5.HashData(Encoding.Unicode.GetBytes(name)); | ||
| tasks.Add(Task.Run(() => nameHash)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Он же уже посчитан. Task.Result?
| { | ||
| result[currentIndex] = task.Result[i]; | ||
| ++currentIndex; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Процесс можно было немного автоматизировать через Array.Copy
| } | ||
| } | ||
|
|
||
| return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И тоже, ожидался 128-битный хеш, вернули что попало
| public static class Program | ||
| { | ||
| /// <summary> | ||
| /// Main entry point of the program. | ||
| /// </summary> | ||
| /// <param name="args">First argument is the path of | ||
| /// the file to evaluate the check sum of.</param> | ||
| public static void Main(string[] args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это не нужно, используйте top-level statements
| stopWatch.Restart(); | ||
| CheckSumUtils.GetCheckSumSequentially(path); | ||
| stopWatch.Stop(); | ||
| Console.WriteLine($"Time of the sequential evaluation: {stopWatch.Elapsed}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Указывайте единицы измерения всегда
No description provided.