Type Alias bevy::utils::petgraph::prelude::DiGraphMap

``pub type DiGraphMap<N, E> = GraphMap<N, E, Directed>;``
Expand description

A `GraphMap` with directed edges.

For example, an edge from 1 to 2 is distinct from an edge from 2 to 1.

Aliased Type§

``struct DiGraphMap<N, E> { /* private fields */ }``

Implementations§

source§

impl<N, E, Ty> GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

source

pub fn new() -> GraphMap<N, E, Ty>

Create a new `GraphMap`

source

pub fn with_capacity(nodes: usize, edges: usize) -> GraphMap<N, E, Ty>

Create a new `GraphMap` with estimated capacity.

source

pub fn capacity(&self) -> (usize, usize)

Return the current node and edge capacity of the graph.

source

pub fn is_directed(&self) -> bool

Whether the graph has directed edges.

source

pub fn from_edges<I>(iterable: I) -> GraphMap<N, E, Ty>where I: IntoIterator, <I as IntoIterator>::Item: IntoWeightedEdge<E, NodeId = N>,

Create a new `GraphMap` from an iterable of edges.

Node values are taken directly from the list. Edge weights `E` may either be specified in the list, or they are filled with default values.

Nodes are inserted automatically to match the edges.

``````use petgraph::graphmap::UnGraphMap;

// Create a new undirected GraphMap.
// Use a type hint to have `()` be the edge weight type.
let gr = UnGraphMap::<_, ()>::from_edges(&[
(0, 1), (0, 2), (0, 3),
(1, 2), (1, 3),
(2, 3),
]);``````
source

pub fn node_count(&self) -> usize

Return the number of nodes in the graph.

source

pub fn edge_count(&self) -> usize

Return the number of edges in the graph.

source

pub fn clear(&mut self)

Remove all nodes and edges

source

pub fn add_node(&mut self, n: N) -> N

Add node `n` to the graph.

source

pub fn remove_node(&mut self, n: N) -> bool

Return `true` if node `n` was removed.

Computes in O(V) time, due to the removal of edges with other nodes.

source

pub fn contains_node(&self, n: N) -> bool

Return `true` if the node is contained in the graph.

source

pub fn add_edge(&mut self, a: N, b: N, weight: E) -> Option<E>

Add an edge connecting `a` and `b` to the graph, with associated data `weight`. For a directed graph, the edge is directed from `a` to `b`.

Inserts nodes `a` and/or `b` if they aren’t already part of the graph.

Return `None` if the edge did not previously exist, otherwise, the associated data is updated and the old value is returned as `Some(old_weight)`.

``````// Create a GraphMap with directed edges, and add one edge to it
use petgraph::graphmap::DiGraphMap;

let mut g = DiGraphMap::new();
assert_eq!(g.node_count(), 2);
assert_eq!(g.edge_count(), 1);
assert!(g.contains_edge("x", "y"));
assert!(!g.contains_edge("y", "x"));``````
source

pub fn remove_edge(&mut self, a: N, b: N) -> Option<E>

Remove edge from `a` to `b` from the graph and return the edge weight.

Return `None` if the edge didn’t exist.

``````// Create a GraphMap with undirected edges, and add and remove an edge.
use petgraph::graphmap::UnGraphMap;

let mut g = UnGraphMap::new();

let edge_data = g.remove_edge("y", "x");
assert_eq!(edge_data, Some(-1));
assert_eq!(g.edge_count(), 0);``````
source

pub fn contains_edge(&self, a: N, b: N) -> bool

Return `true` if the edge connecting `a` with `b` is contained in the graph.

source

pub fn nodes(&self) -> Nodes<'_, N> ⓘ

Return an iterator over the nodes of the graph.

Iterator element type is `N`.

source

pub fn neighbors(&self, a: N) -> Neighbors<'_, N, Ty> ⓘ

Return an iterator of all nodes with an edge starting from `a`.

• `Directed`: Outgoing edges from `a`.
• `Undirected`: All edges from or to `a`.

Produces an empty iterator if the node doesn’t exist.
Iterator element type is `N`.

source

pub fn neighbors_directed( &self, a: N, dir: Direction ) -> NeighborsDirected<'_, N, Ty> ⓘ

Return an iterator of all neighbors that have an edge between them and `a`, in the specified direction. If the graph’s edges are undirected, this is equivalent to .neighbors(a).

• `Directed`, `Outgoing`: All edges from `a`.
• `Directed`, `Incoming`: All edges to `a`.
• `Undirected`: All edges from or to `a`.

Produces an empty iterator if the node doesn’t exist.
Iterator element type is `N`.

source

pub fn edges(&self, a: N) -> Edges<'_, N, E, Ty> ⓘ

Return an iterator of target nodes with an edge starting from `a`, paired with their respective edge weights.

• `Directed`: Outgoing edges from `a`.
• `Undirected`: All edges from or to `a`.

Produces an empty iterator if the node doesn’t exist.
Iterator element type is `(N, N, &E)`.

source

pub fn edges_directed( &self, a: N, dir: Direction ) -> EdgesDirected<'_, N, E, Ty> ⓘ

Return an iterator of target nodes with an edge starting from `a`, paired with their respective edge weights.

• `Directed`, `Outgoing`: All edges from `a`.
• `Directed`, `Incoming`: All edges to `a`.
• `Undirected`, `Outgoing`: All edges connected to `a`, with `a` being the source of each edge.
• `Undirected`, `Incoming`: All edges connected to `a`, with `a` being the target of each edge.

Produces an empty iterator if the node doesn’t exist.
Iterator element type is `(N, N, &E)`.

source

pub fn edge_weight(&self, a: N, b: N) -> Option<&E>

Return a reference to the edge weight connecting `a` with `b`, or `None` if the edge does not exist in the graph.

source

pub fn edge_weight_mut(&mut self, a: N, b: N) -> Option<&mut E>

Return a mutable reference to the edge weight connecting `a` with `b`, or `None` if the edge does not exist in the graph.

source

pub fn all_edges(&self) -> AllEdges<'_, N, E, Ty> ⓘ

Return an iterator over all edges of the graph with their weight in arbitrary order.

Iterator element type is `(N, N, &E)`

source

pub fn all_edges_mut(&mut self) -> AllEdgesMut<'_, N, E, Ty> ⓘ

Return an iterator over all edges of the graph in arbitrary order, with a mutable reference to their weight.

Iterator element type is `(N, N, &mut E)`

source

pub fn into_graph<Ix>(self) -> Graph<N, E, Ty, Ix>where Ix: IndexType,

Return a `Graph` that corresponds to this `GraphMap`.

1. Note that node and edge indices in the `Graph` have nothing in common with the `GraphMap`s node weights `N`. The node weights `N` are used as node weights in the resulting `Graph`, too.
2. Note that the index type is user-chosen.

Computes in O(|V| + |E|) time (average).

Panics if the number of nodes or edges does not fit with the resulting graph’s index type.

source

pub fn from_graph<Ix>(graph: Graph<N, E, Ty, Ix>) -> GraphMap<N, E, Ty>where Ix: IndexType, E: Clone,

Creates a `GraphMap` that corresponds to the given `Graph`.

Warning: Nodes with the same weight are merged and only the last parallel edge is kept. Node and edge indices of the `Graph` are lost. Only use this function if the node weights are distinct and there are no parallel edges.

Computes in O(|V| + |E|) time (average).

Trait Implementations§

source§

impl<N, E, Ty> Build for GraphMap<N, E, Ty>where Ty: EdgeType, N: NodeTrait,

source§

source§

fn add_edge( &mut self, a: <GraphMap<N, E, Ty> as GraphBase>::NodeId, b: <GraphMap<N, E, Ty> as GraphBase>::NodeId, weight: <GraphMap<N, E, Ty> as Data>::EdgeWeight ) -> Option<<GraphMap<N, E, Ty> as GraphBase>::EdgeId>

Add a new edge. If parallel edges (duplicate) are not allowed and the edge already exists, return `None`.
source§

fn update_edge( &mut self, a: <GraphMap<N, E, Ty> as GraphBase>::NodeId, b: <GraphMap<N, E, Ty> as GraphBase>::NodeId, weight: <GraphMap<N, E, Ty> as Data>::EdgeWeight ) -> <GraphMap<N, E, Ty> as GraphBase>::EdgeId

Add or update the edge from `a` to `b`. Return the id of the affected edge.
source§

impl<N, E, Ty> Clone for GraphMap<N, E, Ty>where N: Clone, E: Clone, Ty: Clone,

source§

fn clone(&self) -> GraphMap<N, E, Ty>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more
source§

source§

source§

§

§

source§

impl<N, E, Ty> Debug for GraphMap<N, E, Ty>where N: Eq + Hash + Debug, E: Debug, Ty: EdgeType,

source§

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

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

impl<N, E, Ty> Default for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

Create a new empty `GraphMap`.

source§

fn default() -> GraphMap<N, E, Ty>

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

impl<N, E, Ty> EdgeCount for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

source§

fn edge_count(&self) -> usize

Return the number of edges in the graph.
source§

impl<N, E, Ty> EdgeIndexable for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

source§

fn edge_bound(&self) -> usize

Return an upper bound of the edge indices in the graph (suitable for the size of a bitmap).
source§

fn to_index(&self, ix: <GraphMap<N, E, Ty> as GraphBase>::EdgeId) -> usize

Convert `a` to an integer index.
source§

fn from_index(&self, ix: usize) -> <GraphMap<N, E, Ty> as GraphBase>::EdgeId

Convert `i` to an edge index. `i` must be a valid value in the graph.
source§

impl<N, E, Ty, Item> Extend<Item> for GraphMap<N, E, Ty>where Item: IntoWeightedEdge<E, NodeId = N>, N: NodeTrait, Ty: EdgeType,

Extend the graph from an iterable of edges.

Nodes are inserted automatically to match the edges.

source§

fn extend<I>(&mut self, iterable: I)where I: IntoIterator<Item = Item>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (`extend_one`)
Extends a collection with exactly one element.
source§

🔬This is a nightly-only experimental API. (`extend_one`)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

source§

source§

impl<N, E, Ty, Item> FromIterator<Item> for GraphMap<N, E, Ty>where Item: IntoWeightedEdge<E, NodeId = N>, N: NodeTrait, Ty: EdgeType,

Create a new `GraphMap` from an iterable of edges.

source§

fn from_iter<I>(iterable: I) -> GraphMap<N, E, Ty>where I: IntoIterator<Item = Item>,

Creates a value from an iterator. Read more
source§

impl<N, E, Ty> GetAdjacencyMatrix for GraphMap<N, E, Ty>where N: Copy + Ord + Hash, Ty: EdgeType,

The `GraphMap` keeps an adjacency matrix internally.

§

source§

source§

fn is_adjacent(&self, _: &(), a: N, b: N) -> bool

Return true if there is an edge from `a` to `b`, false otherwise. Read more
source§

§

node identifier
§

edge identifier
source§

impl<N, E, Ty> GraphProp for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

§

type EdgeType = Ty

The kind of edges in the graph.
source§

source§

impl<N, E, Ty> Index<(N, N)> for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

Index `GraphMap` by node pairs to access edge weights.

§

type Output = E

The returned type after indexing.
source§

fn index(&self, index: (N, N)) -> &E

Performs the indexing (`container[index]`) operation. Read more
source§

impl<N, E, Ty> IndexMut<(N, N)> for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

Index `GraphMap` by node pairs to access edge weights.

source§

fn index_mut(&mut self, index: (N, N)) -> &mut E

Performs the mutable indexing (`container[index]`) operation. Read more
source§

source§

source§

impl<N, E, Ty> NodeIndexable for GraphMap<N, E, Ty>where N: NodeTrait, Ty: EdgeType,

source§

fn node_bound(&self) -> usize

Return an upper bound of the node indices in the graph (suitable for the size of a bitmap).
source§

fn to_index(&self, ix: <GraphMap<N, E, Ty> as GraphBase>::NodeId) -> usize

Convert `a` to an integer index.
source§

fn from_index(&self, ix: usize) -> <GraphMap<N, E, Ty> as GraphBase>::NodeId

Convert `i` to a node index. `i` must be a valid value in the graph.
source§

impl<N, E, Ty> Visitable for GraphMap<N, E, Ty>where N: Copy + Ord + Hash, Ty: EdgeType,

§

type Map = HashSet<N, RandomState>

The associated map type
source§

fn visit_map(&self) -> HashSet<N, RandomState>

Create a new visitor map
source§

fn reset_map(&self, map: &mut <GraphMap<N, E, Ty> as Visitable>::Map)

Reset the visitor map (and resize to new size of graph if needed)
source§