AdjList

Struct AdjList 

Source
pub struct AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,
{ /* private fields */ }
Expand description

Graph represented as Adjacency list. Directly support both direct and undirect graphs. This representation offers a minimal memory foot print - it keeps information only about existing arcs - at the cost of some inefficiencies in some opertations. The memory footprint of an AdJList is always O(|N|) + O(|A|), where |N| is the number of nodes and |A| is the number of arcs in the graph.

Implementations§

Source§

impl<N> AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source

pub fn new_direct(node_count: usize) -> Self

Create a new direct graph with the given number of nodes. The resulting graph will NOT contain arcs. All nodes’ weights are set to num_traits::Num::zero()

Source

pub fn new_undirect(node_count: usize) -> Self

Create a new undirect graph with the given number of nodes. The resulting graph will NOT contain arcs. All nodes’ weights are set to num_traits::Num::zero()

Source

pub fn node_iterator(&self) -> impl Iterator<Item = (usize, N)> + '_

Return an iterator over the nodes.

Source

pub fn arc_iterator(&self) -> impl Iterator<Item = (usize, usize, N)> + '_

Return an iterator over all the arcs in the graph.

Source

pub fn successor_iterator( &self, node: usize, ) -> impl Iterator<Item = (usize, usize, N)> + '_

Return an iterator over the arcs exiting the given nodes.

Trait Implementations§

Source§

impl<N> ArcCost<N> for &AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

fn cost(&self, src: usize, dst: usize) -> N

Return the weight associated to given arc.
Source§

impl<N> Clone for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize + Clone,

Source§

fn clone(&self) -> AdjList<N>

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<N> Debug for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize + Debug,

Source§

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

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

impl<'de, N> Deserialize<'de> for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize + Deserialize<'de>,

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<N> From<AdjList<N>> for MathGraph<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

fn from(adj: AdjList<N>) -> Self

Converts to this type from the input type.
Source§

impl<N> From<MathGraph<N>> for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

fn from(g: MathGraph<N>) -> Self

Converts to this type from the input type.
Source§

impl<N> GetGraphType for &AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

impl<N> GetGraphType for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

impl<N> Graph<N> for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

fn new(node_count: usize, gtype: GraphType) -> Self

Initialize a new directed or undirecte graph with the given number of nodes.
Source§

fn add_new_default_arc(&mut self, src: usize, dst: usize)

Create a new arc from src to dst (and from dst to src if the graph is undirected) and associtate with this new arc the cost num_traits::Num::zero()
Source§

fn add_new_arc(&mut self, src: usize, dst: usize, weight: N)

Create a new arc from src to dst (and from dst to src if the graph is undirected) and associtate with this new arc the cost weight
Source§

fn update_all_arcs_weight<F>(&mut self, f: F)
where F: Fn(usize, usize, N) -> N,

Update all arcs weight using the given callback function. At each function call the first argument is the index of the source node, the second is the index of the destination node and the third is the current weight of the arc. Note: in undirect graph the arc (i, j) is equivalent to the node (j, i) and the implementation should, for efficiency and reduce mistakes, call f for just one arc.
Source§

fn update_all_nodes_weight<F>(&mut self, f: F)
where F: Fn(usize, N) -> N,

Update all nodes weights using the given callback function. The first argument to each call is the index of the node and the second is its current weight.
Source§

impl<N> GraphVisitor<N> for &AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Source§

fn node_visitor<F: FnMut(usize, N)>(&self, f: F)

Call function f for each node in the graph. At each call the first argument is a node’s index and the second is the current node weight.
Source§

fn arc_visitor<G: FnMut(usize, usize, N)>(&self, g: G)

Call function g for each arc in the graph. At each call the first argument is the source node index, the second is destination node index and the third the current arc weight.
Source§

fn node_count(&self) -> usize

Return the number of nodes in the graph.
Source§

fn arc_count(&self) -> usize

Return the number of arcs in the graph.
Source§

fn total_entries(&self) -> usize

Return the total number of nodes and arcs in the graph.
Source§

impl<N> PartialEq for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize + PartialEq,

Source§

fn eq(&self, other: &AdjList<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<N> Serialize for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize + Serialize,

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

impl<N> StructuralPartialEq for AdjList<N>
where N: Num + Default + Clone + Copy + Serialize,

Auto Trait Implementations§

§

impl<N> Freeze for AdjList<N>

§

impl<N> RefUnwindSafe for AdjList<N>
where N: RefUnwindSafe,

§

impl<N> Send for AdjList<N>
where N: Send,

§

impl<N> Sync for AdjList<N>
where N: Sync,

§

impl<N> Unpin for AdjList<N>
where N: Unpin,

§

impl<N> UnwindSafe for AdjList<N>
where N: UnwindSafe,

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> 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>,