Skip to main content

DiHypergraph

Struct DiHypergraph 

Source
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 (default serde_json::Value)
  • E — hyperedge attribute type (default serde_json::Value)
  • M — per-membership attribute type (default serde_json::Value)

Implementations§

Source§

impl<N, E, M> DiHypergraph<N, E, M>

Source

pub fn new() -> Self

Create an empty directed hypergraph.

Source

pub fn num_nodes(&self) -> usize

Number of nodes. XGI parity: DH.num_nodes.

Source

pub fn num_edges(&self) -> usize

Number of edges. XGI parity: DH.num_edges.

Source

pub fn has_node(&self, node_id: &str) -> bool

Whether a node exists. XGI parity: n in DH.

Source

pub fn has_edge(&self, edge_id: &str) -> bool

Whether an edge exists. XGI parity: e in DH.edges.

Source

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).

Source

pub fn graph_attr(&self, key: &str) -> Option<&Value>

Read a graph-level attribute. XGI parity: DH["name"].

Source

pub fn set_graph_attr(&mut self, key: &str, value: Value)

Set a graph-level attribute. XGI parity: DH["name"] = value.

Source

pub fn node_attrs(&self, node_id: &str) -> Option<&N>

Read a node’s attributes. XGI parity: DH.nodes[n].

Source

pub fn edge_attrs(&self, edge_id: &str) -> Option<&E>

Read a hyperedge’s attributes. XGI parity: DH.edges[e].

Source

pub fn next_edge_id(&self) -> u64

The id the next edge added without an explicit id will get. XGI parity: DH._edge_uid.

Source

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.

Source

pub fn add_edge( &mut self, tail: Vec<String>, head: Vec<String>, idx: Option<String>, attrs: E, ) -> Result<String, EdgeError>
where N: Default, M: Default + Clone,

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.

Source

pub fn node_ids(&self) -> Vec<String>

All node ids, insertion order. XGI parity: list(DH.nodes).

Source

pub fn edge_ids(&self) -> Vec<String>

All edge ids, insertion order. XGI parity: list(DH.edges).

Source

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.

Source

pub fn tail(&self, edge_id: &str) -> Option<Vec<String>>

Tail (sender) node ids. XGI parity: DH.edges.tail(e).

Source

pub fn head(&self, edge_id: &str) -> Option<Vec<String>>

Head (receiver) node ids. XGI parity: DH.edges.head(e).

Source

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).

Source

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).

Source

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).

Source

pub fn remove_edge(&mut self, edge_id: &str) -> Result<(), EdgeError>

Remove an edge. XGI parity: DH.remove_edge(idx) (dihypergraph.py:834-860).

Source

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).

Source

pub fn add_node_to_edge( &mut self, edge_id: &str, node_id: &str, role: DiRole, ) -> Result<(), EdgeError>
where N: Default, E: Default, M: Default + Clone,

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).

Source

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);
Source

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());
Source

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)]))
);
Source

pub fn add_node_to_edge_with_data( &mut self, edge_id: &str, node_id: &str, role: DiRole, data: M, ) -> Result<(), EdgeError>
where N: Default, E: Default,

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));
Source

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).

Source

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).

Source

pub fn in_degree(&self, node_id: &str) -> usize

Node in-degree: edges where the node is a head (receiver).

Source

pub fn out_degree(&self, node_id: &str) -> usize

Node out-degree: edges where the node is a tail (sender).

Source

pub fn size(&self, edge_id: &str) -> usize

Edge size: |tail ∪ head|. XGI parity: DH.edges.size.

Source

pub fn order(&self, edge_id: &str) -> usize

Edge order: size − 1. XGI parity: DH.edges.order.

Source

pub fn tail_size(&self, edge_id: &str) -> usize

Number of tail (sender) members.

Source

pub fn head_size(&self, edge_id: &str) -> usize

Number of head (receiver) members.

Source

pub fn tail_order(&self, edge_id: &str) -> usize

Tail size − 1.

Source

pub fn head_order(&self, edge_id: &str) -> usize

Head size − 1.

Source

pub fn isolate_node_ids(&self) -> Vec<String>

Node ids with degree 0. XGI parity: DH.nodes.isolates().

Source

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).

Source

pub fn copy(&self) -> Self
where N: Clone, E: Clone, M: Clone,

An independent deep copy. XGI parity: DH.copy(). D13: the copy carries frozen, unlike XGI’s copy() — XGI’s freeze is per-instance method-swizzling that a fresh instance never inherits, but the core’s frozen is data, so the safety property must propagate.

Source

pub fn freeze(&mut self)

Freeze against modification. XGI parity: DH.freeze().

Source

pub fn is_frozen(&self) -> bool

Whether the dihypergraph is frozen. XGI parity: DH.is_frozen.

Trait Implementations§

Source§

impl<N, E, M> Debug for DiHypergraph<N, E, M>

Source§

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

XGI parity: __repr__ = DiHypergraph([(tail, head), ...]).

Source§

impl<N, E, M> Default for DiHypergraph<N, E, M>

Source§

fn default() -> Self

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

impl<N: PartialEq, E: PartialEq, M> PartialEq for DiHypergraph<N, E, M>

Source§

fn eq(&self, other: &Self) -> bool

Equal iff same nodes (with attrs), same edges (with (tail,head) sets and attrs), and same graph attrs.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<N, E, M> Forget for DiHypergraph<N, E, M>

§

impl<N, E, M> Freeze for DiHypergraph<N, E, M>

§

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>
where M: Send, E: Send, N: Send, RawVecInner: Send, RawTable<usize>: Send, RawTable<(NodeIndex, String)>: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send,

§

impl<N, E, M> Sync for DiHypergraph<N, E, M>
where M: Sync, E: Sync, N: Sync, RawVecInner: Sync, RawTable<usize>: Sync, RawTable<(NodeIndex, String)>: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync,

§

impl<N, E, M> Unpin for DiHypergraph<N, E, M>
where M: Unpin, E: Unpin, N: Unpin, *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin,

§

impl<N, E, M> UnsafeUnpin for DiHypergraph<N, E, M>

§

impl<N, E, M> UnwindSafe for DiHypergraph<N, E, M>

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.