diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f3903fa..922379e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -542,7 +542,7 @@ endif () ############################################################################### -foreach (tool cpuid poisson macro scratch) +foreach (tool buzstats cpuid poisson macro scratch) add_executable (util_${tool} tools/${tool}.cpp) set_target_properties (util_${tool} PROPERTIES OUTPUT_NAME ${tool}) target_link_libraries (util_${tool} cruft) diff --git a/tools/buzstats.cpp b/tools/buzstats.cpp new file mode 100644 index 00000000..4c3a3ed7 --- /dev/null +++ b/tools/buzstats.cpp @@ -0,0 +1,32 @@ +#include "hash/buzhash.hpp" +#include "io.hpp" + +#include + +int main (int argc, char const **argv) +{ + (void)argc; + + cruft::mapped_file src (argv[1]); + cruft::view bytes (src); + + static constexpr std::size_t BITS = 16; + std::vector counts (BITS, 0); + + static constexpr std::size_t WINDOW = 48; + cruft::hash::buzhash h (WINDOW, bytes); + + for (auto const &val: bytes.consume (WINDOW)) { + auto const res = h (&val); + + std::size_t mask = ~u64(0) >> (64 - BITS); + for (std::size_t i = 0; i < BITS; ++i) { + if ((res & mask) == 0) + counts[i]++; + mask >>= 1; + } + } + + for (auto const &i: counts) + std::cout << i << '\n'; +} \ No newline at end of file