Skip to content

Commit 70418e5

Browse files
committed
fix clippy and a deprecation warnings
1 parent d2d7b0b commit 70418e5

File tree

9 files changed

+77
-64
lines changed

9 files changed

+77
-64
lines changed

benches/filters.rs

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ extern crate pdatastructs;
44

55
use std::collections::HashSet;
66

7-
use criterion::{Bencher, Criterion, Fun, ParameterizedBenchmark};
7+
use criterion::{Bencher, BenchmarkId, Criterion};
88
use pdatastructs::filters::bloomfilter::BloomFilter;
99
use pdatastructs::filters::cuckoofilter::CuckooFilter;
1010
use pdatastructs::filters::quotientfilter::QuotientFilter;
1111
use pdatastructs::filters::Filter;
1212
use pdatastructs::rand::SeedableRng;
1313
use rand_chacha::ChaChaRng;
1414

15+
const ID_BLOOMFILTER: &str = "bloomfilter";
16+
const ID_CUCKOOFILTER: &str = "cuckoofilter";
17+
const ID_HASHSET: &str = "hashset";
18+
const ID_QUOTIENTFILTER: &str = "quotientfilter";
19+
1520
fn setup_bloomfilter() -> BloomFilter<u64> {
1621
let false_positive_rate = 0.02; // = 2%
1722
let expected_elements = 10_000;
@@ -71,49 +76,60 @@ where
7176
}
7277

7378
fn benchmarks_setup(c: &mut Criterion) {
74-
let functions = vec![
75-
Fun::new("bloomfilter", |b, _| run_setup(setup_bloomfilter, b)),
76-
Fun::new("cuckoofilter", |b, _| run_setup(setup_cuckoofilter, b)),
77-
Fun::new("hashset", |b, _| run_setup(setup_hashset, b)),
78-
Fun::new("quotientfilter", |b, _| run_setup(setup_quotientfilter, b)),
79-
];
80-
c.bench_functions("setup", functions, ());
79+
let mut g = c.benchmark_group("setup");
80+
81+
g.bench_function(ID_BLOOMFILTER, |b| run_setup(setup_bloomfilter, b));
82+
g.bench_function(ID_CUCKOOFILTER, |b| run_setup(setup_cuckoofilter, b));
83+
g.bench_function(ID_HASHSET, |b| run_setup(setup_hashset, b));
84+
g.bench_function(ID_QUOTIENTFILTER, |b| run_setup(setup_quotientfilter, b));
85+
86+
g.finish();
8187
}
8288

8389
fn benchmarks_insert_many(c: &mut Criterion) {
84-
let parameters = vec![4_000, 8_000, 12_000, 16_000, 20_000];
85-
let benchmark = ParameterizedBenchmark::new(
86-
"bloomfilter",
87-
|b, n| run_insert_many(setup_bloomfilter, b, *n),
88-
parameters,
89-
)
90-
.with_function("cuckoofilter", |b, n| {
91-
run_insert_many(setup_cuckoofilter, b, *n)
92-
})
93-
.with_function("hashset", |b, n| run_insert_many(setup_hashset, b, *n))
94-
.with_function("quotientfilter", |b, n| {
95-
run_insert_many(setup_quotientfilter, b, *n)
96-
})
97-
.sample_size(20);
98-
c.bench("insert_many", benchmark);
90+
let mut g = c.benchmark_group("insert_many");
91+
92+
g.sample_size(20);
93+
94+
for n in [4_000, 8_000, 12_000, 16_000, 20_000] {
95+
g.bench_with_input(BenchmarkId::new(ID_BLOOMFILTER, &n), &n, |b, n| {
96+
run_insert_many(setup_bloomfilter, b, *n)
97+
});
98+
g.bench_with_input(BenchmarkId::new(ID_CUCKOOFILTER, &n), &n, |b, n| {
99+
run_insert_many(setup_cuckoofilter, b, *n)
100+
});
101+
g.bench_with_input(BenchmarkId::new(ID_HASHSET, &n), &n, |b, n| {
102+
run_insert_many(setup_hashset, b, *n)
103+
});
104+
g.bench_with_input(BenchmarkId::new(ID_QUOTIENTFILTER, &n), &n, |b, n| {
105+
run_insert_many(setup_quotientfilter, b, *n)
106+
});
107+
}
108+
109+
g.finish();
99110
}
100111

101112
fn benchmarks_query_single(c: &mut Criterion) {
102-
let parameters = vec![4_000, 8_000];
103-
let benchmark = ParameterizedBenchmark::new(
104-
"bloomfilter",
105-
|b, n| run_query_single(setup_bloomfilter, b, *n),
106-
parameters,
107-
)
108-
.with_function("cuckoofilter", |b, n| {
109-
run_query_single(setup_cuckoofilter, b, *n)
110-
})
111-
.with_function("hashset", |b, n| run_query_single(setup_hashset, b, *n))
112-
.with_function("quotientfilter", |b, n| {
113-
run_query_single(setup_quotientfilter, b, *n)
114-
})
115-
.sample_size(20);
116-
c.bench("query_single", benchmark);
113+
let mut g = c.benchmark_group("query_single");
114+
115+
g.sample_size(20);
116+
117+
for n in [4_000, 8_000] {
118+
g.bench_with_input(BenchmarkId::new(ID_BLOOMFILTER, &n), &n, |b, n| {
119+
run_query_single(setup_bloomfilter, b, *n)
120+
});
121+
g.bench_with_input(BenchmarkId::new(ID_CUCKOOFILTER, &n), &n, |b, n| {
122+
run_query_single(setup_cuckoofilter, b, *n)
123+
});
124+
g.bench_with_input(BenchmarkId::new(ID_HASHSET, &n), &n, |b, n| {
125+
run_query_single(setup_hashset, b, *n)
126+
});
127+
g.bench_with_input(BenchmarkId::new(ID_QUOTIENTFILTER, &n), &n, |b, n| {
128+
run_query_single(setup_quotientfilter, b, *n)
129+
});
130+
}
131+
132+
g.finish();
117133
}
118134

119135
criterion_group!(

src/countminsketch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ where
216216
///
217217
/// Returns guessed count after addition.
218218
pub fn add(&mut self, obj: &T) -> C {
219-
self.add_n(&obj, &C::one())
219+
self.add_n(obj, &C::one())
220220
}
221221

222222
/// Add `n` to the counter of the given element.

src/filters/quotientfilter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::hash_map::DefaultHasher;
33
use std::collections::VecDeque;
44
use std::hash::{BuildHasher, BuildHasherDefault, Hash, Hasher};
55
use std::marker::PhantomData;
6-
use std::mem::size_of;
76

87
use fixedbitset::FixedBitSet;
98
use succinct::{IntVec, IntVecMut, IntVector};
@@ -290,10 +289,10 @@ where
290289
buildhasher: B,
291290
) -> Self {
292291
assert!(
293-
(bits_remainder > 0) && (bits_remainder <= size_of::<usize>() * 8),
292+
(bits_remainder > 0) && (bits_remainder <= (usize::BITS as usize)),
294293
"bits_remainder ({}) must be greater than 0 and smaller or equal than {}",
295294
bits_remainder,
296-
size_of::<usize>() * 8,
295+
usize::BITS,
297296
);
298297
assert!(
299298
bits_quotient > 0,

src/hash_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111
{
112112
let h1 = self.h_i(&obj, 0) % (self.m as u64);
113113
let h2 = self.h_i(&obj, 1) % (self.m as u64);
114-
HashIter::new(&self, h1, h2)
114+
HashIter::new(self, h1, h2)
115115
}
116116

117117
/// Set up `f`.

src/hyperloglog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ where
102102
/// Same as `new` but with a specific `BuildHasher`.
103103
pub fn with_hash(b: usize, buildhasher: B) -> Self {
104104
assert!(
105-
(b >= 4) & (b <= 18),
105+
(4..=18).contains(&b),
106106
"b ({}) must be larger or equal than 4 and smaller or equal than 18",
107107
b
108108
);
109109

110-
let m = (1 as usize) << b;
110+
let m = 1_usize << b;
111111
let registers = vec![0; m];
112112
Self {
113113
registers,
@@ -196,7 +196,7 @@ where
196196
const K: usize = 6;
197197
assert!(lookup_array.len() >= K);
198198
let mut neighbors = [0; K];
199-
for i in 0..K {
199+
for neighbor in &mut neighbors {
200200
let (right_instead_left, idx) = match (idx_left, idx_right) {
201201
(Some(i_left), Some(i_right)) => {
202202
// 2 candidates, find better one
@@ -218,7 +218,7 @@ where
218218
}
219219
_ => panic!("neighborhood search failed, this is bug!"),
220220
};
221-
neighbors[i] = idx;
221+
*neighbor = idx;
222222
if right_instead_left {
223223
idx_right = if idx < lookup_array.len() - 1 {
224224
Some(idx + 1)

src/hyperloglog_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4278,5 +4278,5 @@ pub(crate) const POW2MINX: [f64; 256] = [
42784278

42794279
#[test]
42804280
fn test_pow2minx() {
4281-
(0..256).for_each(|x| assert_eq!(POW2MINX[x as usize], 2f64.powi(-(i32::from(x)))))
4281+
(0..256).for_each(|x| assert_eq!(POW2MINX[x as usize], 2f64.powi(-x)))
42824282
}

src/tdigest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ where
414414

415415
#[inline(always)]
416416
fn interpolate(a: f64, b: f64, t: f64) -> f64 {
417-
debug_assert!((t >= 0.) && (t <= 1.));
417+
debug_assert!((0. ..=1.).contains(&t));
418418
debug_assert!(a <= b);
419419
t * b + (1. - t) * a
420420
}
@@ -853,7 +853,7 @@ where
853853
///
854854
/// Panics if the quantile is not in range `[0, 1]`.
855855
pub fn quantile(&self, q: f64) -> f64 {
856-
assert!((q >= 0.) && (q <= 1.), "q ({}) must be in [0, 1]", q);
856+
assert!((0. ..=1.).contains(&q), "q ({}) must be in [0, 1]", q);
857857

858858
// apply compression if required
859859
self.inner.borrow_mut().merge();

src/topk/cmsheap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ where
214214
///
215215
/// The result may contain less than `k` values if less than `k` unique data points where
216216
/// observed.
217-
pub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = T> {
217+
pub fn iter(&self) -> impl '_ + Iterator<Item = T> {
218218
self.tree.iter().map(|x| (*x.obj).clone())
219219
}
220220

@@ -324,10 +324,10 @@ mod tests {
324324
fn is_empty() {
325325
let cms = CountMinSketch::with_params(10, 20);
326326
let mut tk = CMSHeap::new(2, cms);
327-
assert_eq!(tk.is_empty(), true);
327+
assert!(tk.is_empty());
328328

329329
tk.add(0);
330-
assert_eq!(tk.is_empty(), false);
330+
assert!(!tk.is_empty());
331331
}
332332

333333
#[test]
@@ -337,7 +337,7 @@ mod tests {
337337
tk.add(0);
338338

339339
tk.clear();
340-
assert_eq!(tk.is_empty(), true);
340+
assert!(tk.is_empty());
341341

342342
tk.add(1);
343343
assert_eq!(tk.iter().collect::<Vec<u32>>(), vec![1]);

src/topk/lossycounter.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ where
264264
/// ```
265265
///
266266
/// The order of the elements is undefined.
267-
pub fn query<'a>(&'a self, threshold: f64) -> impl 'a + Iterator<Item = T> {
267+
pub fn query(&self, threshold: f64) -> impl '_ + Iterator<Item = T> {
268268
let bound = (((threshold - self.epsilon) * (self.n as f64)).ceil()).max(0.) as usize;
269269
self.known
270270
.iter()
@@ -340,7 +340,7 @@ mod tests {
340340
assert!(counter.add(42));
341341

342342
let mut data: Vec<u64> = counter.query(0.).collect();
343-
data.sort();
343+
data.sort_unstable();
344344
assert_eq!(data, vec![13, 42]);
345345
}
346346

@@ -352,7 +352,7 @@ mod tests {
352352
assert!(counter.add(42));
353353

354354
let mut data: Vec<u64> = counter.query(0.6).collect();
355-
data.sort();
355+
data.sort_unstable();
356356
assert_eq!(data, vec![13]);
357357
}
358358

@@ -369,7 +369,7 @@ mod tests {
369369
}
370370

371371
let mut data: Vec<u64> = counter.query(0.02).collect();
372-
data.sort();
372+
data.sort_unstable();
373373
assert_eq!(data, vec![7, 8, 9]);
374374
}
375375

@@ -385,11 +385,11 @@ mod tests {
385385
assert_eq!(counter2.n(), 2);
386386

387387
let mut data1: Vec<u64> = counter1.query(0.).collect();
388-
data1.sort();
388+
data1.sort_unstable();
389389
assert_eq!(data1, vec![13]);
390390

391391
let mut data2: Vec<u64> = counter2.query(0.).collect();
392-
data2.sort();
392+
data2.sort_unstable();
393393
assert_eq!(data2, vec![13, 42]);
394394
}
395395

@@ -401,8 +401,7 @@ mod tests {
401401

402402
counter.clear();
403403
assert_eq!(counter.n(), 0);
404-
let data: Vec<u64> = counter.query(0.).collect();
405-
assert!(data.is_empty());
404+
assert!(counter.query(0.).next().is_none());
406405

407406
assert!(counter.add(13));
408407
assert_eq!(counter.n(), 1);
@@ -421,7 +420,6 @@ mod tests {
421420

422421
assert!(counter.add(42));
423422
assert_eq!(counter.n(), 2);
424-
let data: Vec<u64> = counter.query(0.).collect();
425-
assert!(data.is_empty());
423+
assert!(counter.query(0.).next().is_none());
426424
}
427425
}

0 commit comments

Comments
 (0)