Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbapple/libfilter
High-speed Bloom filters and taffy filters for C, C++, and Java
https://github.com/jbapple/libfilter
bloom-filter bloom-filters bloomfilter c cpp data-structures java library
Last synced: 12 days ago
JSON representation
High-speed Bloom filters and taffy filters for C, C++, and Java
- Host: GitHub
- URL: https://github.com/jbapple/libfilter
- Owner: jbapple
- License: apache-2.0
- Created: 2020-05-23T22:07:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-09T23:57:38.000Z (about 1 year ago)
- Last Synced: 2023-08-10T00:44:37.832Z (about 1 year ago)
- Topics: bloom-filter, bloom-filters, bloomfilter, c, cpp, data-structures, java, library
- Language: C++
- Homepage:
- Size: 2.12 MB
- Stars: 25
- Watchers: 4
- Forks: 6
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
![](https://github.com/jbapple/libfilter/workflows/unit-tests/badge.svg?branch=master)
This repository provides implementations of various Bloom filters and
taffy filters for C, C++, Java, Python, and Go.If you need a basic filter and you know ahead of time which keys will be in it, use a static filter.
If you don't know what the keys will be, but you know approximately how many there are, use a block filter.
Otherwise, use a taffy filter, which can grow as you add more keys to it.
Example usage of block filter in C:
```C
#includeunsigned ndv = 1000000;
double fpp = 0.0065;
uint64_t hash = 0xfeedbadbee52b055;libfilter_block filter;
unsigned bytes = libfilter_block_bytes_needed(ndv, fpp);
libfilter_block_init(bytes, &filter);
libfilter_block_add_hash(hash, &filter);
assert(libfilter_block_find_hash(hash, &filter));
libfilter_block_destruct(&filter);
```in C++:
```C++
#includeunsigned ndv = 1000000;
double fpp = 0.0065;
uint64_t hash = 0xfeedbadbee52b055;auto filter = filter::BlockFilter::CreateWithNdvFpp(ndv, fpp);
filter.InsertHash(hash);
assert(filter.FindHash(hash));
```in Java
```Java
import com.github.jbapple.libfilter.BlockFilter;int ndv = 1000000;
double fpp = 0.0065;
long hash = (((long) 0xfeedbadb) << 32) | (long) 0xee52b055;BlockFilter = BlockFilter.CreateWithNdvFpp(ndv, fpp);
filter.AddHash64(hash);
assert filter.FindHash64(hash)
```in Go
```Go
import ("github.com/jbapple/libfilter")b := NewBlockFilter(BlockBytesNeeded(1000000, 0.0065))
var hash uint64
hash = 0xfeedbadbee52b055
b.AddHash(hash)
if !b.FindHash(hash) {
panic("uhoh!")
}
```in Python
```Python
import blockb = block.Block(1000000, 0.0065)
hash = 0xfeedbadbee52b055
b += hash
assert (hash in b)
```To install:
```shell
make
# probably needs a sudo:
make install
make java-world
mvn -f ./java/ install -Dmaven.test.skip=true
[optional: copy java/target/libfilter-*.jar to your classpath]
make python-world
make go-world
```The C and C++ libraries can also be installed with CMake:
```shell
cmake -B build -S . -DCMAKE_INSTALL_PATH=
cmake --build build
# probably needs a sudo:
cmake --install build
```The library targets are exported and can be used in `CMakeLists.txt`:
```cmake
find_package(libfilter)
# The C API:
target_link_libraries(mylib PRIVATE libfilter::c)
# The C++ API:
target_link_libraries(mylib PRIVATE libfilter::cxx)
```