pub struct DiHypergraph<N = Value, E = Value, M = Value> { /* private fields */ }Expand description
A directed hypergraph. XGI parity: xgi.DiHypergraph.
§Type Parameters
N— node attribute type (defaultserde_json::Value)E— hyperedge attribute type (defaultserde_json::Value)M— per-membership attribute type (defaultserde_json::Value)
Implementations§
Source§impl<N, E, M> DiHypergraph<N, E, M>
impl<N, E, M> DiHypergraph<N, E, M>
Sourcepub fn has_edge(&self, edge_id: &str) -> bool
pub fn has_edge(&self, edge_id: &str) -> bool
Whether an edge exists. XGI parity: e in DH.edges.
Sourcepub fn add_node(&mut self, node_id: &str, attrs: N) -> bool
pub fn add_node(&mut self, node_id: &str, attrs: N) -> bool
Add a node with attributes. Returns true if newly created.
XGI parity: DH.add_node(node, **attr) (dihypergraph.py:327-349).
If node_id already exists, its stored attrs are REPLACED (XGI’s
binding merges the incoming dict into the existing one before
calling; a generic N can’t merge, so the core replaces and the
PyO3 layer composes the merge on top — divergence D6).
Sourcepub fn graph_attr(&self, key: &str) -> Option<&Value>
pub fn graph_attr(&self, key: &str) -> Option<&Value>
Read a graph-level attribute. XGI parity: DH["name"].
Sourcepub fn set_graph_attr(&mut self, key: &str, value: Value)
pub fn set_graph_attr(&mut self, key: &str, value: Value)
Set a graph-level attribute. XGI parity: DH["name"] = value.
Sourcepub fn node_attrs(&self, node_id: &str) -> Option<&N>
pub fn node_attrs(&self, node_id: &str) -> Option<&N>
Read a node’s attributes. XGI parity: DH.nodes[n].
Sourcepub fn edge_attrs(&self, edge_id: &str) -> Option<&E>
pub fn edge_attrs(&self, edge_id: &str) -> Option<&E>
Read a hyperedge’s attributes. XGI parity: DH.edges[e].
Sourcepub fn next_edge_id(&self) -> u64
pub fn next_edge_id(&self) -> u64
The id the next edge added without an explicit id will get.
XGI parity: DH._edge_uid.
Sourcepub fn update_uid_counter(&mut self, idx: u64)
pub fn update_uid_counter(&mut self, idx: u64)
Raise the counter past idx: if next_edge_id() <= idx, it becomes
idx + 1. XGI parity: update_uid_counter. Not a structural change,
so it is allowed on a frozen hypergraph. At idx == u64::MAX the
counter saturates there instead of overflowing.
Sourcepub fn add_edge(
&mut self,
tail: Vec<String>,
head: Vec<String>,
idx: Option<String>,
attrs: E,
) -> Result<String, EdgeError>
pub fn add_edge( &mut self, tail: Vec<String>, head: Vec<String>, idx: Option<String>, attrs: E, ) -> Result<String, EdgeError>
Add a directed hyperedge with the given tail (senders) and head
(receivers). Auto-creates member nodes. XGI parity:
DH.add_edge((tail, head), idx=) (dihypergraph.py:525-585).
Deviations: Err(EdgeError::AlreadyExists) on a duplicate idx
(deviation #2). D1: an all-empty (tail, head) pair creates an empty
edge, matching the XGI runtime.
Sourcepub fn node_ids(&self) -> Vec<String>
pub fn node_ids(&self) -> Vec<String>
All node ids, insertion order. XGI parity: list(DH.nodes).
Sourcepub fn edge_ids(&self) -> Vec<String>
pub fn edge_ids(&self) -> Vec<String>
All edge ids, insertion order. XGI parity: list(DH.edges).
Sourcepub fn dimembers(&self, edge_id: &str) -> Option<(Vec<String>, Vec<String>)>
pub fn dimembers(&self, edge_id: &str) -> Option<(Vec<String>, Vec<String>)>
(tail, head) node ids of an edge, in membership-add order (D5 owner
upgrade: petgraph’s edges_directed walks each node’s adjacency list
in REVERSE insertion order, so we collect + reverse before splitting
by role). XGI parity: DH.edges.dimembers(e) = (edge[“in”],
edge[“out”]) (views.py:1017-1071), except XGI’s sets are
hash-unordered; we are strictly more defined.
Sourcepub fn tail(&self, edge_id: &str) -> Option<Vec<String>>
pub fn tail(&self, edge_id: &str) -> Option<Vec<String>>
Tail (sender) node ids. XGI parity: DH.edges.tail(e).
Sourcepub fn head(&self, edge_id: &str) -> Option<Vec<String>>
pub fn head(&self, edge_id: &str) -> Option<Vec<String>>
Head (receiver) node ids. XGI parity: DH.edges.head(e).
Sourcepub fn members(&self, edge_id: &str) -> Option<Vec<String>>
pub fn members(&self, edge_id: &str) -> Option<Vec<String>>
Union of tail and head, tail-then-head first-seen order (D5 owner
upgrade). XGI parity: DH.edges.members(e).
Sourcepub fn dimemberships(&self, node_id: &str) -> Option<(Vec<String>, Vec<String>)>
pub fn dimemberships(&self, node_id: &str) -> Option<(Vec<String>, Vec<String>)>
(in, out) edge ids for a node: in = edges where the node is a head
(receiver), out = edges where it is a tail (sender), in
membership-add order (D5 owner upgrade; see Self::dimembers for
the reverse-adjacency correction). XGI parity: DH.nodes.dimemberships(n)
= (node[“in”], node[“out”]) (views.py:889-918).
Sourcepub fn memberships(&self, node_id: &str) -> Option<Vec<String>>
pub fn memberships(&self, node_id: &str) -> Option<Vec<String>>
All edge ids the node belongs to (head or tail), first-seen edge
order (D5 owner upgrade): the raw chronological order in which the
node was added to each edge, deduped (a node in both directions of
the same edge counts once, at its first occurrence). XGI parity:
DH.nodes.memberships(n).
Sourcepub fn remove_edge(&mut self, edge_id: &str) -> Result<(), EdgeError>
pub fn remove_edge(&mut self, edge_id: &str) -> Result<(), EdgeError>
Remove an edge. XGI parity: DH.remove_edge(idx) (dihypergraph.py:834-860).
Sourcepub fn remove_node(
&mut self,
node_id: &str,
strong: bool,
remove_empty: bool,
) -> Result<(), NodeError>
pub fn remove_node( &mut self, node_id: &str, strong: bool, remove_empty: bool, ) -> Result<(), NodeError>
Remove a node. Weak removal detaches the node from its edges and drops
edges that become empty (when remove_empty); strong removal drops all
containing edges. XGI parity: DH.remove_node(n, strong, remove_empty)
(dihypergraph.py:385-436).
Sourcepub fn add_node_to_edge(
&mut self,
edge_id: &str,
node_id: &str,
role: DiRole,
) -> Result<(), EdgeError>
pub fn add_node_to_edge( &mut self, edge_id: &str, node_id: &str, role: DiRole, ) -> Result<(), EdgeError>
Add a node to an edge in the given role. Auto-creates both if missing.
XGI parity: DH.add_node_to_edge(edge, node, direction)
(dihypergraph.py:794-832).
Sourcepub fn member_data(
&self,
edge_id: &str,
node_id: &str,
role: DiRole,
) -> Option<&M>
pub fn member_data( &self, edge_id: &str, node_id: &str, role: DiRole, ) -> Option<&M>
The value the membership of node_id in edge_id in the given role
carries. None when the edge or the node does not exist, or the node
is not in that role of the edge. A node in both the tail and the head
has two memberships with separate values.
A membership made by any constructor carries M::default() until a
value is written. XGI has no value on a membership, so the
XGI-compatible formats do not carry it.
use hypergraph_rs::{DiHypergraph, DiRole};
let mut d: DiHypergraph<(), (), u64> = DiHypergraph::new();
d.add_edge(vec!["x".into()], vec!["y".into()], Some("e".into()), ()).unwrap();
assert_eq!(d.member_data("e", "x", DiRole::Tail), Some(&0));
assert_eq!(d.member_data("e", "x", DiRole::Head), None);Sourcepub fn set_member_data(
&mut self,
edge_id: &str,
node_id: &str,
role: DiRole,
data: M,
) -> Result<(), MembershipError>
pub fn set_member_data( &mut self, edge_id: &str, node_id: &str, role: DiRole, data: M, ) -> Result<(), MembershipError>
Replace that value. Refuses an unknown edge, an unknown node, and a node that is not in that role of the edge. Panics on a frozen directed hypergraph, like every mutator.
use hypergraph_rs::{DiHypergraph, DiRole};
let mut d: DiHypergraph<(), (), u64> = DiHypergraph::new();
d.add_edge(vec!["x".into()], vec!["y".into()], Some("e".into()), ()).unwrap();
d.set_member_data("e", "x", DiRole::Tail, 3).unwrap();
assert_eq!(d.member_data("e", "x", DiRole::Tail), Some(&3));
assert!(d.set_member_data("e", "x", DiRole::Head, 3).is_err());Sourcepub fn dimembers_with_data(
&self,
edge_id: &str,
) -> Option<(Vec<(String, &M)>, Vec<(String, &M)>)>
pub fn dimembers_with_data( &self, edge_id: &str, ) -> Option<(Vec<(String, &M)>, Vec<(String, &M)>)>
(tail with values, head with values), each in the order of
Self::dimembers. None when the edge does not exist.
use hypergraph_rs::{DiHypergraph, DiRole};
let mut d: DiHypergraph<(), (), u64> = DiHypergraph::new();
d.add_edge(vec!["x".into()], vec!["y".into()], Some("e".into()), ()).unwrap();
d.set_member_data("e", "y", DiRole::Head, 4).unwrap();
assert_eq!(
d.dimembers_with_data("e"),
Some((vec![("x".to_string(), &0)], vec![("y".to_string(), &4)]))
);Sourcepub fn add_node_to_edge_with_data(
&mut self,
edge_id: &str,
node_id: &str,
role: DiRole,
data: M,
) -> Result<(), EdgeError>
pub fn add_node_to_edge_with_data( &mut self, edge_id: &str, node_id: &str, role: DiRole, data: M, ) -> Result<(), EdgeError>
Self::add_node_to_edge, with the value the new membership carries.
Auto-creates the edge and the node if missing. If the node is already
in that role of the edge, its value is replaced.
use hypergraph_rs::{DiHypergraph, DiRole};
let mut d: DiHypergraph<(), (), u64> = DiHypergraph::new();
d.add_node_to_edge_with_data("e", "a", DiRole::Head, 5).unwrap();
d.add_node_to_edge_with_data("e", "a", DiRole::Head, 9).unwrap();
assert_eq!(d.member_data("e", "a", DiRole::Head), Some(&9));Sourcepub fn remove_node_from_edge(
&mut self,
edge_id: &str,
node_id: &str,
role: DiRole,
remove_empty: bool,
) -> Result<(), MembershipError>
pub fn remove_node_from_edge( &mut self, edge_id: &str, node_id: &str, role: DiRole, remove_empty: bool, ) -> Result<(), MembershipError>
Remove a node from an edge’s given role. Errors if the edge/node is
missing or the node is not in that role-set; drops the edge if empty and
remove_empty. XGI parity: DH.remove_node_from_edge(edge, node, direction, remove_empty) (dihypergraph.py:891-943). XGI raises
XGIError for a missing edge, a missing node, or a node not a
member in that direction — the core returns the matching
MembershipError variant and the PyO3 binding translates
Err -> raise, reproducing XGI’s exact per-direction messages
(D2 error channel).
Sourcepub fn degree(&self, node_id: &str) -> usize
pub fn degree(&self, node_id: &str) -> usize
Node degree: number of distinct edges it belongs to. XGI parity:
DH.nodes.degree (dinodestats.py:138-139).
Sourcepub fn in_degree(&self, node_id: &str) -> usize
pub fn in_degree(&self, node_id: &str) -> usize
Node in-degree: edges where the node is a head (receiver).
Sourcepub fn out_degree(&self, node_id: &str) -> usize
pub fn out_degree(&self, node_id: &str) -> usize
Node out-degree: edges where the node is a tail (sender).
Sourcepub fn size(&self, edge_id: &str) -> usize
pub fn size(&self, edge_id: &str) -> usize
Edge size: |tail ∪ head|. XGI parity: DH.edges.size.
Sourcepub fn tail_order(&self, edge_id: &str) -> usize
pub fn tail_order(&self, edge_id: &str) -> usize
Tail size − 1.
Sourcepub fn head_order(&self, edge_id: &str) -> usize
pub fn head_order(&self, edge_id: &str) -> usize
Head size − 1.
Sourcepub fn isolate_node_ids(&self) -> Vec<String>
pub fn isolate_node_ids(&self) -> Vec<String>
Node ids with degree 0. XGI parity: DH.nodes.isolates().
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all nodes and edges (keeps the uid counter, like Phase 1).
XGI parity: DH.clear() (dihypergraph.py:1000-1017).
Trait Implementations§
Source§impl<N, E, M> Debug for DiHypergraph<N, E, M>
impl<N, E, M> Debug for DiHypergraph<N, E, M>
Source§impl<N, E, M> Default for DiHypergraph<N, E, M>
impl<N, E, M> Default for DiHypergraph<N, E, M>
Auto Trait Implementations§
impl<N, E, M> Forget for DiHypergraph<N, E, M>
impl<N, E, M> Freeze for DiHypergraph<N, E, M>where
*const u8 is !null: Freeze,
PhantomData<Node<Option<NodeKind<N, E>>>>: Freeze,
PhantomData<Edge<Option<DiMembershipEdge<M>>>>: Freeze,
PhantomData<Directed>: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, NodeIndex>>: Freeze,
PhantomData<(NodeIndex, String)>: Freeze,
*const LeafNode<String, Value> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, Value)>>: Freeze,
impl<N, E, M> Move for DiHypergraph<N, E, M>
impl<N, E, M> RefUnwindSafe for DiHypergraph<N, E, M>
impl<N, E, M> Send for DiHypergraph<N, E, M>
impl<N, E, M> Sync for DiHypergraph<N, E, M>
impl<N, E, M> Unpin for DiHypergraph<N, E, M>
impl<N, E, M> UnsafeUnpin for DiHypergraph<N, E, M>where
*const u8 is !null: UnsafeUnpin,
PhantomData<Node<Option<NodeKind<N, E>>>>: UnsafeUnpin,
PhantomData<Edge<Option<DiMembershipEdge<M>>>>: UnsafeUnpin,
PhantomData<Directed>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, NodeIndex>>: UnsafeUnpin,
PhantomData<(NodeIndex, String)>: UnsafeUnpin,
*const LeafNode<String, Value> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Value)>>: UnsafeUnpin,
impl<N, E, M> UnwindSafe for DiHypergraph<N, E, M>where
RawVecInner: UnwindSafe,
N: UnwindSafe,
E: UnwindSafe,
M: UnwindSafe,
NonNull<u8>: UnwindSafe,
HashMap<NodeIndex, String>: UnwindSafe,
BTreeMap<String, Value>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.