diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..14be8d7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: Rust CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install latest stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose + + - name: Check formatting + run: cargo fmt -- --check + + - name: Run clippy + run: cargo clippy -- -D warnings + + - name: Check + run: cargo check + diff --git a/src/lib.rs b/src/lib.rs index 568ca3e..eec96ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,27 +1,28 @@ #![allow(non_upper_case_globals)] -/// This is implementation of Silding Bloom Filter +/// This is implementation of Silding Bloom Filter. /// -/// * Sub-Filters: The main Bloom filter is divided into N sub-filters: BF_1, BF_2, …, BF_N . -/// * Time Windows: Each sub-filter corresponds to a fixed time window T (e.g., 1 minute). -/// * Rotation Mechanism: Sub-filters are rotated in a circular manner to represent sliding -/// time intervals. +/// Features: +/// * Sub-Filters: The main Bloom filter is divided into N sub-filters: BF_1, BF_2, …, BF_N . +/// * Time Windows: Each sub-filter corresponds to a fixed time window T (e.g., 1 minute). +/// * Rotation Mechanism: Sub-filters are rotated in a circular manner to represent sliding +/// time intervals. /// /// Insertion: -/// * When an element is added at time t , it is inserted into the current sub-filter BF_{current}. -/// * Hash the element using the standard Bloom filter hash functions and set the bits in BF_{current} . +/// * When an element is added at time t , it is inserted into the current sub-filter BF_{current}. +/// * Hash the element using the standard Bloom filter hash functions and set the bits in BF_{current} . /// Query: -/// * To check if an element is in the filter, perform the query against all active sub-filters. -/// * If all the required bits are set in any sub-filter, the element is considered present. +/// * To check if an element is in the filter, perform the query against all active sub-filters. +/// * If all the required bits are set in any sub-filter, the element is considered present. /// Expiration: -/// * At each time interval T , the oldest sub-filter BF_{oldest} is cleared. -/// * The cleared sub-filter becomes the new BF_{current} for incoming elements. -/// * This effectively removes elements that were only in BF_{oldest} , thus expiring them. +/// * At each time interval T , the oldest sub-filter BF_{oldest} is cleared. +/// * The cleared sub-filter becomes the new BF_{current} for incoming elements. +/// * This effectively removes elements that were only in BF_{oldest} , thus expiring them. /// /// Obvious problems: -/// * False Positives: As elements may exist in multiple sub-filters, -/// the probability of false positives can increase. -/// * Synchronization: In concurrent environments, care must be taken to synchronize -/// access during sub-filter rotation. +/// * False Positives: As elements may exist in multiple sub-filters, +/// the probability of false positives can increase. +/// * Synchronization: In concurrent environments, care must be taken to synchronize +/// access during sub-filter rotation. use bitvec::prelude::*; use fnv::FnvHasher; use murmur3::murmur3_32; @@ -62,7 +63,6 @@ pub trait BitVector { /// The hash function computes `num_hashes` hash indices for the given `item`, /// ensuring each index is within the range `[0, capacity)`. These indices are /// used to set or check bits in the Bloom filter's bit vector. -// type HashFunction = dyn Fn(&[u8], usize, usize) -> Vec + Send + Sync; type HashFunction = fn(&[u8], usize, usize) -> Vec; fn hash_murmur32(key: &[u8]) -> u32 {