Skip to content

Commit

Permalink
refactor(s2n-quic-dc): put map impl behind trait
Browse files Browse the repository at this point in the history
  • Loading branch information
camshaft committed Oct 30, 2024
1 parent 01cbb44 commit 87ee143
Show file tree
Hide file tree
Showing 11 changed files with 1,260 additions and 1,044 deletions.
8 changes: 5 additions & 3 deletions dc/s2n-quic-dc/src/fixed_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use core::{
hash::Hash,
sync::atomic::{AtomicU8, Ordering},
};
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockUpgradableReadGuard};
use parking_lot::{RwLock, RwLockReadGuard, RwLockUpgradableReadGuard};
use std::{collections::hash_map::RandomState, hash::BuildHasher};

pub use parking_lot::MappedRwLockReadGuard as ReadGuard;

pub struct Map<K, V, S = RandomState> {
slots: Box<[Slot<K, V>]>,
hash_builder: S,
Expand Down Expand Up @@ -94,7 +96,7 @@ where
self.get_by_key(key).is_some()
}

pub fn get_by_key(&self, key: &K) -> Option<MappedRwLockReadGuard<'_, V>> {
pub fn get_by_key(&self, key: &K) -> Option<ReadGuard<'_, V>> {
self.slot_by_hash(key).get_by_key(key)
}
}
Expand Down Expand Up @@ -148,7 +150,7 @@ where
None
}

fn get_by_key(&self, needle: &K) -> Option<MappedRwLockReadGuard<'_, V>> {
fn get_by_key(&self, needle: &K) -> Option<ReadGuard<'_, V>> {
// Scan each value and check if our requested needle is present.
let values = self.values.read();
for (value_idx, value) in values.iter().enumerate() {
Expand Down
Loading

0 comments on commit 87ee143

Please sign in to comment.