pub struct List<E, Ix = u32>where
Ix: IndexType,{ /* private fields */ }
Expand description
An adjacency list with labeled edges.
Can be interpreted as a directed graph with unweighted nodes.
This is the most simple adjacency list you can imagine. Graph
, in contrast,
maintains both the list of successors and predecessors for each node,
which is a different trade-off.
Allows parallel edges and self-loops.
This data structure is append-only (except for clear
), so indices
returned at some point for a given graph will stay valid with this same
graph until it is dropped or clear
is called.
Space consumption: O(|E|).
Implementations§
source§impl<E, Ix> List<E, Ix>where
Ix: IndexType,
impl<E, Ix> List<E, Ix>where
Ix: IndexType,
sourcepub fn with_capacity(nodes: usize) -> List<E, Ix>
pub fn with_capacity(nodes: usize) -> List<E, Ix>
Creates a new, empty adjacency list tailored for nodes
nodes.
sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges in the list
Computes in O(|V|) time.
sourcepub fn add_node(&mut self) -> Ix
pub fn add_node(&mut self) -> Ix
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
sourcepub fn add_node_with_capacity(&mut self, successors: usize) -> Ix
pub fn add_node_with_capacity(&mut self, successors: usize) -> Ix
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
sourcepub fn add_node_from_edges<I>(&mut self, edges: I) -> Ix
pub fn add_node_from_edges<I>(&mut self, edges: I) -> Ix
Adds a new node to the list by giving its list of successors and the corresponding weigths.
sourcepub fn add_edge(&mut self, a: Ix, b: Ix, weight: E) -> EdgeIndex<Ix>
pub fn add_edge(&mut self, a: Ix, b: Ix, weight: E) -> EdgeIndex<Ix>
Add an edge from a
to b
to the graph, with its associated
data weight
.
Return the index of the new edge.
Computes in O(1) time.
Panics if the source node does not exist.
Note: List
allows adding parallel (“duplicate”) edges. If you want
to avoid this, use .update_edge(a, b, weight)
instead.
sourcepub fn edge_endpoints(&self, e: EdgeIndex<Ix>) -> Option<(Ix, Ix)>
pub fn edge_endpoints(&self, e: EdgeIndex<Ix>) -> Option<(Ix, Ix)>
Accesses the source and target of edge e
Computes in O(1)
pub fn edge_indices_from(&self, a: Ix) -> OutgoingEdgeIndices<Ix> ⓘ
sourcepub fn contains_edge(&self, a: Ix, b: Ix) -> bool
pub fn contains_edge(&self, a: Ix, b: Ix) -> bool
Lookups whether there is an edge from a
to b
.
Computes in O(e’) time, where e’ is the number of successors of a
.
sourcepub fn find_edge(&self, a: Ix, b: Ix) -> Option<EdgeIndex<Ix>>
pub fn find_edge(&self, a: Ix, b: Ix) -> Option<EdgeIndex<Ix>>
Lookups whether there is an edge from a
to b
.
Computes in O(e’) time, where e’ is the number of successors of a
.
sourcepub fn node_indices(&self) -> NodeIndices<Ix> ⓘ
pub fn node_indices(&self) -> NodeIndices<Ix> ⓘ
Returns an iterator over all node indices of the graph.
Consuming the whole iterator take O(|V|).
sourcepub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix> ⓘ
pub fn edge_indices(&self) -> EdgeIndices<'_, E, Ix> ⓘ
Returns an iterator over all edge indices of the graph.
Consuming the whole iterator take O(|V| + |E|).
Trait Implementations§
source§impl<E, Ix> Build for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> Build for List<E, Ix>where
Ix: IndexType,
source§fn add_node(&mut self, _weight: ()) -> Ix
fn add_node(&mut self, _weight: ()) -> Ix
Adds a new node to the list. This allocates a new Vec
and then should
run in amortized O(1) time.
source§fn add_edge(&mut self, a: Ix, b: Ix, weight: E) -> Option<EdgeIndex<Ix>>
fn add_edge(&mut self, a: Ix, b: Ix, weight: E) -> Option<EdgeIndex<Ix>>
Add an edge from a
to b
to the graph, with its associated
data weight
.
Return the index of the new edge.
Computes in O(1) time.
Panics if the source node does not exist.
Note: List
allows adding parallel (“duplicate”) edges. If you want
to avoid this, use .update_edge(a, b, weight)
instead.
source§fn update_edge(&mut self, a: Ix, b: Ix, weight: E) -> EdgeIndex<Ix>
fn update_edge(&mut self, a: Ix, b: Ix, weight: E) -> EdgeIndex<Ix>
Updates or adds an edge from a
to b
to the graph, with its associated
data weight
.
Return the index of the new edge.
Computes in O(e’) time, where e’ is the number of successors of a
.
Panics if the source node does not exist.
source§impl<E, Ix> Data for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> Data for List<E, Ix>where
Ix: IndexType,
type NodeWeight = ()
type EdgeWeight = E
source§impl<E, Ix> DataMapMut for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> DataMapMut for List<E, Ix>where
Ix: IndexType,
source§impl<E, Ix> EdgeCount for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> EdgeCount for List<E, Ix>where
Ix: IndexType,
source§fn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Returns the number of edges in the list
Computes in O(|V|) time.
source§impl<E, Ix> GetAdjacencyMatrix for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> GetAdjacencyMatrix for List<E, Ix>where
Ix: IndexType,
The adjacency matrix for List is a bitmap that’s computed by
.adjacency_matrix()
.
§type AdjMatrix = FixedBitSet
type AdjMatrix = FixedBitSet
source§fn adjacency_matrix(&self) -> FixedBitSet
fn adjacency_matrix(&self) -> FixedBitSet
source§fn is_adjacent(&self, matrix: &FixedBitSet, a: Ix, b: Ix) -> bool
fn is_adjacent(&self, matrix: &FixedBitSet, a: Ix, b: Ix) -> bool
source§impl<'a, Ix, E> IntoEdgeReferences for &'a List<E, Ix>where
Ix: IndexType,
impl<'a, Ix, E> IntoEdgeReferences for &'a List<E, Ix>where
Ix: IndexType,
type EdgeRef = EdgeReference<'a, E, Ix>
type EdgeReferences = EdgeReferences<'a, E, Ix>
fn edge_references( self ) -> <&'a List<E, Ix> as IntoEdgeReferences>::EdgeReferences
source§impl<'a, E, Ix> IntoNeighbors for &'a List<E, Ix>where
Ix: IndexType,
impl<'a, E, Ix> IntoNeighbors for &'a List<E, Ix>where
Ix: IndexType,
source§fn neighbors(self, a: Ix) -> <&'a List<E, Ix> as IntoNeighbors>::Neighbors
fn neighbors(self, a: Ix) -> <&'a List<E, Ix> as IntoNeighbors>::Neighbors
Returns an iterator of all nodes with an edge starting from a
.
Panics if a
is out of bounds.
Use List::edge_indices_from
instead if you do not want to borrow the adjacency list while
iterating.
type Neighbors = Neighbors<'a, E, Ix>
source§impl<'a, E, Ix> IntoNodeIdentifiers for &'a List<E, Ix>where
Ix: IndexType,
impl<'a, E, Ix> IntoNodeIdentifiers for &'a List<E, Ix>where
Ix: IndexType,
type NodeIdentifiers = NodeIndices<Ix>
fn node_identifiers(self) -> NodeIndices<Ix> ⓘ
source§impl<'a, Ix, E> IntoNodeReferences for &'a List<E, Ix>where
Ix: IndexType,
impl<'a, Ix, E> IntoNodeReferences for &'a List<E, Ix>where
Ix: IndexType,
type NodeRef = Ix
type NodeReferences = NodeIndices<Ix>
fn node_references( self ) -> <&'a List<E, Ix> as IntoNodeReferences>::NodeReferences
source§impl<E, Ix> NodeCount for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> NodeCount for List<E, Ix>where
Ix: IndexType,
source§fn node_count(&self) -> usize
fn node_count(&self) -> usize
Returns the number of nodes in the list
Computes in O(1) time.
source§impl<E, Ix> NodeIndexable for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> NodeIndexable for List<E, Ix>where
Ix: IndexType,
impl<E, Ix> NodeCompactIndexable for List<E, Ix>where
Ix: IndexType,
Auto Trait Implementations§
impl<E, Ix> RefUnwindSafe for List<E, Ix>where
E: RefUnwindSafe,
Ix: RefUnwindSafe,
impl<E, Ix> Send for List<E, Ix>
impl<E, Ix> Sync for List<E, Ix>
impl<E, Ix> Unpin for List<E, Ix>
impl<E, Ix> UnwindSafe for List<E, Ix>where
E: UnwindSafe,
Ix: UnwindSafe,
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.