Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cuckoo filter instead of Bloom filter #26

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linear_solver"
version = "0.2.1"
version = "0.2.2"
authors = ["Sven Nilsen <[email protected]>"]
edition = "2018"
keywords = ["linear", "solver", "theorem", "proving", "reasoning"]
Expand All @@ -13,4 +13,4 @@ documentation = "https://docs.rs/linear_solver"
categories = ["algorithms", "science"]

[dependencies]
bloom = "0.3.2"
cuckoofilter = "0.3.2"
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,12 @@
//! if it's minimum set of facts does not equals `false`.
//!

extern crate bloom;
extern crate cuckoofilter;

use cuckoofilter::CuckooFilter;
use std::collections::HashSet;
use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
use bloom::{ASMS, BloomFilter};

/// Tells the solver how to treat inference.
pub enum Inference<T> {
Expand Down Expand Up @@ -417,12 +418,11 @@ pub fn solve_minimum<T: Clone + PartialEq + Eq + Hash>(
cache.insert(s.clone());
}

// Bloom filter of previous sets of facts.
// Cuckoo filter of previous sets of facts.
// Used to detect whether a given set of facts has already been inferred.
// Set to a value such that a false positive never happens in practice.
let false_positive_rate = 0.00000001;
let expected_num_items = 1000000000;
let mut filter = BloomFilter::with_rate(false_positive_rate,expected_num_items);
// Set to a value such that a false positive likely does not happen in practice.
let filter_capacity = 1 << 22;
let mut filter: CuckooFilter<DefaultHasher> = CuckooFilter::with_capacity(filter_capacity);

let mut state = State::Solving;

Expand All @@ -431,7 +431,7 @@ pub fn solve_minimum<T: Clone + PartialEq + Eq + Hash>(
State::Solving => {
if filter.contains(&facts) {
state = State::SearchMinimum(facts.clone());
filter = BloomFilter::with_rate(false_positive_rate,expected_num_items);
filter = CuckooFilter::with_capacity(filter_capacity);
}
}
State::SearchMinimum(ref fa) if filter.contains(&facts) => {
Expand All @@ -447,7 +447,7 @@ pub fn solve_minimum<T: Clone + PartialEq + Eq + Hash>(
}
_ => {}
}
filter.insert(&facts);
filter.add(&facts);
if let Some(x) = infer(&cache, &facts) {
match x {
Inference::ManyTrue {from} => {
Expand Down