Crate cuckoofilter_mmap

Crate cuckoofilter_mmap 

Source
Expand description

A disk-based Cuckoo Filter implementation using memory-mapped files.

This library provides a Cuckoo Filter that stores its data on disk, making it suitable for large datasets that may not fit into RAM. It uses memmap2 for efficient file I/O.

§Features

  • insert: Add an item to the filter.
  • contains: Check if an item is in the filter.
  • delete: Remove an item from the filter.
  • builder: Create a new, empty filter backed by a file with custom parameters.
  • open: Open an existing filter from a file.

§Example

use cuckoofilter_mmap::{CuckooFilter, FlushMode};
use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = "my_filter.db";
    let capacity = 1_000_000;

    // Create a new filter using the builder
    let mut filter = CuckooFilter::<str>::builder(capacity)
        .fingerprint_size(2)
        .bucket_size(4)
        .flush_mode(FlushMode::None)
        .build(path)?;

    // Insert an item
    let item = "hello world";
    if filter.insert(item)? {
        println!("Item inserted successfully.");
    }

    // Check for the item
    assert!(filter.contains(item));

    // Delete the item
    assert!(filter.delete(item)?);
    assert!(!filter.contains(item));

    // Clean up the file
    fs::remove_file(path)?;

    Ok(())
}

Structs§

ConcurrentCuckooFilter
A thread-safe, concurrent version of the Cuckoo Filter.
CuckooFilter
The main Cuckoo Filter structure.
CuckooFilterBuilder
A builder for creating CuckooFilter instances with custom parameters.

Enums§

CuckooError
Custom error types for the Cuckoo Filter.
FlushMode
Defines the flushing strategy for the Cuckoo Filter.

Traits§

Item
A hashable type that can be used with the Cuckoo Filter.