From fe21a4783502e49f4f0074dc9fc757b013f784e3 Mon Sep 17 00:00:00 2001 From: ppoliani Date: Sun, 28 Jan 2024 11:32:41 +0200 Subject: [PATCH] chore: run cargo fmt --- src/capped_hashmap.rs | 30 ++++++++++++++++-------------- src/committee/node.rs | 5 ++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/capped_hashmap.rs b/src/capped_hashmap.rs index f2df036..a2931d6 100644 --- a/src/capped_hashmap.rs +++ b/src/capped_hashmap.rs @@ -1,30 +1,31 @@ use std::{ - hash::Hash, cmp::Eq, + cmp::Eq, collections::{HashMap, VecDeque}, + hash::Hash, }; pub struct CappedHashMap where - K: Hash + Eq + Copy + Clone + K: Hash + Eq + Copy + Clone, { inner: HashMap, last_tasks: VecDeque, } -impl CappedHashMap +impl CappedHashMap where K: Hash + Eq + Copy + Clone, { const MAX_LEN: usize = 100; pub fn new() -> Self { - Self { - inner: HashMap::with_capacity(Self::MAX_LEN), - last_tasks: VecDeque::with_capacity(Self::MAX_LEN), - } + Self { + inner: HashMap::with_capacity(Self::MAX_LEN), + last_tasks: VecDeque::with_capacity(Self::MAX_LEN), + } } - /// Inserts an new item to the collection. Return Some(key) where key is the + /// Inserts an new item to the collection. Return Some(key) where key is the /// key that was removed when we reach the max capacity. Otherwise returns None. pub fn insert(&mut self, k: K, v: V) -> Option { self.last_tasks.push_front(k); @@ -34,21 +35,22 @@ where let key = self.last_tasks.pop_back().unwrap(); self.remove(&key); - return Some(key) + return Some(key); } - + self.inner.insert(k, v); - + None } /// Removes a key from the map, returning the value at the key if the key was previously in the map. pub fn remove(&mut self, k: &K) -> Option { let Some(v) = self.inner.remove(k) else { - return None + return None; }; - - self.last_tasks = self.last_tasks + + self.last_tasks = self + .last_tasks .iter() .filter(|key| *key != k) .map(|key| *key) diff --git a/src/committee/node.rs b/src/committee/node.rs index bbeb58d..5f81358 100644 --- a/src/committee/node.rs +++ b/src/committee/node.rs @@ -17,7 +17,10 @@ use rand::thread_rng; use serde::{Deserialize, Serialize}; use crate::{ - bob_request::{BobRequest, SmartContract}, capped_hashmap::CappedHashMap, frost, mpc_sign_tx::get_digest_to_hash + bob_request::{BobRequest, SmartContract}, + capped_hashmap::CappedHashMap, + frost, + mpc_sign_tx::get_digest_to_hash, }; //