mirror of https://github.com/xacrimon/dashmap
lint + fmt
This commit is contained in:
parent
7197fa3323
commit
e530e80da0
18
src/lib.rs
18
src/lib.rs
|
@ -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)))
|
||||
|
|
10
src/t.rs
10
src/t.rs
|
@ -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>;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue