/* * 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 2010 Danny Robson */ #include "fletcher.hpp" #include "../debug.hpp" using util::hash::fletcher; /////////////////////////////////////////////////////////////////////////////// template fletcher::fletcher (part_t _modulus, part_t _a, part_t _b): m_modulus { _modulus }, m_initial { _a, _b } { ; } /////////////////////////////////////////////////////////////////////////////// template typename fletcher::digest_t fletcher::operator() (util::view data) const noexcept { state_t accum = m_initial; for (const auto i: data) { accum.a = (accum.a + i) % m_modulus; accum.b = (accum.a + accum.b) % m_modulus; } return accum.b << (sizeof(part_t) * 8u) | accum.a; } /////////////////////////////////////////////////////////////////////////////// template class util::hash::fletcher;