Skip to main content

Network

Struct Network 

Source
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

Source

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.

Source

pub fn slot_count(&self) -> usize

Number of total slots.

Source

pub fn node_count(&self) -> usize

Number of nodes.

Source

pub fn contains_node(&self, i: u32) -> bool

Whether slot i is occupied by a node.

Source

pub fn directed(&self) -> bool

Whether the edges are directed.

Source

pub fn version(&self) -> u64

Version of the graph. It goes up whenever the edges, their colours or their direction change.

Source

pub fn edge_count(&self) -> usize

Number of edges.

Source

pub fn edges(&self) -> (&[u32], &[u32], &[u8])

Returns the edge list as (src, dst, color).

Source

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.

Source

pub fn set_edge_color(&mut self, edge: u32, color: u8)

Sets the color of edge edge to color.

Source

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.

Source

pub fn remove_edge(&mut self, edge: u32)

Removes edge edge from the graph.

Source

pub fn in_neighbors(&self, i: u32) -> &[u32]

Returns the nodes that have an edge to i.

Source

pub fn out_neighbors(&self, i: u32) -> &[u32]

Returns the nodes that i has an edge to.

Source

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.

Source

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.

Source

pub fn has_edge(&self, a: u32, b: u32) -> bool

Returns whether there is an edge from a to b.

Source

pub fn heap_bytes(&self) -> usize

Heap memory held by the graph, in bytes.

Trait Implementations§

Source§

impl Debug for Network

Prints the graph’s size, not its edges.

Source§

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

Formats the value using the given formatter. 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> 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, 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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSync for T
where T: Sync,