From 04821c431b0644a496ea7e63274ddc6952a93ecb Mon Sep 17 00:00:00 2001 From: Gene Hightower Date: Fri, 14 Oct 2022 14:35:58 -0700 Subject: [PATCH] Better to check at compile time. (If at all) --- src/BloomFilter.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/BloomFilter.cpp b/src/BloomFilter.cpp index d7cb2b1..540a6c6 100644 --- a/src/BloomFilter.cpp +++ b/src/BloomFilter.cpp @@ -42,6 +42,7 @@ static vector readVectorFromStream(BinaryInputStream &in); // Implementation BloomFilter::BloomFilter(size_t maxItems, double targetProbability) { + static_assert(CHAR_BIT == BITS_PER_BLOCK, "Unsupported architecture: char is not 8 bit"); checkArchitecture(); bitCount = (size_t) ceil((maxItems * log(targetProbability)) / log(1.0 / (pow(2.0, log(2.0))))); auto blocks = (size_t) ceil(bitCount / (double) BITS_PER_BLOCK); @@ -50,21 +51,16 @@ BloomFilter::BloomFilter(size_t maxItems, double targetProbability) { } BloomFilter::BloomFilter(const string &importFilePath, size_t bitCount, size_t maxItems) : bitCount(bitCount) { - checkArchitecture(); bloomVector = readVectorFromFile(importFilePath); hashRounds = calculateHashRounds(bitCount, maxItems); } BloomFilter::BloomFilter(BinaryInputStream &in, size_t bitCount, size_t maxItems) : bitCount(bitCount) { - checkArchitecture(); bloomVector = readVectorFromStream(in); hashRounds = calculateHashRounds(bitCount, maxItems); } static void checkArchitecture() { - if (CHAR_BIT != BITS_PER_BLOCK) { - throw std::runtime_error("Unsupported architecture: char is not 8 bit"); - } } static size_t calculateHashRounds(size_t size, size_t maxItems) { @@ -151,4 +147,4 @@ static vector readVectorFromStream(BinaryInputStream &in) { size_t BloomFilter::getBitCount() const { return bitCount; -} \ No newline at end of file +}