Skip to content

Commit

Permalink
connect: use small_rng, derive Default
Browse files Browse the repository at this point in the history
  • Loading branch information
photovoltex committed Jan 23, 2025
1 parent 9767e3d commit 7390a18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion connect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"
futures-util = "0.3"
log = "0.4"
protobuf = "3.5"
rand = "0.8"
rand = { version = "0.8", default-features = false, features = ["small_rng"] }
serde_json = "1.0"
thiserror = "2.0"
tokio = { version = "1", features = ["macros", "parking_lot", "sync"] }
Expand Down
14 changes: 4 additions & 10 deletions connect/src/shuffle_vec.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rand::{Rng, SeedableRng};
use rand::{rngs::SmallRng, Rng, SeedableRng};
use std::{
ops::{Deref, DerefMut},
vec::IntoIter,
};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct ShuffleVec<T> {
vec: Vec<T>,
indices: Option<Vec<usize>>,
Expand Down Expand Up @@ -45,12 +45,6 @@ impl<T> From<Vec<T>> for ShuffleVec<T> {
}
}

impl<T> Default for ShuffleVec<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> ShuffleVec<T> {
pub fn new() -> Self {
Self {
Expand All @@ -60,7 +54,7 @@ impl<T> ShuffleVec<T> {
}

pub fn shuffle_with_seed(&mut self, seed: u64) {
self.shuffle_with_rng(rand::rngs::StdRng::seed_from_u64(seed))
self.shuffle_with_rng(SmallRng::seed_from_u64(seed))
}

pub fn shuffle_with_rng(&mut self, mut rng: impl Rng) {
Expand Down Expand Up @@ -97,7 +91,7 @@ impl<T> ShuffleVec<T> {

#[cfg(test)]
mod test {
use crate::shuffle_vec::ShuffleVec;
use super::*;
use rand::Rng;

#[test]
Expand Down

0 comments on commit 7390a18

Please sign in to comment.