Skip to content

Commit c76063c

Browse files
Copilotsiriak
andcommitted
Revert unnecessary code changes, keep only lint allow for clippy large_stack_arrays warning
Co-authored-by: siriak <[email protected]>
1 parent b6f6283 commit c76063c

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/data_structures/probabilistic/bloom_filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ pub trait BloomFilter<Item: Hash> {
2424
#[allow(dead_code)]
2525
#[derive(Debug)]
2626
struct BasicBloomFilter<const CAPACITY: usize> {
27-
vec: Vec<bool>,
27+
vec: [bool; CAPACITY],
2828
}
2929

3030
impl<const CAPACITY: usize> Default for BasicBloomFilter<CAPACITY> {
3131
fn default() -> Self {
3232
Self {
33-
vec: vec![false; CAPACITY],
33+
vec: [false; CAPACITY],
3434
}
3535
}
3636
}

src/data_structures/probabilistic/count_min_sketch.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ pub trait CountMinSketch {
9090
/// But an interesting property is that the count we return for "TEST" cannot be underestimated
9191
pub struct HashCountMinSketch<Item: Hash, const WIDTH: usize, const DEPTH: usize> {
9292
phantom: std::marker::PhantomData<Item>, // just a marker for Item to be used
93-
counts: Vec<[usize; WIDTH]>,
94-
hashers: Vec<RandomState>,
93+
counts: [[usize; WIDTH]; DEPTH],
94+
hashers: [RandomState; DEPTH],
9595
}
9696

9797
impl<Item: Hash, const WIDTH: usize, const DEPTH: usize> Debug
@@ -106,13 +106,11 @@ impl<T: Hash, const WIDTH: usize, const DEPTH: usize> Default
106106
for HashCountMinSketch<T, WIDTH, DEPTH>
107107
{
108108
fn default() -> Self {
109-
let hashers = std::iter::repeat_with(RandomState::new)
110-
.take(DEPTH)
111-
.collect();
109+
let hashers = std::array::from_fn(|_| RandomState::new());
112110

113111
Self {
114112
phantom: std::marker::PhantomData,
115-
counts: vec![[0; WIDTH]; DEPTH],
113+
counts: [[0; WIDTH]; DEPTH],
116114
hashers,
117115
}
118116
}
@@ -185,14 +183,14 @@ mod tests {
185183
let mut sketch: HashCountMinSketch<&str, 5, 7> = HashCountMinSketch::default();
186184
sketch.increment("test");
187185
// Inspect internal state:
188-
for counts in &sketch.counts {
186+
for counts in sketch.counts {
189187
let zeroes = counts.iter().filter(|count| **count == 0).count();
190188
assert_eq!(4, zeroes);
191189
let ones = counts.iter().filter(|count| **count == 1).count();
192190
assert_eq!(1, ones);
193191
}
194192
sketch.increment("test");
195-
for counts in &sketch.counts {
193+
for counts in sketch.counts {
196194
let zeroes = counts.iter().filter(|count| **count == 0).count();
197195
assert_eq!(4, zeroes);
198196
let twos = counts.iter().filter(|count| **count == 2).count();

0 commit comments

Comments
 (0)