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

update hashbrown to v0.15 #314

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dashmap"
version = "6.1.0"
version = "7.0.0"
authors = ["Acrimon <[email protected]>"]
edition = "2018"
rust-version = "1.65"
Expand All @@ -21,7 +21,7 @@ inline = ["hashbrown/inline-more"]
[dependencies]
lock_api = "0.4.10"
parking_lot_core = "0.9.8"
hashbrown = { version = "0.14.0", default-features = false, features = ["raw"] }
hashbrown = { version = "0.15.0", default-features = false }
serde = { version = "1.0.188", optional = true, features = ["derive"] }
cfg-if = "1.0.0"
rayon = { version = "1.7.0", optional = true }
Expand Down
110 changes: 27 additions & 83 deletions src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::mapref::multiple::{RefMulti, RefMutMulti};
use crate::lock::{RwLockReadGuard, RwLockWriteGuard};
use crate::lock::{RwLockReadGuardDetached, RwLockWriteGuardDetached};
use crate::t::Map;
use crate::util::SharedValue;
use crate::{DashMap, HashMap};
use crate::DashMap;
use core::hash::{BuildHasher, Hash};
use core::mem;
use std::collections::hash_map::RandomState;
Expand Down Expand Up @@ -38,24 +37,24 @@ impl<K: Eq + Hash, V, S: BuildHasher + Clone> OwningIter<K, V, S> {
}
}

type GuardOwningIter<K, V> = hashbrown::raw::RawIntoIter<(K, SharedValue<V>)>;
type GuardOwningIter<K, V> = hashbrown::hash_table::IntoIter<(K, V)>;

impl<K: Eq + Hash, V, S: BuildHasher + Clone> Iterator for OwningIter<K, V, S> {
type Item = (K, V);

fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(current) = self.current.as_mut() {
if let Some((k, v)) = current.next() {
return Some((k, v.into_inner()));
if let Some(value) = current.next() {
return Some(value);
}
}

if self.shard_i == self.map._shard_count() {
return None;
}

//let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
// Safety: shard index is in bounds
let mut shard_wl = unsafe { self.map._yield_write_shard(self.shard_i) };

let map = mem::take(&mut *shard_wl);
Expand All @@ -64,38 +63,21 @@ impl<K: Eq + Hash, V, S: BuildHasher + Clone> Iterator for OwningIter<K, V, S> {

let iter = map.into_iter();

//unsafe { ptr::write(&mut self.current, Some((arcee, iter))); }
self.current = Some(iter);

self.shard_i += 1;
}
}
}

unsafe impl<K, V, S> Send for OwningIter<K, V, S>
where
K: Eq + Hash + Send,
V: Send,
S: BuildHasher + Clone + Send,
{
}

unsafe impl<K, V, S> Sync for OwningIter<K, V, S>
where
K: Eq + Hash + Sync,
V: Sync,
S: BuildHasher + Clone + Sync,
{
}

type GuardIter<'a, K, V> = (
Arc<RwLockReadGuard<'a, HashMap<K, V>>>,
hashbrown::raw::RawIter<(K, SharedValue<V>)>,
Arc<RwLockReadGuardDetached<'a>>,
hashbrown::hash_table::Iter<'a, (K, V)>,
);

type GuardIterMut<'a, K, V> = (
Arc<RwLockWriteGuard<'a, HashMap<K, V>>>,
hashbrown::raw::RawIter<(K, SharedValue<V>)>,
Arc<RwLockWriteGuardDetached<'a>>,
hashbrown::hash_table::IterMut<'a, (K, V)>,
);

/// Iterator over a DashMap yielding immutable references.
Expand All @@ -122,24 +104,6 @@ impl<'i, K: Clone + Hash + Eq, V: Clone, S: Clone + BuildHasher> Clone for Iter<
}
}

unsafe impl<'a, 'i, K, V, S, M> Send for Iter<'i, K, V, S, M>
where
K: 'a + Eq + Hash + Send,
V: 'a + Send,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, V, S>,
{
}

unsafe impl<'a, 'i, K, V, S, M> Sync for Iter<'i, K, V, S, M>
where
K: 'a + Eq + Hash + Sync,
V: 'a + Sync,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, V, S>,
{
}

impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iter<'a, K, V, S, M> {
pub(crate) fn new(map: &'a M) -> Self {
Self {
Expand All @@ -159,24 +123,23 @@ impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iter
fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(current) = self.current.as_mut() {
if let Some(b) = current.1.next() {
return unsafe {
let (k, v) = b.as_ref();
let guard = current.0.clone();
Some(RefMulti::new(guard, k, v.get()))
};
if let Some(data) = current.1.next() {
let guard = current.0.clone();
// Safety: The guard still protects the data
return unsafe { Some(RefMulti::new(guard, data)) };
}
}

if self.shard_i == self.map._shard_count() {
return None;
}

// Safety: shard index is in bounds
let guard = unsafe { self.map._yield_read_shard(self.shard_i) };
// Safety: The data will not outlive the guard.
let (guard, data) = unsafe { RwLockReadGuardDetached::detach_from(guard) };

let iter = unsafe { guard.iter() };

self.current = Some((Arc::new(guard), iter));
self.current = Some((Arc::new(guard), data.iter()));

self.shard_i += 1;
}
Expand All @@ -202,24 +165,6 @@ pub struct IterMut<'a, K, V, S = RandomState, M = DashMap<K, V, S>> {
marker: PhantomData<S>,
}

unsafe impl<'a, 'i, K, V, S, M> Send for IterMut<'i, K, V, S, M>
where
K: 'a + Eq + Hash + Send,
V: 'a + Send,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, V, S>,
{
}

unsafe impl<'a, 'i, K, V, S, M> Sync for IterMut<'i, K, V, S, M>
where
K: 'a + Eq + Hash + Sync,
V: 'a + Sync,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, V, S>,
{
}

impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>>
IterMut<'a, K, V, S, M>
{
Expand All @@ -241,24 +186,23 @@ impl<'a, K: Eq + Hash, V, S: 'a + BuildHasher + Clone, M: Map<'a, K, V, S>> Iter
fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(current) = self.current.as_mut() {
if let Some(b) = current.1.next() {
return unsafe {
let (k, v) = b.as_mut();
let guard = current.0.clone();
Some(RefMutMulti::new(guard, k, v.get_mut()))
};
if let Some(data) = current.1.next() {
let guard = current.0.clone();
// Safety: The guard still protects the data
return unsafe { Some(RefMutMulti::new(guard, data)) };
}
}

if self.shard_i == self.map._shard_count() {
return None;
}

// Safety: shard index is in bounds
let guard = unsafe { self.map._yield_write_shard(self.shard_i) };
// Safety: The data will not outlive the guard.
let (guard, data) = unsafe { RwLockWriteGuardDetached::detach_from(guard) };

let iter = unsafe { guard.iter() };

self.current = Some((Arc::new(guard), iter));
self.current = Some((Arc::new(guard), data.iter_mut()));

self.shard_i += 1;
}
Expand All @@ -280,7 +224,7 @@ mod tests {
let mut c = 0;

for shard in map.shards() {
c += unsafe { shard.write().iter().count() };
c += shard.write().iter().count();
}

assert_eq!(c, 1);
Expand Down
30 changes: 0 additions & 30 deletions src/iter_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,10 @@ impl<K: Eq + Hash, S: BuildHasher + Clone> Iterator for OwningIter<K, S> {
}
}

unsafe impl<K, S> Send for OwningIter<K, S>
where
K: Eq + Hash + Send,
S: BuildHasher + Clone + Send,
{
}

unsafe impl<K, S> Sync for OwningIter<K, S>
where
K: Eq + Hash + Sync,
S: BuildHasher + Clone + Sync,
{
}

pub struct Iter<'a, K, S, M> {
inner: crate::iter::Iter<'a, K, (), S, M>,
}

unsafe impl<'a, 'i, K, S, M> Send for Iter<'i, K, S, M>
where
K: 'a + Eq + Hash + Send,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, (), S>,
{
}

unsafe impl<'a, 'i, K, S, M> Sync for Iter<'i, K, S, M>
where
K: 'a + Eq + Hash + Sync,
S: 'a + BuildHasher + Clone,
M: Map<'a, K, (), S>,
{
}

impl<'a, K: Eq + Hash, S: 'a + BuildHasher + Clone, M: Map<'a, K, (), S>> Iter<'a, K, S, M> {
pub(crate) fn new(inner: crate::iter::Iter<'a, K, (), S, M>) -> Self {
Self { inner }
Expand Down
Loading
Loading