password-analyzer/stat_length.cpp

17 lines
581 B
C++
Raw Normal View History

2023-11-03 21:06:09 +08:00
#include <algorithm>
#include <map>
#include <vector>
#include "defs.hpp"
void stat_length(const DataSource &source) {
2023-11-04 00:24:22 +08:00
timeit(fmt::format("stat_length({})", magic_enum::enum_name(source)));
2023-11-03 21:06:09 +08:00
std::map<size_t, size_t> stat;
for (auto const &password : passwords(source)) ++stat[password.size()];
std::vector<std::pair<size_t, size_t>> vec(stat.begin(), stat.end());
std::sort(vec.begin(), vec.end(), [](auto const &lhs, auto const &rhs) { return lhs.second > rhs.second; });
2023-11-05 16:01:45 +08:00
for (auto const &[length, count] : vec) spdlog::info("{}: {}", length, count);
2023-11-03 21:06:09 +08:00
}