pub struct Network { /* private fields */ }Expand description
A network of nodes and edges.
Rows are stored in compressed sparse row (CSR) format, with an edge list for the view to draw.
Implementations§
Source§impl Network
impl Network
Sourcepub fn new(nodes: usize, directed: bool) -> Self
pub fn new(nodes: usize, directed: bool) -> Self
Creates a new Network with nodes slots and no edges. All slots are considered occupied with a node.
Sourcepub fn slot_count(&self) -> usize
pub fn slot_count(&self) -> usize
Number of total slots.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes.
Sourcepub fn contains_node(&self, i: u32) -> bool
pub fn contains_node(&self, i: u32) -> bool
Whether slot i is occupied by a node.
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Version of the graph. It goes up whenever the edges, their colours or their direction change.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges.
Sourcepub fn update_colors(
&mut self,
f: impl FnOnce(&[u32], &[u32], &mut [u8]) -> bool,
)
pub fn update_colors( &mut self, f: impl FnOnce(&[u32], &[u32], &mut [u8]) -> bool, )
Calls f with the edge list and a mutable slice of the edge colours, for recolouring edges in bulk.
f returns whether it changed any colour. The version is incremented only if it did,
so a recolour that changes nothing does not make the view copy the edge list again.
Sourcepub fn set_edge_color(&mut self, edge: u32, color: u8)
pub fn set_edge_color(&mut self, edge: u32, color: u8)
Sets the color of edge edge to color.
Sourcepub fn add_edge(&mut self, a: u32, b: u32, color: u8) -> u32
pub fn add_edge(&mut self, a: u32, b: u32, color: u8) -> u32
Creates a new edge from a to b with color color, returning its index in the edge list.
Repeated edges are allowed.
§Panics
Panics on debug builds if a == b.
Sourcepub fn remove_edge(&mut self, edge: u32)
pub fn remove_edge(&mut self, edge: u32)
Removes edge edge from the graph.
Sourcepub fn in_neighbors(&self, i: u32) -> &[u32]
pub fn in_neighbors(&self, i: u32) -> &[u32]
Returns the nodes that have an edge to i.
Sourcepub fn out_neighbors(&self, i: u32) -> &[u32]
pub fn out_neighbors(&self, i: u32) -> &[u32]
Returns the nodes that i has an edge to.
Sourcepub fn degree(&self, i: u32) -> usize
pub fn degree(&self, i: u32) -> usize
Returns the degree of the node. On directed graphs, this is the sum of in-degree and out-degree.
Sourcepub fn edge_between(&self, a: u32, b: u32) -> Option<u32>
pub fn edge_between(&self, a: u32, b: u32) -> Option<u32>
Returns the index of an edge from a to b in the edge list, if there is one.
On undirected graphs, an edge in either direction counts, and the shorter of the two rows is searched.
On directed graphs, the out-row of a is searched.
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
Heap memory held by the graph, in bytes.