mod edge;
mod graphs;
mod mst;
mod shortestpath;
use std::{
cmp::Ordering,
ops::{Deref, DerefMut},
};
pub use edge::{WeightedDirectedEdge, WeightedEdge};
pub use graphs::{WeightedDiGraph, WeightedGraph};
pub use mst::MST;
pub use shortestpath::{
AStarResult, BellmanFordResult, DijkstraResult, ShortestPath,
};
pub trait EdgeWeightedGraph<T> {
#[must_use]
fn vertices(&self) -> usize;
#[must_use]
fn edges(&self) -> usize;
#[must_use]
fn degree(&self, v: usize) -> usize;
#[must_use]
fn adjacent(&self, v: usize) -> impl Iterator<Item = T>;
fn add_edge(&mut self, edge: T);
fn all_edges(&self) -> impl Iterator<Item = T>;
#[must_use]
fn to_dot(&self) -> String;
}
#[derive(Debug, Clone, Copy)]
struct MinFloatTotalOrder(f64);
impl PartialEq for MinFloatTotalOrder {
fn eq(&self, other: &Self) -> bool {
self.0.total_cmp(&other.0).is_eq()
}
}
impl Eq for MinFloatTotalOrder {}
impl PartialOrd for MinFloatTotalOrder {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for MinFloatTotalOrder {
fn cmp(&self, other: &Self) -> Ordering {
self.0.total_cmp(&other.0).reverse() }
}
impl Deref for MinFloatTotalOrder {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for MinFloatTotalOrder {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}