Skip to content

Commit

Permalink
make clippy happy + basic rust ci
Browse files Browse the repository at this point in the history
  • Loading branch information
oiwn committed Sep 14, 2024
1 parent dfa4fc6 commit e8ae2a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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

34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<u32> + Send + Sync;
type HashFunction = fn(&[u8], usize, usize) -> Vec<u32>;

fn hash_murmur32(key: &[u8]) -> u32 {
Expand Down

0 comments on commit e8ae2a3

Please sign in to comment.