pub struct Edge<T, A>where
T: PartialOrd + Send,{
pub u: T,
pub v: T,
pub attributes: Option<A>,
pub weight: f64,
}Expand description
Represents a graph edge as (u, v).
Also allows attributes, as a HashMap, to be stored on an edge.
Fields§
§u: TThe name of the first node of the edge.
v: TThe name of the second node of the edge.
attributes: Option<A>Any attributes of the edge.
weight: f64The edge weight. For weighted Graph this should be a real number.
For an unweighted Graph this should be f64:NAN.
Implementations§
Source§impl<T, A> Edge<T, A>
impl<T, A> Edge<T, A>
Sourcepub fn ordered(self: &Edge<T, A>) -> Edge<T, A>
pub fn ordered(self: &Edge<T, A>) -> Edge<T, A>
Returns (v, u) if u > v.
use graphrs::Edge;
let edge1 = Edge::<&str, ()>::new("n2", "n1");
let edge2 = edge1.ordered();
assert_eq!(edge2.u, "n1");
assert_eq!(edge2.v, "n2");Sourcepub fn reversed(self: &Edge<T, A>) -> Edge<T, A>
pub fn reversed(self: &Edge<T, A>) -> Edge<T, A>
Reverses the edge. (u, v) -> (v, u)
use graphrs::Edge;
let edge1 = Edge::<&str, ()>::new("n2", "n1");
let edge2 = edge1.reversed();
assert_eq!(edge2.u, "n1");
assert_eq!(edge2.v, "n2");Sourcepub fn with_weight(u: T, v: T, weight: f64) -> Arc<Edge<T, A>>
pub fn with_weight(u: T, v: T, weight: f64) -> Arc<Edge<T, A>>
Creates a (u, v) Edge with a specified weight.
§Arguments
u: The name of the first node of the edge.v: The name of the second node of the edge.weight: The weight of the edge.
§Examples
use graphrs::Edge;
let edges = vec![
Edge::<&str, ()>::with_weight("n1", "n2", 1.0),
Edge::<&str, ()>::with_weight("n2", "n1", 2.0),
];Trait Implementations§
Source§impl<T: Eq + PartialOrd + Send + Sync, A> Ord for Edge<T, A>
impl<T: Eq + PartialOrd + Send + Sync, A> Ord for Edge<T, A>
Source§impl<T: Eq + PartialEq + PartialOrd + Send + Sync, A> PartialOrd for Edge<T, A>
impl<T: Eq + PartialEq + PartialOrd + Send + Sync, A> PartialOrd for Edge<T, A>
impl<T: Eq + PartialOrd + Send + Sync, A> Eq for Edge<T, A>
Auto Trait Implementations§
impl<T, A> Freeze for Edge<T, A>
impl<T, A> RefUnwindSafe for Edge<T, A>where
T: RefUnwindSafe,
A: RefUnwindSafe,
impl<T, A> Send for Edge<T, A>where
A: Send,
impl<T, A> Sync for Edge<T, A>
impl<T, A> Unpin for Edge<T, A>
impl<T, A> UnwindSafe for Edge<T, A>where
T: UnwindSafe,
A: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 more