Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to code a C++ implementation of a Bloom filter using the Murmur3 hash function. My implementation is based on this site: http://blog.michaelschmatz.com/2016/04/11/how-to-write-a-bloom-filter-cpp/

I am trying to code a C++ implementation of a Bloom filter using the Murmur3 hash function. My implementation is based on this site: http://blog.michaelschmatz.com/2016/04/11/how-to-write-a-bloom-filter-cpp/ Somehow, in my BloomFilter header file, the hash function throws an incomplete type error, also, when I use the hash function inside of the add function, I get a "hash is ambigious error". What can I do to fix this?

#ifndef BLOOM_FILTER_H

#define BLOOM_FILTER_H

#include "MurmurHash3.h"

#include

//basic structure of a bloom filter object

struct BloomFilter {

BloomFilter(uint64_t size, uint8_t numHashes);

void add(const uint8_t *data, std::size_t len);

bool possiblyContains(const uint8_t *data, std::size_t len) const;

private:

uint8_t m_numHashes;

std::vector m_bits;

};

//Bloom filter constructor

BloomFilter::BloomFilter(uint64_t size, uint8_t numHashes)

: m_bits(size),

m_numHashes(numHashes) {}

//Hash array created using the MurmurHash3 code

std::array hash(const uint8_t *data, std::size_t len)

{

std::array hashValue;

MurmurHash3_x64_128(data, len, 0, hashValue.data());

return hashValue;

}

//Hash array created using the MurmurHash3 code

inline uint64_t nthHash(uint8_t n,

uint64_t hashA,

uint64_t hashB,

uint64_t filterSize) {

return (hashA + n * hashB) % filterSize;

}

//Adds an element to the array

void BloomFilter::add(const uint8_t *data, std::size_t len) {

auto hashValues = hash(data, len);

for (int n = 0; n < m_numHashes; n++)

{

m_bits[nthHash(n, hashValues[0], hashValues[1], m_bits.size())] = true;

}

}

//Returns true or false based on a probabilistic assesment of the array using MurmurHash3

bool BloomFilter::possiblyContains(const uint8_t *data, std::size_t len) const {

auto hashValues = hash(data, len);

for (int n = 0; n < m_numHashes; n++)

{

if (!m_bits[nthHash(n, hashValues[0], hashValues[1], m_bits.size())])

{

return false;

}

}

return true;

}

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

=+2 How can the effectiveness of global virtual teams be improved?

Answered: 1 week ago

Question

=+1 What are the major issues related to international T&D?

Answered: 1 week ago