Skip to content

Commit 67f4309

Browse files
Merge #119
119: rework features r=crepererum a=crepererum Co-authored-by: Marco Neumann <marco@crepererum.net>
2 parents 08f8a38 + 706353c commit 67f4309

File tree

6 files changed

+84
-15
lines changed

6 files changed

+84
-15
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,53 @@ jobs:
3333
toolchain: ${{ matrix.rust }}
3434
override: true
3535

36+
- name: Cache
37+
uses: Swatinem/rust-cache@v1
38+
39+
- name: Install cargo-hack
40+
uses: actions-rs/cargo@v1.0.3
41+
with:
42+
command: install
43+
args: cargo-hack
44+
3645
- name: cargo fmt
3746
uses: actions-rs/cargo@v1.0.3
3847
with:
3948
command: fmt
4049
args: --all -- --check
4150

51+
- name: cargo check (feature powerset)
52+
uses: actions-rs/cargo@v1.0.3
53+
with:
54+
command: hack
55+
args: check --feature-powerset --no-dev-deps --optional-deps --workspace
56+
4257
- name: cargo build
4358
uses: actions-rs/cargo@v1.0.3
4459
with:
4560
command: build
46-
args: --verbose --all
61+
args: --verbose --all-features
62+
63+
- name: cargo clippy
64+
uses: actions-rs/cargo@v1.0.3
65+
with:
66+
command: clippy
67+
args: --verbose --all-features --all-targets --workspace
4768

4869
- name: cargo test
4970
uses: actions-rs/cargo@v1.0.3
5071
with:
5172
command: test
52-
args: --verbose --all
73+
args: --verbose --all-features --workspace
5374

5475
- name: cargo doc
5576
uses: actions-rs/cargo@v1.0.3
5677
with:
5778
command: doc
58-
args: --verbose --all
79+
args: --verbose --all-features --workspace
5980

6081
- name: cargo bench
6182
uses: actions-rs/cargo@v1.0.3
6283
with:
6384
command: bench
64-
args: --verbose --all -- --test
85+
args: --verbose --all-features --workspace -- --test

Cargo.toml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ readme = "README.md"
1717
edition = "2021"
1818

1919
[dependencies]
20-
fixedbitset = "0.4"
21-
num-traits = "^0.2.4"
22-
rand = "0.8"
23-
succinct = "^0.5"
24-
25-
[dependencies.bytecount]
26-
version = "0.6"
27-
features = ["runtime-dispatch-simd"]
20+
bytecount = { version = "0.6", features = ["runtime-dispatch-simd"], optional = true }
21+
fixedbitset = { version = "0.4", optional = true }
22+
num-traits = { version = "^0.2.4", optional = true }
23+
rand = { version = "0.8", optional = true }
24+
succinct = { version = "^0.5", optional = true }
2825

2926
[dev-dependencies]
3027
criterion = "0.3"
3128
rand_chacha = "0.3"
3229
rand_distr = "0.4"
3330

31+
[features]
32+
default = [
33+
"bytecount",
34+
"fixedbitset",
35+
"num-traits",
36+
"rand",
37+
"succinct",
38+
]
39+
3440
[[bench]]
3541
name = "filters"
3642
harness = false

src/filters/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
//! Filters, Approximate Membership Queries (AMQs).
22
3+
#[cfg(feature = "fixedbitset")]
34
pub mod bloomfilter;
5+
46
pub mod compat;
7+
8+
#[cfg(all(feature = "rand", feature = "succinct"))]
59
pub mod cuckoofilter;
10+
11+
#[cfg(all(feature = "fixedbitset", feature = "succinct"))]
612
pub mod quotientfilter;
713

814
use std::fmt::Debug;

src/helpers.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1+
#![allow(dead_code)]
12
use std::mem;
23

3-
use num_traits::Zero;
44
use succinct::storage::BlockType;
55
use succinct::IntVector;
66

7+
/// Our own version of `num_traits::Zero` so we don't need to depend on it just for the two types.
8+
pub(crate) trait NumZero {
9+
fn create_zero() -> Self;
10+
}
11+
12+
impl NumZero for usize {
13+
fn create_zero() -> Self {
14+
0
15+
}
16+
}
17+
18+
impl NumZero for u64 {
19+
fn create_zero() -> Self {
20+
0
21+
}
22+
}
23+
724
/// Quicker all-zero initialization of an IntVector.
825
pub(crate) fn all_zero_intvector<T>(element_bits: usize, len: usize) -> IntVector<T>
926
where
10-
T: BlockType + Zero,
27+
T: BlockType + NumZero,
1128
{
1229
let n_blocks = {
1330
let bits = mem::size_of::<T>()
@@ -23,5 +40,5 @@ where
2340
blocks
2441
}
2542
};
26-
IntVector::block_with_fill(element_bits, n_blocks, T::zero())
43+
IntVector::block_with_fill(element_bits, n_blocks, T::create_zero())
2744
}

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,34 @@
1919
#![deny(unsafe_code)]
2020
#![deny(unused_extern_crates)]
2121

22+
#[cfg(feature = "num-traits")]
2223
pub use num_traits;
24+
25+
#[cfg(feature = "rand")]
2326
pub use rand;
2427

28+
#[cfg(feature = "num-traits")]
2529
pub mod countminsketch;
30+
2631
pub mod filters;
32+
2733
pub mod hash_utils;
34+
35+
#[cfg(feature = "succinct")]
2836
mod helpers;
37+
38+
#[cfg(feature = "bytecount")]
2939
pub mod hyperloglog;
40+
41+
#[cfg(feature = "bytecount")]
3042
mod hyperloglog_data;
43+
44+
#[cfg(feature = "rand")]
3145
pub mod reservoirsampling;
46+
47+
#[cfg(feature = "rand")]
3248
pub mod tdigest;
49+
3350
pub mod topk;
3451

3552
#[cfg(test)]

src/topk/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//! Top-K, store `k` most frequent data points in stream.
2+
#[cfg(feature = "num-traits")]
23
pub mod cmsheap;
4+
35
pub mod lossycounter;

0 commit comments

Comments
 (0)