Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

remove send/sync retrictions when possible #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
benchmark/
Cargo.lock
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,4 +10,5 @@ license = "MIT"

[dependencies]
libc = "^0.2"
[dev-dependencies]
rand = "^0.3.9"
37 changes: 14 additions & 23 deletions src/hamt.rs
Original file line number Diff line number Diff line change
@@ -60,8 +60,7 @@ enum BorrowedNodeRef<'a, K, V, IS, H>
}

impl<K, V, IS, H> NodeRef<K, V, IS, H>
where K: Eq+Send+Sync,
V: Send+Sync,
where K: Eq,
IS: ItemStore<K, V>,
H: Hasher
{
@@ -183,9 +182,7 @@ enum NodeEntryRef<'a, K, V, IS, H>
}

impl<'a, K, V, IS, H> NodeEntryRef<'a, K, V, IS, H>
where K: Send+Sync,
V: Send+Sync,
IS: ItemStore<K, V>
where IS: ItemStore<K, V>
{
// Clones the contents of a NodeEntryRef into a NodeEntryOwned value to be used elsewhere.
fn clone_out(&self) -> NodeEntryOwned<K, V, IS, H> {
@@ -406,8 +403,7 @@ impl<'a, K, V, IS, H> UnsafeNode<K, V, IS, H>

// impl UnsafeNode (continued)
impl<K, V, IS, H> UnsafeNode<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: Send+Sync,
where K: Eq+Hash,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1159,8 +1155,7 @@ pub struct HamtMap<K, V, IS=ShareStore<K,V>, H=StdHasher> {

// impl HamtMap
impl<K, V, IS, H> HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: Send+Sync,
where K: Eq+Hash,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1336,8 +1331,7 @@ impl<K, V, IS, H> Clone for HamtMap<K, V, IS, H> {

// Default for HamtMap
impl<K, V, IS, H> Default for HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: Send+Sync,
where K: Eq+Hash,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1347,8 +1341,8 @@ impl<K, V, IS, H> Default for HamtMap<K, V, IS, H>
}

impl<'a, K, V, IS, H> IntoIterator for &'a HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash+'a,
V: Send+Sync+'a,
where K: Eq+Hash+'a,
V: 'a,
IS: ItemStore<K, V>+'a,
H: Hasher+Default+'a
{
@@ -1363,8 +1357,8 @@ impl<'a, K, V, IS, H> IntoIterator for &'a HamtMap<K, V, IS, H>

// Eq for HamtMap
impl<K, V, IS, H> PartialEq for HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: PartialEq+Send+Sync,
where K: Eq+Hash,
V: PartialEq,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1397,8 +1391,8 @@ impl<K, V, IS, H> PartialEq for HamtMap<K, V, IS, H>

// Eq for HamtMap
impl<K, V, IS, H> Eq for HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: Eq+Send+Sync,
where K: Eq+Hash,
V: Eq,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1407,8 +1401,7 @@ impl<K, V, IS, H> Eq for HamtMap<K, V, IS, H>

// FromIterator
impl<K, V, IS, H> ::std::iter::FromIterator<(K, V)> for HamtMap<K, V, IS, H>
where K: Eq+Send+Sync+Hash,
V: Send+Sync,
where K: Eq+Hash,
IS: ItemStore<K, V>,
H: Hasher+Default
{
@@ -1467,8 +1460,7 @@ pub struct HamtMapIterator<'a, K, V, IS, H>

impl<'a, K, V, IS, H>
HamtMapIterator<'a, K, V, IS, H>
where K: Eq+Send+Sync,
V: Send+Sync,
where K: Eq,
IS: ItemStore<K, V>,
H: Hasher
{
@@ -1486,8 +1478,7 @@ HamtMapIterator<'a, K, V, IS, H>

impl<'a, K, V, IS, H>
Iterator for HamtMapIterator<'a, K, V, IS, H>
where K: Eq+Send+Sync,
V: Send+Sync,
where K: Eq,
IS: ItemStore<K, V>,
H: 'a + Hasher
{
16 changes: 12 additions & 4 deletions src/item_store.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ use std::sync::Arc;
//=-------------------------------------------------------------------------------------------------
// trait ItemStore
//=-------------------------------------------------------------------------------------------------
pub trait ItemStore<K, V>: Clone+Send+Sync {
pub trait ItemStore<K, V>: Clone {
fn key<'a>(&'a self) -> &'a K;
fn val<'a>(&'a self) -> &'a V;

@@ -40,7 +40,7 @@ pub struct CopyStore<K, V> {
val: V
}

impl<K: Clone+Send+Sync, V: Clone+Send+Sync> ItemStore<K, V> for CopyStore<K, V> {
impl<K: Clone, V: Clone> ItemStore<K, V> for CopyStore<K, V> {
fn key<'a>(&'a self) -> &'a K { &self.key }
fn val<'a>(&'a self) -> &'a V { &self.val }

@@ -52,7 +52,7 @@ impl<K: Clone+Send+Sync, V: Clone+Send+Sync> ItemStore<K, V> for CopyStore<K, V>
}
}

impl<K: Clone+Send+Sync, V: Clone+Send+Sync> Clone for CopyStore<K, V> {
impl<K: Clone, V: Clone> Clone for CopyStore<K, V> {
fn clone(&self) -> CopyStore<K, V> {
CopyStore {
key: self.key.clone(),
@@ -61,12 +61,16 @@ impl<K: Clone+Send+Sync, V: Clone+Send+Sync> Clone for CopyStore<K, V> {
}
}

unsafe impl <K, V> Send for CopyStore<K, V> where K: Send, V: Send { }

unsafe impl <K, V> Sync for CopyStore<K, V> where K: Sync, V: Sync { }



//=-------------------------------------------------------------------------------------------------
// struct ShareStore
//=-------------------------------------------------------------------------------------------------
pub struct ShareStore<K, V> {
pub struct ShareStore<K: Sync + Send, V: Sync+ Send> {
store: Arc<(K, V)>,
}

@@ -86,3 +90,7 @@ impl<K: Send+Sync, V: Send+Sync> Clone for ShareStore<K, V> {
}
}
}

unsafe impl <K, V> Send for ShareStore<K, V> where K: Send + Sync, V: Send + Sync { }

unsafe impl <K, V> Sync for ShareStore<K, V> where K: Send + Sync, V: Send + Sync { }
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
#![allow(unused_parens)]

extern crate libc;

#[cfg(test)]
extern crate rand;

pub use hamt::HamtMap;