emory/emory.cpp
2019-04-23 08:17:34 +10:00

41 lines
1.0 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2013 Danny Robson <danny@nerdcruft.net>
*/
#include <cruft/util/hash/buzhash.hpp>
#include <cruft/util/io.hpp>
#include <iostream>
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<std::size_t> counts (BITS, 0);
static constexpr std::size_t WINDOW = 48;
cruft::hash::buzhash<u64> 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';
}