[−][src]Struct ipld_amt::Amt
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 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) -> u64
[src]
Gets the height of the Amt
.
pub fn count(&self) -> u64
[src]
Gets count of elements added in the Amt
.
pub fn new_from_slice(block_store: &'db BS, vals: &[V]) -> Result<Cid, Error> where
V: Clone,
[src]
V: Clone,
Generates an AMT with block store and array of cbor marshallable objects and returns Cid
pub fn get(&self, i: u64) -> Result<Option<&V>, Error>
[src]
Get value at index of AMT
pub fn set(&mut self, i: u64, val: V) -> Result<(), Error>
[src]
Set value at index
pub fn batch_set(&mut self, vals: &[V]) -> Result<(), Error> where
V: Clone,
[src]
V: Clone,
Batch set (naive for now)
pub fn delete(&mut self, i: u64) -> Result<bool, Error>
[src]
Delete item from AMT at index
pub fn batch_delete(
&mut self,
iter: impl IntoIterator<Item = u64>
) -> Result<(), Error>
[src]
&mut self,
iter: impl IntoIterator<Item = u64>
) -> Result<(), Error>
Deletes multiple items from AMT
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(u64, &V) -> Result<(), Box<dyn StdError>>,
[src]
F: FnMut(u64, &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 u64
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<(u64, 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(u64, &V) -> Result<bool, Box<dyn StdError>>,
[src]
F: FnMut(u64, &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(u64, &mut ValueMut<'_, V>) -> Result<(), Box<dyn StdError>>,
[src]
V: Clone,
F: FnMut(u64, &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(u64, &mut ValueMut<'_, V>) -> Result<bool, Box<dyn StdError>>,
[src]
V: Clone,
F: FnMut(u64, &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>
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>,