https://github.com/terenstare/modern_bloom
Bloom filters for modern C++.
https://github.com/terenstare/modern_bloom
bloom-filter cpp cpp17
Last synced: 12 months ago
JSON representation
Bloom filters for modern C++.
- Host: GitHub
- URL: https://github.com/terenstare/modern_bloom
- Owner: TerensTare
- License: mit
- Created: 2024-02-13T21:16:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T13:52:28.000Z (about 2 years ago)
- Last Synced: 2025-03-28T02:05:17.936Z (about 1 year ago)
- Topics: bloom-filter, cpp, cpp17
- Language: C++
- Homepage:
- Size: 58.6 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Bloom filters for modern C++
This repo contains a simple implementation of a bloom filter in C++17.
## Introduction
A bloom filter is a probabilistic data structure that is used to test whether an element is a member of a set. False positives are possible, but false negatives are not. Elements can be added to the set, but not removed.
## Usage
```cpp
#include
struct my_article final
{
std::string title;
std::string author;
std::string content;
};
struct article_hash final
{
inline std::size_t operator()(my_article const& article) const noexcept
{
return std::hash{}(article.title);
}
};
int main()
{
// Assume that the average user can read 1000 articles on average.
tnt::dynamic_bloom read_articles(1'000);
// Our user reads an article.
my_article article1{"The C++ Programming Language", "Bjarne Stroustrup", "The C++ Programming Language is a computer programming book first published in October 1985."};
read_articles.insert(article1);
std::vector suggestions;
for (auto const &article : )
{
if (!read_articles.matches(article))
{
// Add non-read articles to the suggestions list.
suggestions.push_back(article);
}
}
}
```
## Integration
This is a header-only library. You can use it by simply copying the files in the `include` directory to your project. Then include one of the header files in your source code as following.
```cpp
// for fixed-size bloom filter
#include // tnt::static_bloom
// for dynamically-sized bloom filter
#include // tnt::dynamic_bloom
```
## Requirements
The library is written in C++17, so you need a compiler that supports at least C++17. However, the tests are written in C++20, so you need a compiler that supports at least C++20 to run the tests. Furthermore, you need CMake 3.14 or newer to build the tests.
## Tests
To run the tests, you need to have CMake 3.14 or newer installed on your system. Then, you can run the following commands.
```bash
mkdir build
cd build
cmake ..
cmake --build . --target run_tests
```
## License
Code is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.