Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
cuckoo_filter_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9*/
10
11#include <iostream>
12#include <string>
13#include <vector>
14#include <iomanip>
15#include <cuckoo-filter.H>
16
17using namespace std;
18using namespace Aleph;
19
20int main()
21{
22 cout << "Aleph-w Cuckoo Filter Example" << endl;
23 cout << "=============================" << endl << endl;
24
25 // Create a Cuckoo Filter for around 1000 items
26 // Using 12 bits per fingerprint and 4 entries per bucket (default)
28
29 // 1. Basic insertions
30 vector<string> items = {"apple", "banana", "cherry", "date", "elderberry"};
31
32 cout << "Inserting items: ";
33 for (const auto& item : items) {
34 cout << item << " ";
35 filter.insert(item);
36 }
37 cout << endl;
38
39 cout << "Filter size: " << filter.size() << endl;
40 cout << "Load factor: " << fixed << setprecision(4) << filter.load_factor() << endl << endl;
41
42 // 2. Lookups
43 cout << "Checking membership:" << endl;
44 vector<string> queries = {"apple", "banana", "fig", "grape"};
45 for (const auto& query : queries) {
46 cout << " - " << setw(10) << query << ": "
47 << (filter.contains(query) ? "LIKELY PRESENT" : "DEFINITELY ABSENT") << endl;
48 }
49 cout << endl;
50
51 // 3. Deletions
52 cout << "Removing 'banana'..." << endl;
53 if (filter.remove("banana")) {
54 cout << "'banana' was removed successfully." << endl;
55 }
56
57 cout << "Checking 'banana' again: "
58 << (filter.contains("banana") ? "LIKELY PRESENT" : "DEFINITELY ABSENT") << endl;
59 cout << "Filter size after removal: " << filter.size() << endl << endl;
60
61 // 4. Higher load example
62 cout << "Filling the filter with more items..." << endl;
63 for (int i = 0; i < 800; ++i) {
64 filter.insert("item_" + to_string(i));
65 }
66
67 cout << "Final filter size: " << filter.size() << endl;
68 cout << "Final load factor: " << fixed << setprecision(4) << filter.load_factor() << endl;
69
70 if (filter.load_factor() > 0.8) {
71 cout << "Notice high load factor supported by Cuckoo Filter!" << endl;
72 }
73
74 return 0;
75}
Industrial-grade Cuckoo Filter implementation.
Probabilistic set membership with Cuckoo filters.
int main()
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Definition ah-date.H:140
STL namespace.