MemoryDAGStore

Struct MemoryDAGStore 

Source
pub struct MemoryDAGStore {
    nodes: HashMap<Hash, MerkleNode>,
    heads: HashSet<Hash>,
    children_index: HashMap<Hash, HashSet<Hash>>,
    missing: HashSet<Hash>,
    cached_topo_order: RwLock<Option<Vec<Hash>>>,
}
Expand description

In-memory implementation of DAGStore.

Fields§

§nodes: HashMap<Hash, MerkleNode>

All nodes indexed by CID.

§heads: HashSet<Hash>

Current heads (nodes without children).

§children_index: HashMap<Hash, HashSet<Hash>>

Reverse index: parent -> children.

§missing: HashSet<Hash>

Referenced but missing nodes.

§cached_topo_order: RwLock<Option<Vec<Hash>>>

Cached topological order (invalidated on put/put_unchecked).

Implementations§

Source§

impl MemoryDAGStore

Source

pub fn new() -> Self

Create a new empty DAG store.

Source

pub fn with_genesis(creator: impl Into<String>) -> (Self, Hash)

Create a store with a genesis node.

Source

fn update_heads(&mut self, node: &MerkleNode)

Update the heads set after adding a node.

Source

fn update_children_index(&mut self, node: &MerkleNode)

Update the children index after adding a node.

Source

pub fn stats(&self) -> DAGStats

Get statistics about the DAG.

Source

fn compute_max_depth(&self) -> usize

Compute the maximum depth of the DAG.

Source

fn compute_branching_stats(&self) -> f64

Compute average branching factor.

Trait Implementations§

Source§

impl Clone for MemoryDAGStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DAGStore for MemoryDAGStore

Source§

fn get(&self, cid: &Hash) -> Option<&MerkleNode>

Get a node by its CID.
Source§

fn put(&mut self, node: MerkleNode) -> Result<Hash, DAGError>

Store a node, returning its CID. Read more
Source§

fn put_unchecked(&mut self, node: MerkleNode) -> Result<Hash, DAGError>

Store a node without checking for missing parents. Read more
Source§

fn heads(&self) -> Vec<Hash>

Get the current heads (nodes without children).
Source§

fn contains(&self, cid: &Hash) -> bool

Check if a node exists in the store.
Source§

fn ancestors(&self, cid: &Hash) -> HashSet<Hash>

Get all ancestors of a node (transitive closure).
Source§

fn children(&self, cid: &Hash) -> Vec<Hash>

Get immediate children of a node.
Source§

fn topological_order(&self) -> Vec<Hash>

Get all nodes in topological order (parents before children).
Source§

fn missing_nodes(&self) -> HashSet<Hash>

Get nodes that are missing (referenced but not present).
Source§

fn len(&self) -> usize

Get the total number of nodes.
Source§

fn is_empty(&self) -> bool

Check if the store is empty.
Source§

impl Debug for MemoryDAGStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryDAGStore

Source§

fn default() -> MemoryDAGStore

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MemoryDAGStore

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MemoryDAGStore

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,