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,
The adjacency matrix for List is a bitmap that’s computed by
.adjacency_matrix().
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().
Source§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
impl<E, Ix> NodeCompactIndexable for List<E, Ix>where
Ix: IndexType,
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,
Auto Trait Implementations§
impl<E, Ix> Freeze for List<E, Ix>
impl<E, Ix> RefUnwindSafe for List<E, Ix>where
Ix: RefUnwindSafe,
E: 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> UnsafeUnpin for List<E, Ix>
impl<E, Ix> UnwindSafe for List<E, Ix>where
Ix: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);