Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
bloom_filter_example.C File Reference

Bloom filter in Aleph-w (probabilistic set membership, false positives, and tuning). More...

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <tclap/CmdLine.h>
#include <bloom-filter.H>
Include dependency graph for bloom_filter_example.C:

Go to the source code of this file.

Functions

void print_section (const string &title)
 
void print_subsection (const string &title)
 
void demo_basic ()
 
void demo_false_positives ()
 
void demo_optimal_params ()
 
void demo_spell_checker ()
 
void demo_cache_filter ()
 
void demo_space_comparison ()
 
int main (int argc, char *argv[])
 

Detailed Description

Bloom filter in Aleph-w (probabilistic set membership, false positives, and tuning).

Overview

This example demonstrates Aleph-w's Bloom_Filter<T>: a probabilistic data structure for set membership queries.

  • If it says **"not present"**: the element is definitely not in the set.
  • If it says **"present"**: the element is probably in the set (false positives are possible).

The program is structured as a set of independent demos:

  • basic insert/query usage
  • observed false positives
  • parameter tuning and sizing intuition
  • spell-check / cache-filter style examples
  • space comparison vs storing elements

Data model used by this example

  • Bloom filter type: Bloom_Filter<string>
  • Parameters:
    • m: bit array size
    • k: number of hash functions

Usage / CLI

This example uses TCLAP and a selector:

  • --section / -s <section>: run only one section. Valid values: basic, fp, params, spell, cache, space, all (default).
  • --help: show help.
# Run all demos
./bloom_filter_example
# Run a specific section
./bloom_filter_example --section basic
./bloom_filter_example --section fp
./bloom_filter_example --section params
./bloom_filter_example --section spell
./bloom_filter_example --section cache
./bloom_filter_example --section space
# Short form
./bloom_filter_example -s space
# Show help
./bloom_filter_example --help

Complexity

Let k be the number of hash functions.

  • insert: O(k)
  • query: O(k)
  • space: O(m) bits

Pitfalls and edge cases

  • Standard Bloom filters do not support deletion (use a counting variant).
  • Poor parameter choices (too small m, too large/small k) increase the false positive rate.

References / see also

Author
Leandro Rabindranath León
Date
2024

Definition in file bloom_filter_example.C.

Function Documentation

◆ demo_basic()

void demo_basic ( )

◆ demo_cache_filter()

void demo_cache_filter ( )

◆ demo_false_positives()

void demo_false_positives ( )

Definition at line 162 of file bloom_filter_example.C.

References exp(), Aleph::filter(), Aleph::maps(), pow(), print_section(), and print_subsection().

Referenced by main().

◆ demo_optimal_params()

void demo_optimal_params ( )

Definition at line 214 of file bloom_filter_example.C.

References ceil(), exp(), log(), Aleph::maps(), pow(), print_section(), and print_subsection().

Referenced by main().

◆ demo_space_comparison()

void demo_space_comparison ( )

Definition at line 380 of file bloom_filter_example.C.

References log(), Aleph::maps(), and print_section().

Referenced by main().

◆ demo_spell_checker()

void demo_spell_checker ( )

◆ main()

◆ print_section()

void print_section ( const string &  title)

◆ print_subsection()

void print_subsection ( const string &  title)