Clang tidy 2022 Day 7.
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
// Created by Matthew Gretton-Dann on 07/12/2022.
|
// Created by Matthew Gretton-Dann on 07/12/2022.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -14,11 +13,11 @@ using UInt = std::uint64_t;
|
|||||||
|
|
||||||
struct DirectoryInfo
|
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 const file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
|
||||||
[](UInt a, auto const& b) { return a + b.second; })};
|
[](UInt a, auto const& b) { return a + b.second; })};
|
||||||
UInt directory_size{
|
UInt const directory_size{
|
||||||
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
|
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
|
||||||
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
|
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
|
||||||
return file_size + directory_size;
|
return file_size + directory_size;
|
||||||
@@ -88,7 +87,7 @@ auto main() -> int
|
|||||||
std::smatch m;
|
std::smatch m;
|
||||||
if (!std::regex_search(line, m, re)) {
|
if (!std::regex_search(line, m, re)) {
|
||||||
std::cerr << "Unable to interpret: " << line << "\n";
|
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)));
|
its.back()->second.add_file(m.str(2), std::stoul(m.str(1)));
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
// Created by Matthew Gretton-Dann on 07/12/2022.
|
// Created by Matthew Gretton-Dann on 07/12/2022.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -14,11 +13,11 @@ using UInt = std::uint64_t;
|
|||||||
|
|
||||||
struct DirectoryInfo
|
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 const file_size{std::accumulate(files_.begin(), files_.end(), UInt{0},
|
||||||
[](UInt a, auto const& b) { return a + b.second; })};
|
[](UInt a, auto const& b) { return a + b.second; })};
|
||||||
UInt directory_size{
|
UInt const directory_size{
|
||||||
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
|
std::accumulate(dirs_.begin(), dirs_.end(), UInt{0},
|
||||||
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
|
[](UInt a, auto const& b) { return a + b.second.total_size(); })};
|
||||||
return file_size + directory_size;
|
return file_size + directory_size;
|
||||||
@@ -99,8 +98,8 @@ auto main() -> int
|
|||||||
|
|
||||||
UInt constexpr disk_size{70000000};
|
UInt constexpr disk_size{70000000};
|
||||||
UInt constexpr needed_space{30000000};
|
UInt constexpr needed_space{30000000};
|
||||||
UInt current_space{disk_size - root->second.total_size()};
|
UInt const current_space{disk_size - root->second.total_size()};
|
||||||
UInt min_space_to_free(needed_space - current_space);
|
UInt const min_space_to_free(needed_space - current_space);
|
||||||
std::cout << "Size to free: " << size_to_free(root, min_space_to_free) << '\n';
|
std::cout << "Size to free: " << size_to_free(root, min_space_to_free) << '\n';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user