From c07da87b3a2212a3ec8e84a7d36c352194cb6f63 Mon Sep 17 00:00:00 2001 From: Gene Hightower Date: Fri, 14 Oct 2022 14:12:51 -0700 Subject: [PATCH] The "char" type might be signed, both hash functions are defined to work on unsigned 8-bit values. --- src/BloomFilter.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BloomFilter.cpp b/src/BloomFilter.cpp index d7cb2b1..af65259 100644 --- a/src/BloomFilter.cpp +++ b/src/BloomFilter.cpp @@ -105,16 +105,16 @@ bool BloomFilter::contains(const string &element) { static unsigned int djb2Hash(const string &text) { unsigned int hash = 5381; - for (const char &iterator : text) { - hash = ((hash << 5) + hash) + iterator; + for (auto ch : text) { + hash = ((hash << 5) + hash) + static_cast(ch); } return hash; } static unsigned int sdbmHash(const string &text) { unsigned int hash = 0; - for (const char &iterator : text) { - hash = iterator + ((hash << 6) + (hash << 16) - hash); + for (auto ch : text) { + hash = static_cast(ch) + ((hash << 6) + (hash << 16) - hash); } return hash; } @@ -151,4 +151,4 @@ static vector readVectorFromStream(BinaryInputStream &in) { size_t BloomFilter::getBitCount() const { return bitCount; -} \ No newline at end of file +}