lint + fmt

This commit is contained in:
xacrimon 2022-02-06 16:17:38 +01:00
parent 7197fa3323
commit e530e80da0
No known key found for this signature in database
GPG Key ID: FE567F46AFBDF3AE
3 changed files with 25 additions and 22 deletions

View File

@ -732,13 +732,19 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S>
self.shards.get_unchecked(i).write()
}
unsafe fn _try_yield_read_shard(&'a self, i: usize) -> Option<RwLockReadGuard<'a, HashMap<K, V, S>>> {
unsafe fn _try_yield_read_shard(
&'a self,
i: usize,
) -> Option<RwLockReadGuard<'a, HashMap<K, V, S>>> {
debug_assert!(i < self.shards.len());
self.shards.get_unchecked(i).try_read()
}
unsafe fn _try_yield_write_shard(&'a self, i: usize) -> Option<RwLockWriteGuard<'a, HashMap<K, V, S>>> {
unsafe fn _try_yield_write_shard(
&'a self,
i: usize,
) -> Option<RwLockWriteGuard<'a, HashMap<K, V, S>>> {
debug_assert!(i < self.shards.len());
self.shards.get_unchecked(i).try_write()
@ -906,7 +912,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S>
fn _try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V, S>>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized
Q: Hash + Eq + ?Sized,
{
let hash = self.hash_usize(&key);
@ -1013,7 +1019,11 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + BuildHasher + Clone> Map<'a, K, V, S>
let vptr = &mut *vptr.as_ptr();
Some(Entry::Occupied(OccupiedEntry::new(shard, key, (kptr, vptr))))
Some(Entry::Occupied(OccupiedEntry::new(
shard,
key,
(kptr, vptr),
)))
}
} else {
Some(Entry::Vacant(VacantEntry::new(shard, key)))

View File

@ -31,12 +31,18 @@ pub trait Map<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + Clone + BuildHasher> {
/// # Safety
///
/// The index must not be out of bounds.
unsafe fn _try_yield_read_shard(&'a self, i: usize) -> Option<RwLockReadGuard<'a, HashMap<K, V, S>>>;
unsafe fn _try_yield_read_shard(
&'a self,
i: usize,
) -> Option<RwLockReadGuard<'a, HashMap<K, V, S>>>;
/// # Safety
///
/// The index must not be out of bounds.
unsafe fn _try_yield_write_shard(&'a self, i: usize) -> Option<RwLockWriteGuard<'a, HashMap<K, V, S>>>;
unsafe fn _try_yield_write_shard(
&'a self,
i: usize,
) -> Option<RwLockWriteGuard<'a, HashMap<K, V, S>>>;
fn _insert(&self, key: K, value: V) -> Option<V>;

View File

@ -1,4 +1,3 @@
/// Represents the result of a non-blocking read from a [DashMap](crate::DashMap).
#[derive(Debug)]
pub enum TryResult<R> {
@ -12,30 +11,18 @@ pub enum TryResult<R> {
impl<R> TryResult<R> {
/// Returns `true` if the value was present in the map, and the lock for the shard was successfully obtained.
#[inline]
pub fn is_present(&self) -> bool {
match self {
TryResult::Present(_) => true,
_ => false,
}
matches!(self, TryResult::Present(_))
}
/// Returns `true` if the shard wasn't locked, and the value wasn't present in the map.
#[inline]
pub fn is_absent(&self) -> bool {
match self {
TryResult::Absent => true,
_ => false,
}
matches!(self, TryResult::Absent)
}
/// Returns `true` if the shard was locked.
#[inline]
pub fn is_locked(&self) -> bool {
match self {
TryResult::Locked => true,
_ => false,
}
matches!(self, TryResult::Locked)
}
/// If `self` is [Present](TryResult::Present), returns the reference to the value in the map.