Clang tidy 2022 Day 7.

This commit is contained in:
2022-12-07 07:41:52 +00:00
parent 54900d5a36
commit bfd11cf480
2 changed files with 11 additions and 13 deletions

View File

@@ -2,7 +2,6 @@
// Created by Matthew Gretton-Dann on 07/12/2022.
//
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
@@ -14,11 +13,11 @@ using UInt = std::uint64_t;
struct DirectoryInfo
{
auto total_size() const noexcept -> UInt
[[nodiscard]] auto total_size() const noexcept -> UInt
{
UInt file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second; })};
UInt directory_size{
UInt const file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second; })};
UInt const directory_size{
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
return file_size + directory_size;
@@ -88,7 +87,7 @@ auto main() -> int
std::smatch m;
if (!std::regex_search(line, m, re)) {
std::cerr << "Unable to interpret: " << line << "\n";
std::exit(1);
return EXIT_FAILURE;
}
its.back()->second.add_file(m.str(2), std::stoul(m.str(1)));
}

View File

@@ -2,7 +2,6 @@
// Created by Matthew Gretton-Dann on 07/12/2022.
//
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
@@ -14,11 +13,11 @@ using UInt = std::uint64_t;
struct DirectoryInfo
{
auto total_size() const noexcept -> UInt
[[nodiscard]] auto total_size() const noexcept -> UInt
{
UInt file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second; })};
UInt directory_size{
UInt const file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second; })};
UInt const directory_size{
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
return file_size + directory_size;
@@ -99,8 +98,8 @@ auto main() -> int
UInt constexpr disk_size{70000000};
UInt constexpr needed_space{30000000};
UInt current_space{disk_size - root->second.total_size()};
UInt min_space_to_free(needed_space - current_space);
UInt const current_space{disk_size - root->second.total_size()};
UInt const min_space_to_free(needed_space - current_space);
std::cout << "Size to free: " << size_to_free(root, min_space_to_free) << '\n';
return 0;
}