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

Commit

Permalink
chore: Fix lints in nightly 2024-02-27 (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell authored Feb 29, 2024
1 parent 887ebff commit ac7f5fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
12 changes: 6 additions & 6 deletions rust/noosphere-collections/src/hamt/hamt_implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ where
/// }
/// ```
#[inline]
pub async fn get<Q: ?Sized>(&self, k: &Q) -> Result<Option<&V>>
pub async fn get<Q>(&self, k: &Q) -> Result<Option<&V>>
where
K: Borrow<Q>,
Q: Hash + Eq + TargetConditionalSendSync,
Q: ?Sized + Hash + Eq + TargetConditionalSendSync,
V: DeserializeOwned,
{
match self.root.get(k, &self.store, self.bit_width).await? {
Expand Down Expand Up @@ -281,10 +281,10 @@ where
/// }
/// ```
#[inline]
pub async fn contains_key<Q: ?Sized>(&self, k: &Q) -> Result<bool>
pub async fn contains_key<Q>(&self, k: &Q) -> Result<bool>
where
K: Borrow<Q>,
Q: Hash + Eq + TargetConditionalSendSync,
Q: ?Sized + Hash + Eq + TargetConditionalSendSync,
{
Ok(self
.root
Expand Down Expand Up @@ -317,10 +317,10 @@ where
/// assert_eq!(map.delete(&1).await.unwrap(), None);
/// }
/// ```
pub async fn delete<Q: ?Sized>(&mut self, k: &Q) -> Result<Option<(K, V)>>
pub async fn delete<Q>(&mut self, k: &Q) -> Result<Option<(K, V)>>
where
K: Borrow<Q>,
Q: Hash + Eq + TargetConditionalSendSync,
Q: ?Sized + Hash + Eq + TargetConditionalSendSync,
{
self.root.remove_entry(k, &self.store, self.bit_width).await
}
Expand Down
12 changes: 6 additions & 6 deletions rust/noosphere-collections/src/hamt/hash_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub type HashedKey = [u8; 32];

/// Algorithm used as the hasher for the Hamt.
pub trait HashAlgorithm: TargetConditionalSendSync {
fn hash<X: ?Sized>(key: &X) -> HashedKey
fn hash<X>(key: &X) -> HashedKey
where
X: Hash;
X: ?Sized + Hash;
}

/// Type is needed because the Sha256 hasher does not implement `std::hash::Hasher`
Expand All @@ -40,9 +40,9 @@ impl Hasher for Sha2HasherWrapper {
pub enum Sha256 {}

impl HashAlgorithm for Sha256 {
fn hash<X: ?Sized>(key: &X) -> HashedKey
fn hash<X>(key: &X) -> HashedKey
where
X: Hash,
X: ?Sized + Hash,
{
let mut hasher = Sha2HasherWrapper::default();
key.hash(&mut hasher);
Expand Down Expand Up @@ -77,9 +77,9 @@ pub enum Identity {}

#[cfg(feature = "identity")]
impl HashAlgorithm for Identity {
fn hash<X: ?Sized>(key: &X) -> HashedKey
fn hash<X>(key: &X) -> HashedKey
where
X: Hash,
X: ?Sized + Hash,
{
let mut ident_hasher = IdentityHasher::default();
key.hash(&mut ident_hasher);
Expand Down
40 changes: 22 additions & 18 deletions rust/noosphere-collections/src/hamt/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
H: HashAlgorithm + TargetConditionalSendSync,
V: Serialize + DeserializeOwned + TargetConditionalSendSync,
{
pub async fn set<S: BlockStore>(
pub async fn set<S>(
&mut self,
key: K,
value: V,
Expand All @@ -103,6 +103,7 @@ where
) -> Result<(Option<V>, bool)>
where
V: PartialEq,
S: BlockStore,
{
self.modify_value(
HashBits::new(H::hash(&key)),
Expand All @@ -117,29 +118,25 @@ where
}

#[inline]
pub async fn get<Q: ?Sized + TargetConditionalSendSync, S: BlockStore>(
&self,
k: &Q,
store: &S,
bit_width: u32,
) -> Result<Option<&V>>
pub async fn get<Q, S>(&self, k: &Q, store: &S, bit_width: u32) -> Result<Option<&V>>
where
K: Borrow<Q>,
Q: Eq + Hash,
Q: ?Sized + TargetConditionalSendSync + Eq + Hash,
S: BlockStore,
{
Ok(self.search(k, store, bit_width).await?.map(|kv| kv.value()))
}

#[inline]
pub async fn remove_entry<Q: ?Sized, S>(
pub async fn remove_entry<Q, S>(
&mut self,
k: &Q,
store: &S,
bit_width: u32,
) -> Result<Option<(K, V)>>
where
K: Borrow<Q>,
Q: Eq + Hash + TargetConditionalSendSync,
Q: ?Sized + TargetConditionalSendSync + Eq + Hash,
S: BlockStore,
{
self.rm_value(HashBits::new(H::hash(k)), bit_width, 0, k, store)
Expand Down Expand Up @@ -241,23 +238,24 @@ where
}

/// Search for a key.
async fn search<Q: ?Sized + TargetConditionalSendSync, S: BlockStore>(
async fn search<Q, S>(
&self,
q: &Q,
store: &S,
bit_width: u32,
) -> Result<Option<&KeyValuePair<K, V>>>
where
K: Borrow<Q>,
Q: Eq + Hash,
Q: ?Sized + TargetConditionalSendSync + Eq + Hash,
S: BlockStore,
{
self.get_value(HashBits::new(H::hash(q)), bit_width, 0, q, store)
.await
}

#[cfg_attr(target_arch="wasm32", async_recursion(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
async fn get_value<Q: ?Sized + TargetConditionalSendSync, S: BlockStore>(
async fn get_value<Q, S>(
&self,
mut hashed_key: HashBits,
bit_width: u32,
Expand All @@ -267,7 +265,8 @@ where
) -> Result<Option<&KeyValuePair<K, V>>>
where
K: Borrow<Q>,
Q: Eq + Hash,
Q: ?Sized + TargetConditionalSendSync + Eq + Hash,
S: BlockStore,
{
let idx = hashed_key.next(bit_width)?;

Expand Down Expand Up @@ -315,7 +314,7 @@ where
#[allow(clippy::too_many_arguments)]
#[cfg_attr(target_arch="wasm32", async_recursion(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
async fn modify_value<S: BlockStore>(
async fn modify_value<S>(
&mut self,
mut hashed_key: HashBits,
bit_width: u32,
Expand All @@ -327,6 +326,7 @@ where
) -> Result<(Option<V>, bool)>
where
V: PartialEq + TargetConditionalSendSync,
S: BlockStore,
{
let idx = hashed_key.next(bit_width)?;

Expand Down Expand Up @@ -446,7 +446,7 @@ where
/// Internal method to delete entries.
#[cfg_attr(target_arch="wasm32", async_recursion(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
async fn rm_value<Q: ?Sized + TargetConditionalSendSync, S: BlockStore>(
async fn rm_value<Q, S>(
&mut self,
mut hashed_key: HashBits,
bit_width: u32,
Expand All @@ -456,7 +456,8 @@ where
) -> Result<Option<(K, V)>>
where
K: Borrow<Q>,
Q: Hash + Eq,
Q: ?Sized + TargetConditionalSendSync + Eq + Hash,
S: BlockStore,
{
let idx = hashed_key.next(bit_width)?;

Expand Down Expand Up @@ -521,7 +522,10 @@ where

#[cfg_attr(target_arch="wasm32", async_recursion(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_recursion)]
pub async fn flush<S: BlockStore>(&mut self, store: &mut S) -> Result<()> {
pub async fn flush<S>(&mut self, store: &mut S) -> Result<()>
where
S: BlockStore,
{
for pointer in &mut self.pointers {
if let Pointer::Dirty(node) = pointer {
// Flush cached sub node to clear it's cache
Expand Down

0 comments on commit ac7f5fc

Please sign in to comment.