dashmap/src/t.rs

135 lines
3.5 KiB
Rust
Raw Normal View History

2019-11-19 20:43:20 +00:00
//! Central map trait to ease modifications and extensions down the road.
2020-12-25 23:05:20 +00:00
2019-11-19 13:18:38 +00:00
use crate::iter::{Iter, IterMut};
2022-04-29 19:02:35 +00:00
use crate::lock::{RwLockReadGuard, RwLockWriteGuard};
2019-11-19 13:18:38 +00:00
use crate::mapref::entry::Entry;
use crate::mapref::one::{Ref, RefMut};
use crate::try_result::TryResult;
2020-01-14 18:10:14 +00:00
use crate::HashMap;
2020-03-26 15:26:29 +00:00
use core::borrow::Borrow;
use core::hash::{BuildHasher, Hash};
2019-11-19 12:22:07 +00:00
2020-02-21 18:52:02 +00:00
/// Implementation detail that is exposed due to generic constraints in public types.
pub trait Map<'a, K: 'a + Eq + Hash, V: 'a, S: 'a + Clone + BuildHasher> {
2019-11-19 14:00:46 +00:00
fn _shard_count(&self) -> usize;
2020-07-04 17:18:59 +00:00
/// # Safety
///
/// The index must not be out of bounds.
2020-03-16 13:34:23 +00:00
unsafe fn _get_read_shard(&'a self, i: usize) -> &'a HashMap<K, V, S>;
2020-07-04 17:18:59 +00:00
/// # Safety
///
/// The index must not be out of bounds.
2020-01-15 03:07:45 +00:00
unsafe fn _yield_read_shard(&'a self, i: usize) -> RwLockReadGuard<'a, HashMap<K, V, S>>;
2020-07-04 17:18:59 +00:00
/// # Safety
///
/// The index must not be out of bounds.
2020-01-15 03:07:45 +00:00
unsafe fn _yield_write_shard(&'a self, i: usize) -> RwLockWriteGuard<'a, HashMap<K, V, S>>;
2020-07-04 17:18:59 +00:00
/// # Safety
///
/// The index must not be out of bounds.
2022-02-06 15:17:38 +00:00
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.
2022-02-06 15:17:38 +00:00
unsafe fn _try_yield_write_shard(
&'a self,
i: usize,
) -> Option<RwLockWriteGuard<'a, HashMap<K, V, S>>>;
2019-11-19 13:18:24 +00:00
fn _insert(&self, key: K, value: V) -> Option<V>;
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _remove<Q>(&self, key: &Q) -> Option<(K, V)>
2020-02-21 18:52:02 +00:00
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-07-31 20:51:09 +00:00
2020-02-21 18:52:02 +00:00
fn _remove_if<Q>(&self, key: &Q, f: impl FnOnce(&K, &V) -> bool) -> Option<(K, V)>
2019-11-19 12:22:07 +00:00
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-07-31 20:51:09 +00:00
2021-11-25 15:56:38 +00:00
fn _remove_if_mut<Q>(&self, key: &Q, f: impl FnOnce(&K, &mut V) -> bool) -> Option<(K, V)>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-01-15 03:07:45 +00:00
fn _iter(&'a self) -> Iter<'a, K, V, S, Self>
2019-11-19 13:18:24 +00:00
where
Self: Sized;
2020-07-31 20:51:09 +00:00
2020-01-15 03:07:45 +00:00
fn _iter_mut(&'a self) -> IterMut<'a, K, V, S, Self>
2019-11-19 13:18:24 +00:00
where
Self: Sized;
2020-07-31 20:51:09 +00:00
2020-01-15 03:07:45 +00:00
fn _get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V, S>>
2019-11-19 12:22:07 +00:00
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-07-31 20:51:09 +00:00
2020-01-15 03:07:45 +00:00
fn _get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V, S>>
2019-11-19 12:22:07 +00:00
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-07-31 20:51:09 +00:00
fn _try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V, S>>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
fn _try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V, S>>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2019-11-19 13:18:24 +00:00
fn _shrink_to_fit(&self);
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _retain(&self, f: impl FnMut(&K, &mut V) -> bool);
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _len(&self) -> usize;
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _capacity(&self) -> usize;
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
2019-11-19 12:22:07 +00:00
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-07-31 20:51:09 +00:00
2019-11-19 13:18:24 +00:00
fn _alter_all(&self, f: impl FnMut(&K, V) -> V);
2020-07-31 20:51:09 +00:00
fn _view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized;
2020-01-15 03:07:45 +00:00
fn _entry(&'a self, key: K) -> Entry<'a, K, V, S>;
2020-07-31 20:51:09 +00:00
fn _try_entry(&'a self, key: K) -> Option<Entry<'a, K, V, S>>;
fn _hasher(&self) -> S;
2019-11-19 12:45:33 +00:00
// provided
2019-11-19 13:18:24 +00:00
fn _clear(&self) {
self._retain(|_, _| false)
2019-11-19 12:45:33 +00:00
}
2019-11-19 13:18:24 +00:00
fn _contains_key<Q>(&'a self, key: &Q) -> bool
2019-11-19 12:45:33 +00:00
where
K: Borrow<Q>,
2019-11-19 13:18:38 +00:00
Q: Hash + Eq + ?Sized,
2019-11-19 12:45:33 +00:00
{
2019-11-19 13:18:24 +00:00
self._get(key).is_some()
2019-11-19 12:45:33 +00:00
}
2019-11-19 13:18:24 +00:00
fn _is_empty(&self) -> bool {
self._len() == 0
2019-11-19 12:45:33 +00:00
}
2019-11-19 12:22:07 +00:00
}