pub struct Graph { /* private fields */ }Expand description
Qo’shnilik ro’yxati (adjacency list) asosidagi graf.
Tugunlar 0..n butun sonlar bilan raqamlanadi. Nomlar bilan ishlash kerak bo’lsa,
HashMap<String, usize> orqali nomni indeksga bog’lang.
§Misol
use rust_algorithms::graph::Graph;
// yo'naltirilmagan, og'irlikli graf
let mut g = Graph::new_undirected(4);
g.add_edge(0, 1, 5);
g.add_edge(0, 2, 2);
g.add_edge(2, 3, 1);
assert_eq!(g.node_count(), 4);
assert_eq!(g.edge_count(), 3);
assert_eq!(g.degree(0), 2);
assert!(g.has_edge(1, 0)); // yo'naltirilmagan — ikki tomonlamaImplementations§
Source§impl Graph
impl Graph
Sourcepub fn new_undirected(n: usize) -> Self
pub fn new_undirected(n: usize) -> Self
n tugunli yo’naltirilmagan graf (qirra ikki tomonga ham ishlaydi).
Sourcepub fn new_directed(n: usize) -> Self
pub fn new_directed(n: usize) -> Self
n tugunli yo’naltirilgan graf (qirra faqat bir tomonga).
Sourcepub fn add_unweighted_edge(&mut self, from: usize, to: usize)
pub fn add_unweighted_edge(&mut self, from: usize, to: usize)
Og’irliksiz qirra (og’irligi 1).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Tugunlar soni.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Qirralar soni (yo’naltirilmaganda juftlik bir marta sanaladi).
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Graf yo’naltirilganmi?
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
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