Skip to content

Commit

Permalink
chore: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ppoliani committed Jan 28, 2024
1 parent bab9e7a commit fe21a47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
30 changes: 16 additions & 14 deletions src/capped_hashmap.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
use std::{
hash::Hash, cmp::Eq,
cmp::Eq,
collections::{HashMap, VecDeque},
hash::Hash,
};

pub struct CappedHashMap<K, V>
where
K: Hash + Eq + Copy + Clone
K: Hash + Eq + Copy + Clone,
{
inner: HashMap<K, V>,
last_tasks: VecDeque<K>,
}

impl <K, V> CappedHashMap <K, V>
impl<K, V> CappedHashMap<K, V>
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<K> {
self.last_tasks.push_front(k);
Expand All @@ -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<V> {
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)
Expand Down
5 changes: 4 additions & 1 deletion src/committee/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

//
Expand Down

0 comments on commit fe21a47

Please sign in to comment.