Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove implied lifetimes #100

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benches/hashmap_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ criterion_main!(insert, remove, search);

// Utility functions:

fn insert_vec<'a, V: Clone + Sync + Send + 'static>(
map: &'a mut HashMap<u32, V>,
fn insert_vec<V: Clone + Sync + Send + 'static>(
map: &mut HashMap<u32, V>,
list: Vec<(u32, V)>,
) -> HashMapWriteTxn<'a, u32, V> {
) -> HashMapWriteTxn<u32, V> {
let mut write_txn = map.write();
for (key, val) in list.into_iter() {
write_txn.insert(key, val);
Expand Down
61 changes: 29 additions & 32 deletions src/arcache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ impl<
tracing::trace!("r {} >>> {}", p_was, *p);
}

fn drain_tlocal_inc<'a, S>(
&'a self,
cache: &mut HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn drain_tlocal_inc<S>(
&self,
cache: &mut HashTrieWriteTxn<K, CacheItem<K, V>>,
inner: &mut ArcInner<K, V>,
shared: &ArcShared<K, V>,
tlocal: Map<K, ThreadCacheItem<V>>,
Expand Down Expand Up @@ -1075,9 +1075,9 @@ impl<
});
}

fn drain_hit_rx<'a>(
&'a self,
cache: &mut HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn drain_hit_rx(
&self,
cache: &mut HashTrieWriteTxn<K, CacheItem<K, V>>,
inner: &mut ArcInner<K, V>,
commit_ts: Instant,
) {
Expand Down Expand Up @@ -1130,9 +1130,9 @@ impl<
}
}

fn drain_inc_rx<'a, S>(
&'a self,
cache: &mut HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn drain_inc_rx<S>(
&self,
cache: &mut HashTrieWriteTxn<K, CacheItem<K, V>>,
inner: &mut ArcInner<K, V>,
shared: &ArcShared<K, V>,
commit_ts: Instant,
Expand Down Expand Up @@ -1288,9 +1288,9 @@ impl<
}
}

fn drain_tlocal_hits<'a>(
&'a self,
cache: &mut HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn drain_tlocal_hits(
&self,
cache: &mut HashTrieWriteTxn<K, CacheItem<K, V>>,
inner: &mut ArcInner<K, V>,
// shared: &ArcShared<K, V>,
commit_txid: u64,
Expand Down Expand Up @@ -1357,8 +1357,8 @@ impl<
}

/*
fn drain_stat_rx<'a>(
&'a self,
fn drain_stat_rx(
&self,
inner: &mut ArcInner<K, V>,
stats: &mut CacheStats,
commit_ts: Instant,
Expand Down Expand Up @@ -1390,9 +1390,9 @@ impl<
*/

#[allow(clippy::cognitive_complexity)]
fn evict<'a, S>(
&'a self,
cache: &mut HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn evict<S>(
&self,
cache: &mut HashTrieWriteTxn<K, CacheItem<K, V>>,
inner: &mut ArcInner<K, V>,
shared: &ArcShared<K, V>,
commit_txid: u64,
Expand Down Expand Up @@ -1513,9 +1513,9 @@ impl<
}

#[allow(clippy::unnecessary_mut_passed)]
fn commit<'a, S>(
&'a self,
mut cache: HashTrieWriteTxn<'a, K, CacheItem<K, V>>,
fn commit<S>(
&self,
mut cache: HashTrieWriteTxn<K, CacheItem<K, V>>,
tlocal: Map<K, ThreadCacheItem<V>>,
hit: Vec<u64>,
clear: bool,
Expand Down Expand Up @@ -1646,11 +1646,10 @@ impl<
}

impl<
'a,
K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static,
V: Clone + Debug + Sync + Send + 'static,
S: ARCacheWriteStat<K>,
> ARCacheWriteTxn<'a, K, V, S>
> ARCacheWriteTxn<'_, K, V, S>
{
/// Commit the changes of this writer, making them globally visible. This causes
/// all items written to this thread's local store to become visible in the main
Expand Down Expand Up @@ -1705,7 +1704,7 @@ impl<
/// the thread local cache, a `Some` is returned, else you will recieve a `None`. On a
/// `None`, you must then consult the external data source that this structure is acting
/// as a cache for.
pub fn get<'b, Q: ?Sized>(&'b mut self, k: &'b Q) -> Option<&'b V>
pub fn get<Q: ?Sized>(&mut self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Expand Down Expand Up @@ -1774,7 +1773,7 @@ impl<
///
/// Since you are mutating the state of the value, if you have sized insertions you MAY
/// break this since you can change the weight of the value to be inconsistent
pub fn get_mut<'b, Q: ?Sized>(&'b mut self, k: &'b Q, make_dirty: bool) -> Option<&'b mut V>
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q, make_dirty: bool) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Expand Down Expand Up @@ -2006,7 +2005,7 @@ impl<
}

#[cfg(test)]
pub(crate) fn peek_cache<'b, Q: ?Sized>(&'a self, k: &'b Q) -> CacheState
pub(crate) fn peek_cache<Q: ?Sized>(&self, k: &Q) -> CacheState
where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Expand Down Expand Up @@ -2039,17 +2038,16 @@ impl<
}

impl<
'a,
K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static,
V: Clone + Debug + Sync + Send + 'static,
S: ARCacheReadStat + Clone,
> ARCacheReadTxn<'a, K, V, S>
> ARCacheReadTxn<'_, K, V, S>
{
/// Attempt to retieve a k-v pair from the cache. If it is present in the main cache OR
/// the thread local cache, a `Some` is returned, else you will recieve a `None`. On a
/// `None`, you must then consult the external data source that this structure is acting
/// as a cache for.
pub fn get<'b, Q: ?Sized>(&'b mut self, k: &'b Q) -> Option<&'b V>
pub fn get<Q: ?Sized>(&mut self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Expand Down Expand Up @@ -2077,7 +2075,7 @@ impl<
});
}
let v = &(**v).as_ref().v as *const _;
// This discards the lifetime and repins it to &'b.
// This discards the lifetime and repins it to the lifetime of `self`.
&(*v)
})
})
Expand Down Expand Up @@ -2110,7 +2108,7 @@ impl<
}

/// Determine if this cache contains the following key.
pub fn contains_key<'b, Q: ?Sized>(&mut self, k: &'b Q) -> bool
pub fn contains_key<Q: ?Sized>(&mut self, k: &Q) -> bool
where
K: Borrow<Q>,
Q: Hash + Eq + Ord,
Expand Down Expand Up @@ -2192,11 +2190,10 @@ impl<
}

impl<
'a,
K: Hash + Eq + Ord + Clone + Debug + Sync + Send + 'static,
V: Clone + Debug + Sync + Send + 'static,
S: ARCacheReadStat + Clone,
> Drop for ARCacheReadTxn<'a, K, V, S>
> Drop for ARCacheReadTxn<'_, K, V, S>
{
fn drop(&mut self) {
// We could make this check the queue sizes rather than blindly quiescing
Expand Down
4 changes: 2 additions & 2 deletions src/bptree/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 's
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'_, K, V>
{
/// Commit the changes from this write transaction. Readers after this point
/// will be able to percieve these changes.
Expand Down
46 changes: 23 additions & 23 deletions src/bptree/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ where
inner: LinCowCellReadTxn<'a, SuperBlock<K, V>, CursorRead<K, V>, CursorWrite<K, V>>,
}

unsafe impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static> Send
for BptreeMapReadTxn<'a, K, V>
unsafe impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static> Send
for BptreeMapReadTxn<'_, K, V>
{
}
unsafe impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static> Sync
for BptreeMapReadTxn<'a, K, V>
unsafe impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static> Sync
for BptreeMapReadTxn<'_, K, V>
{
}

Expand Down Expand Up @@ -149,22 +149,22 @@ impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 's
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
Extend<(K, V)> for BptreeMapWriteTxn<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
Extend<(K, V)> for BptreeMapWriteTxn<'_, K, V>
{
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
self.inner.as_mut().extend(iter);
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'_, K, V>
{
// == RO methods

/// Retrieve a value from the tree. If the value exists, a reference is returned
/// as `Some(&V)`, otherwise if not present `None` is returned.
pub fn get<'b, Q: ?Sized>(&'a self, k: &'b Q) -> Option<&'a V>
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -173,7 +173,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Assert if a key exists in the tree.
pub fn contains_key<'b, Q: ?Sized>(&'a self, k: &'b Q) -> bool
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -192,7 +192,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Iterate over a range of values
pub fn range<'b, R, T>(&'b self, range: R) -> RangeIter<'b, K, V>
pub fn range<R, T>(&self, range: R) -> RangeIter<K, V>
where
K: Borrow<T>,
T: Ord + ?Sized,
Expand Down Expand Up @@ -296,19 +296,19 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
/// Create a read-snapshot of the current tree. This does NOT guarantee the tree may
/// not be mutated during the read, so you MUST guarantee that no functions of the
/// write txn are called while this snapshot is active.
pub fn to_snapshot(&'a self) -> BptreeMapReadSnapshot<K, V> {
pub fn to_snapshot(&self) -> BptreeMapReadSnapshot<K, V> {
BptreeMapReadSnapshot {
inner: SnapshotType::W(self.inner.as_ref()),
}
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapReadTxn<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapReadTxn<'_, K, V>
{
/// Retrieve a value from the tree. If the value exists, a reference is returned
/// as `Some(&V)`, otherwise if not present `None` is returned.
pub fn get<'b, Q: ?Sized>(&'a self, k: &'b Q) -> Option<&'a V>
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -317,7 +317,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Assert if a key exists in the tree.
pub fn contains_key<'b, Q: ?Sized>(&'a self, k: &'b Q) -> bool
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -341,7 +341,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Iterate over a range of values
pub fn range<'b, R, T>(&'b self, range: R) -> RangeIter<'b, K, V>
pub fn range<R, T>(&self, range: R) -> RangeIter<K, V>
where
K: Borrow<T>,
T: Ord + ?Sized,
Expand Down Expand Up @@ -377,7 +377,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send

/// Create a read-snapshot of the current tree.
/// As this is the read variant, it IS safe, and guaranteed the tree will not change.
pub fn to_snapshot(&'a self) -> BptreeMapReadSnapshot<K, V> {
pub fn to_snapshot(&self) -> BptreeMapReadSnapshot<K, V> {
BptreeMapReadSnapshot {
inner: SnapshotType::R(self.inner.as_ref()),
}
Expand All @@ -390,12 +390,12 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapReadSnapshot<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapReadSnapshot<'_, K, V>
{
/// Retrieve a value from the tree. If the value exists, a reference is returned
/// as `Some(&V)`, otherwise if not present `None` is returned.
pub fn get<'b, Q: ?Sized>(&'a self, k: &'b Q) -> Option<&'a V>
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -407,7 +407,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Assert if a key exists in the tree.
pub fn contains_key<'b, Q: ?Sized>(&'a self, k: &'b Q) -> bool
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
where
K: Borrow<Q>,
Q: Ord,
Expand All @@ -432,7 +432,7 @@ impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send
}

/// Iterate over a range of values
pub fn range<'b, R, T>(&'b self, range: R) -> RangeIter<'b, K, V>
pub fn range<R, T>(&self, range: R) -> RangeIter<K, V>
where
K: Borrow<T>,
T: Ord + ?Sized,
Expand Down
4 changes: 2 additions & 2 deletions src/bptree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 's
}
}

impl<'a, K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'a, K, V>
impl<K: Clone + Ord + Debug + Sync + Send + 'static, V: Clone + Sync + Send + 'static>
BptreeMapWriteTxn<'_, K, V>
{
/// Commit the changes from this write transaction. Readers after this point
/// will be able to percieve these changes.
Expand Down
8 changes: 4 additions & 4 deletions src/cowcell/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct CowCell<T> {
/// rollback a change, don't call commit and allow the write transaction to
/// be dropped. This causes the `CowCell` to unlock allowing the next writer
/// to proceed.
pub struct CowCellWriteTxn<'a, T: 'a> {
pub struct CowCellWriteTxn<'a, T> {
// Hold open the guard, and initiate the copy to here.
work: Option<T>,
read: Arc<T>,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<T> Deref for CowCellReadTxn<T> {
}
}

impl<'a, T> CowCellWriteTxn<'a, T>
impl<T> CowCellWriteTxn<'_, T>
where
T: Clone,
{
Expand Down Expand Up @@ -174,7 +174,7 @@ where
}
}

impl<'a, T> Deref for CowCellWriteTxn<'a, T>
impl<T> Deref for CowCellWriteTxn<'_, T>
where
T: Clone,
{
Expand All @@ -189,7 +189,7 @@ where
}
}

impl<'a, T> DerefMut for CowCellWriteTxn<'a, T>
impl<T> DerefMut for CowCellWriteTxn<'_, T>
where
T: Clone,
{
Expand Down
Loading
Loading