Struct ipld_amt::Amt [−][src]
pub struct Amt<'db, V, BS> { /* fields omitted */ }
Array Mapped Trie allows for the insertion and persistence of data, serializable to a CID.
Amt is not threadsafe and can’t be shared between threads.
Usage:
use ipld_amt::Amt; let db = db::MemoryDB::default(); let mut amt = Amt::new(&db); // Insert or remove any serializable values amt.set(2, "foo".to_owned()).unwrap(); amt.set(1, "bar".to_owned()).unwrap(); amt.delete(2).unwrap(); assert_eq!(amt.count(), 1); let bar: &String = amt.get(1).unwrap().unwrap(); // Generate cid by calling flush to remove cache let cid = amt.flush().unwrap();
Implementations
impl<'db, V, BS> Amt<'db, V, BS> where
V: DeserializeOwned + Serialize,
BS: BlockStore,
[src]
V: DeserializeOwned + Serialize,
BS: BlockStore,
pub fn new(block_store: &'db BS) -> Self
[src]
Constructor for Root AMT node
pub fn new_with_bit_width(block_store: &'db BS, bit_width: usize) -> Self
[src]
Construct new Amt with given bit width.
pub fn load(cid: &Cid, block_store: &'db BS) -> Result<Self, Error>
[src]
Constructs an AMT with a blockstore and a Cid of the root of the AMT
pub fn height(&self) -> usize
[src]
Gets the height of the Amt
.
pub fn count(&self) -> usize
[src]
Gets count of elements added in the Amt
.
pub fn new_from_iter(
block_store: &'db BS,
vals: impl IntoIterator<Item = V>
) -> Result<Cid, Error>
[src]
block_store: &'db BS,
vals: impl IntoIterator<Item = V>
) -> Result<Cid, Error>
Generates an AMT with block store and array of cbor marshallable objects and returns Cid
pub fn get(&self, i: usize) -> Result<Option<&V>, Error>
[src]
Get value at index of AMT
pub fn set(&mut self, i: usize, val: V) -> Result<(), Error>
[src]
Set value at index
pub fn batch_set(
&mut self,
vals: impl IntoIterator<Item = V>
) -> Result<(), Error>
[src]
&mut self,
vals: impl IntoIterator<Item = V>
) -> Result<(), Error>
Batch set (naive for now)
pub fn delete(&mut self, i: usize) -> Result<Option<V>, Error>
[src]
Delete item from AMT at index
pub fn batch_delete(
&mut self,
iter: impl IntoIterator<Item = usize>,
strict: bool
) -> Result<bool, Error>
[src]
&mut self,
iter: impl IntoIterator<Item = usize>,
strict: bool
) -> Result<bool, Error>
Deletes multiple items from AMT
If strict
is true, all indices are expected to be present, and this will
return an error if one is not found.
Returns true if items were deleted.
pub fn flush(&mut self) -> Result<Cid, Error>
[src]
flush root and return Cid used as key in block store
pub fn for_each<F>(&self, f: F) -> Result<(), Box<dyn StdError>> where
F: FnMut(usize, &V) -> Result<(), Box<dyn StdError>>,
[src]
F: FnMut(usize, &V) -> Result<(), Box<dyn StdError>>,
Iterates over each value in the Amt and runs a function on the values.
The index in the amt is a usize
and the value is the generic parameter V
as defined
in the Amt.
Examples
use ipld_amt::Amt; let store = db::MemoryDB::default(); let mut map: Amt<String, _> = Amt::new(&store); map.set(1, "One".to_owned()).unwrap(); map.set(4, "Four".to_owned()).unwrap(); let mut values: Vec<(usize, String)> = Vec::new(); map.for_each(|i, v| { values.push((i, v.clone())); Ok(()) }).unwrap(); assert_eq!(&values, &[(1, "One".to_owned()), (4, "Four".to_owned())]);
pub fn for_each_while<F>(&self, f: F) -> Result<(), Box<dyn StdError>> where
F: FnMut(usize, &V) -> Result<bool, Box<dyn StdError>>,
[src]
F: FnMut(usize, &V) -> Result<bool, Box<dyn StdError>>,
Iterates over each value in the Amt and runs a function on the values, for as long as that
function keeps returning true
.
pub fn for_each_mut<F>(&mut self, f: F) -> Result<(), Box<dyn StdError>> where
V: Clone,
F: FnMut(usize, &mut ValueMut<'_, V>) -> Result<(), Box<dyn StdError>>,
[src]
V: Clone,
F: FnMut(usize, &mut ValueMut<'_, V>) -> Result<(), Box<dyn StdError>>,
Iterates over each value in the Amt and runs a function on the values that allows modifying each value.
pub fn for_each_while_mut<F>(&mut self, f: F) -> Result<(), Box<dyn StdError>> where
V: Clone,
F: FnMut(usize, &mut ValueMut<'_, V>) -> Result<bool, Box<dyn StdError>>,
[src]
V: Clone,
F: FnMut(usize, &mut ValueMut<'_, V>) -> Result<bool, Box<dyn StdError>>,
Iterates over each value in the Amt and runs a function on the values that allows modifying
each value, for as long as that function keeps returning true
.
Trait Implementations
impl<'db, V: Debug, BS: Debug> Debug for Amt<'db, V, BS>
[src]
impl<'a, V: PartialEq, BS: BlockStore> PartialEq<Amt<'a, V, BS>> for Amt<'a, V, BS>
[src]
Auto Trait Implementations
impl<'db, V, BS> RefUnwindSafe for Amt<'db, V, BS> where
BS: RefUnwindSafe,
V: RefUnwindSafe + UnwindSafe,
BS: RefUnwindSafe,
V: RefUnwindSafe + UnwindSafe,
impl<'db, V, BS> Send for Amt<'db, V, BS> where
BS: Sync,
V: Send,
BS: Sync,
V: Send,
impl<'db, V, BS> !Sync for Amt<'db, V, BS>
impl<'db, V, BS> Unpin for Amt<'db, V, BS> where
V: Unpin,
V: Unpin,
impl<'db, V, BS> UnwindSafe for Amt<'db, V, BS> where
BS: RefUnwindSafe,
V: UnwindSafe,
BS: RefUnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,