File indexing completed on 2024-11-17 04:55:18
0001 /* 0002 SPDX-License-Identifier: MPL-2.0 0003 */ 0004 0005 /* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license. 0006 * This Source Code Form is subject to the terms of the Mozilla Public 0007 * License, v. 2.0. If a copy of the MPL was not distributed with this 0008 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 0009 0010 #include "hashFn.h" 0011 0012 uint64_t HashFn::operator()(const char *input, int len, 0013 unsigned char lastCharCode, uint64_t lastHash) { 0014 // See the abracadabra example: 0015 // https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm 0016 return (lastHash - lastCharCode * 0017 customPow(&precomputedPowers, precompute, p, len - 1)) * 0018 p + input[len - 1]; 0019 } 0020 0021 uint64_t HashFn::operator()(const char *input, int len) { 0022 uint64_t total = 0; 0023 for (int i = 0; i < len; i++) { 0024 total += input[i] * 0025 customPow(&precomputedPowers, precompute, p, len - i - 1); 0026 } 0027 return total; 0028 }