Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
chengmiaomiao.123 committed Jan 9, 2024
1 parent 98b1479 commit 3de3fc0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions volo-thrift/src/transport/multiplex/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use tokio::sync::Mutex;
const SHARD_COUNT: usize = 64;

pub struct TxHashMap<T> {
shared: [Mutex<fxhash::FxHashMap<i32, T>>; SHARD_COUNT],
sharded: [Mutex<fxhash::FxHashMap<i32, T>>; SHARD_COUNT],
}

impl<T> Default for TxHashMap<T> {
fn default() -> Self {
TxHashMap {
shared: array::from_fn(|_| Default::default()),
sharded: array::from_fn(|_| Default::default()),
}
}
}
Expand All @@ -21,14 +21,14 @@ where
T: Sized,
{
pub async fn remove(&self, key: &i32) -> Option<T> {
self.shared[(*key % (SHARD_COUNT as i32)) as usize]
self.sharded[(*key % (SHARD_COUNT as i32)) as usize]
.lock()
.await
.remove(key)
}

pub async fn is_empty(&self) -> bool {
for s in self.shared.iter() {
for s in self.sharded.iter() {
if !s.lock().await.is_empty() {
return false;
}
Expand All @@ -37,15 +37,15 @@ where
}

pub async fn insert(&self, key: i32, value: T) -> Option<T> {
self.shared[(key % (SHARD_COUNT as i32)) as usize]
self.sharded[(key % (SHARD_COUNT as i32)) as usize]
.lock()
.await
.insert(key, value)
}

pub async fn for_all_drain(&self, mut f: impl FnMut(T) -> ()) {
for shared in self.shared.iter() {
let mut s = shared.lock().await;
for sharded in self.sharded.iter() {
let mut s = sharded.lock().await;
for data in s.drain() {
f(data.1)
}
Expand Down

0 comments on commit 3de3fc0

Please sign in to comment.