Skip to content
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
51 changes: 26 additions & 25 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fvm_integration_tests = { path = "testing/integration", version = "~4.7.3" }

# workspace (other)
fvm_ipld_amt = { path = "ipld/amt", version = "0.7.5" }
fvm_ipld_hamt = { path = "ipld/hamt", version = "0.10.4" }
fvm_ipld_hamt = { path = "ipld/hamt", version = "0.11.0" }
fvm_ipld_kamt = { path = "ipld/kamt", version = "0.4.5" }
fvm_ipld_car = { path = "ipld/car", version = "0.9.0" }
fvm_ipld_blockstore = { path = "ipld/blockstore", version = "0.3.1" }
Expand Down
3 changes: 2 additions & 1 deletion ipld/hamt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fvm_ipld_hamt"
description = "Sharded IPLD HashMap implementation."
version = "0.10.4"
version = "0.11.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do this as a separate PR

license.workspace = true
authors = ["ChainSafe Systems <[email protected]>", "Protocol Labs", "Filecoin Core Devs"]
edition.workspace = true
Expand All @@ -28,6 +28,7 @@ identity = []
[dev-dependencies]
hex = { workspace = true }
criterion = { workspace = true }
itertools = { workspace = true}
unsigned-varint = { workspace = true }
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
Expand Down
31 changes: 16 additions & 15 deletions ipld/hamt/src/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use multihash_codetable::Code;
use serde::de::DeserializeOwned;
use serde::{Serialize, Serializer};

use crate::iter::IterImpl;
use crate::iter::{IterImpl, IterItem};
use crate::node::Node;
use crate::pointer::version::Version;
use crate::{Config, Error, Hash, HashAlgorithm, Sha256, pointer::version};
Expand Down Expand Up @@ -372,12 +372,13 @@ where
#[inline]
pub fn for_each<F>(&self, mut f: F) -> Result<(), Error>
where
V: DeserializeOwned,
K: Clone,
V: DeserializeOwned + Clone,
F: FnMut(&K, &V) -> anyhow::Result<()>,
{
for res in self {
let (k, v) = res?;
(f)(k, v)?;
(f)(k.as_ref(), v.as_ref())?;
}
Ok(())
}
Expand Down Expand Up @@ -430,7 +431,7 @@ where
where
K: Borrow<Q> + Clone,
Q: Eq + Hash + ?Sized,
V: DeserializeOwned,
V: DeserializeOwned + Clone,
F: FnMut(&K, &V) -> anyhow::Result<()>,
{
let mut iter = match &starting_key {
Expand All @@ -441,10 +442,10 @@ where
let mut traversed = 0usize;
for res in iter.by_ref().take(max.unwrap_or(usize::MAX)) {
let (k, v) = res?;
(f)(k, v)?;
(f)(k.as_ref(), v.as_ref())?;
traversed += 1;
}
let next = iter.next().transpose()?.map(|kv| kv.0).cloned();
let next = iter.next().transpose()?.map(|kv| kv.0.as_ref().clone());
Ok((traversed, next))
}

Expand All @@ -456,8 +457,8 @@ where

impl<BS, V, K, H, Ver> HamtImpl<BS, V, K, H, Ver>
where
K: DeserializeOwned + PartialOrd,
V: DeserializeOwned,
K: DeserializeOwned + PartialOrd + Clone,
V: DeserializeOwned + Clone,
Ver: Version,
BS: Blockstore,
{
Expand All @@ -476,7 +477,7 @@ where
///
/// for kv in &hamt {
/// let (k, v) = kv?;
/// println!("{k:?}: {v}");
/// println!("{:?}: {}", k.as_ref(), v.as_ref());
/// }
///
/// # anyhow::Ok(())
Expand Down Expand Up @@ -510,13 +511,13 @@ where
/// assert_eq!(results.len(), 2);
///
/// // Read the rest then sort.
/// for res in hamt.iter_from(results.last().unwrap().0)?.skip(1) {
/// for res in hamt.iter_from(results.last().unwrap().0.as_ref())?.skip(1) {
/// results.push((res?));
/// }
/// results.sort_by_key(|kv| kv.1);
/// results.sort_by_key(|kv| kv.1.clone());
///
/// // Assert that we got out what we put in.
/// let results: Vec<_> = results.into_iter().map(|(k, v)|(k.clone(), v.clone())).collect();
/// let results: Vec<_> = results.into_iter().map(|(k, v)|(k.as_ref().clone(), v.as_ref().clone())).collect();
/// assert_eq!(kvs, results);
///
/// # anyhow::Ok(())
Expand All @@ -533,12 +534,12 @@ where

impl<'a, BS, V, K, H, Ver> IntoIterator for &'a HamtImpl<BS, V, K, H, Ver>
where
K: DeserializeOwned + PartialOrd,
V: DeserializeOwned,
K: DeserializeOwned + PartialOrd + Clone,
V: DeserializeOwned + Clone,
Ver: Version,
BS: Blockstore,
{
type Item = Result<(&'a K, &'a V), Error>;
type Item = Result<(IterItem<'a, K>, IterItem<'a, V>), Error>;
type IntoIter = IterImpl<'a, BS, V, K, H, Ver>;

fn into_iter(self) -> Self::IntoIter {
Expand Down
Loading
Loading