Skip to content

Commit

Permalink
chore(*): finalize SCC 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wvwwvwwv committed May 3, 2024
1 parent 68ae89c commit 636b7af
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .config/glossary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Linearizability
LinkedList
LRU
M1
M2
M3
M4
metadata
overcount
Resize
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Version 2

2.1.1

* Implement `Deref` and `DerefMut` for `OccupiedEntry`: [#140](https://github.com/wvwwvwwv/scalable-concurrent-containers/issues/140) by [gituser-rs](https://github.com/gituser-rs)

2.1.0

* Use [`sdd`](https://crates.io/crates/sdd) as the memory reclaimer.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "scc"
description = "High performance containers and utilities for concurrent and asynchronous programming"
documentation = "https://docs.rs/scc"
version = "2.1.0"
version = "2.1.1"
authors = ["wvwwvwwv <[email protected]>"]
edition = "2021"
rust-version = "1.65.0"
Expand Down
29 changes: 28 additions & 1 deletion src/hash_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::collections::hash_map::RandomState;
use std::fmt::{self, Debug};
use std::hash::{BuildHasher, Hash};
use std::mem::replace;
use std::ops::RangeInclusive;
use std::ops::{Deref, DerefMut, RangeInclusive};
use std::pin::Pin;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{Acquire, Relaxed};
Expand Down Expand Up @@ -363,6 +363,9 @@ where
/// assert!(hashcache.get(&1).is_none());
/// assert!(hashcache.put(1, 10).is_ok());
/// assert_eq!(*hashcache.get(&1).unwrap().get(), 10);
///
/// *hashcache.get(&1).unwrap() = 11;
/// assert_eq!(*hashcache.get(&1).unwrap(), 11);
/// ```
#[inline]
pub fn get<Q>(&self, key: &Q) -> Option<OccupiedEntry<K, V, H>>
Expand Down Expand Up @@ -1602,6 +1605,30 @@ where
}
}

impl<'h, K, V, H> Deref for OccupiedEntry<'h, K, V, H>
where
K: Eq + Hash,
H: BuildHasher,
{
type Target = V;

#[inline]
fn deref(&self) -> &Self::Target {
self.get()
}
}

impl<'h, K, V, H> DerefMut for OccupiedEntry<'h, K, V, H>
where
K: Eq + Hash,
H: BuildHasher,
{
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.get_mut()
}
}

impl<'h, K, V, H> VacantEntry<'h, K, V, H>
where
K: Eq + Hash,
Expand Down
15 changes: 15 additions & 0 deletions src/hash_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ where
/// assert!(hashindex.get(&1).is_none());
/// assert!(hashindex.insert(1, 10).is_ok());
/// assert_eq!(*hashindex.get(&1).unwrap().get(), 10);
/// assert_eq!(*hashindex.get(&1).unwrap(), 10);
/// ```
#[inline]
pub fn get<Q>(&self, key: &Q) -> Option<OccupiedEntry<K, V, H>>
Expand Down Expand Up @@ -1609,6 +1610,20 @@ where
}
}

impl<'h, K, V, H> Deref for OccupiedEntry<'h, K, V, H>
where
K: 'static + Clone + Debug + Eq + Hash,
V: 'static + Clone + Debug,
H: BuildHasher,
{
type Target = V;

#[inline]
fn deref(&self) -> &Self::Target {
self.get()
}
}

impl<'h, K, V, H> VacantEntry<'h, K, V, H>
where
K: 'static + Clone + Eq + Hash,
Expand Down
33 changes: 24 additions & 9 deletions src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::hash_map::RandomState;
use std::fmt::{self, Debug};
use std::hash::{BuildHasher, Hash};
use std::mem::replace;
use std::ops::{Deref, RangeInclusive};
use std::ops::{Deref, DerefMut, RangeInclusive};
use std::pin::Pin;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::{Acquire, Relaxed};
Expand Down Expand Up @@ -659,6 +659,9 @@ where
/// assert!(hashmap.get(&1).is_none());
/// assert!(hashmap.insert(1, 10).is_ok());
/// assert_eq!(*hashmap.get(&1).unwrap().get(), 10);
///
/// *hashmap.get(&1).unwrap() = 11;
/// assert_eq!(*hashmap.get(&1).unwrap(), 11);
/// ```
#[inline]
pub fn get<Q>(&self, key: &Q) -> Option<OccupiedEntry<K, V, H>>
Expand Down Expand Up @@ -1921,30 +1924,42 @@ where
}
}

impl<'h, K, V, H> Debug for OccupiedEntry<'h, K, V, H>
where
K: Debug + Eq + Hash,
V: Debug,
H: BuildHasher,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedEntry")
.field("key", self.key())
.field("value", self.get())
.finish_non_exhaustive()
}
}

impl<'h, K, V, H> Deref for OccupiedEntry<'h, K, V, H>
where
K: Eq + Hash,
H: BuildHasher,
{
type Target = V;

#[inline]
fn deref(&self) -> &Self::Target {
self.get()
}
}

impl<'h, K, V, H> Debug for OccupiedEntry<'h, K, V, H>
impl<'h, K, V, H> DerefMut for OccupiedEntry<'h, K, V, H>
where
K: Debug + Eq + Hash,
V: Debug,
K: Eq + Hash,
H: BuildHasher,
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("OccupiedEntry")
.field("key", self.key())
.field("value", self.get())
.finish_non_exhaustive()
fn deref_mut(&mut self) -> &mut Self::Target {
self.get_mut()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use stack::Stack;
pub mod tree_index;
pub use tree_index::TreeIndex;

/// Re-export the [`sdd`](https://crates.io/crates/sdd) crate for backward compatibility.
/// Re-exports the [`sdd`](https://crates.io/crates/sdd) crate for backward compatibility.
pub use sdd as ebr;

mod exit_guard;
Expand Down

0 comments on commit 636b7af

Please sign in to comment.