Live data from Hacker News

How to write a Bloom filter in C++

blog.michaelschmatz.com

1–10 of 21 posts

Re: How to write a Bloom filter in C++

#5
post #4

This example works well for raw data but not for complex types. You could make the filter a template, taking the key and a "hasher" function as template args.

Great suggestion; I wasn't sure the idiomatic way to template this, thanks for letting me know!

Probably something like this:

template > class BloomFilter;

Re: How to write a Bloom filter in C++

#6
post #4

Earlier quoted context omitted.

Great suggestion; I wasn't sure the idiomatic way to template this, thanks for letting me know!

Probably something like this: template > class BloomFilter;

I updated the blog post with your suggestion; CDN should be updated soon :)

Re: How to write a Bloom filter in C++

#7
post #4

Earlier quoted context omitted.

Great suggestion; I wasn't sure the idiomatic way to template this, thanks for letting me know!

Probably something like this: template > class BloomFilter;

I don't use c++ so I'm not sure how std:hash works or gets implemented, but the way that guava (Google's java library) does it is by passing in a key and a funnel object. The funnel object is essentially responsible for decomposing the object into a byte stream. The advantage of doing it this way rather than making the caller specify his own hash is that you can use murmurhash3 which you thought had the best properties for the bloom filter.

Re: How to write a Bloom filter in C++

#8

This example works well for raw data but not for complex types. You could make the filter a template, taking the key and a "hasher" function as template args.

Even better: N3980 [1]

This proposal decouples the implementation of hash functions from how types get hashed.

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n398...

Post reply on HN