Add Graph::new()
This commit is contained in:
+1
-6
@@ -6,12 +6,7 @@ use models::Vertex;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// TODO: Move this graph example into one or more tests.
|
// TODO: Move this graph example into one or more tests.
|
||||||
let mut graph = Graph {
|
let mut graph = Graph::new();
|
||||||
// TODO: The initializations should happen in an initializer or constructor
|
|
||||||
incidence_headers: vec![],
|
|
||||||
next_incidences: vec![],
|
|
||||||
incidence_vertices: vec![],
|
|
||||||
};
|
|
||||||
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());
|
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());
|
||||||
graph.add_edge(vertices[0], vertices[1]);
|
graph.add_edge(vertices[0], vertices[1]);
|
||||||
graph.add_edge(vertices[1], vertices[2]);
|
graph.add_edge(vertices[1], vertices[2]);
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ pub struct Graph {
|
|||||||
// TODO: Add iterator of edges.
|
// TODO: Add iterator of edges.
|
||||||
// TODO: Add iterator of vertex neighbors, see 'fn add_adjacent()'.
|
// TODO: Add iterator of vertex neighbors, see 'fn add_adjacent()'.
|
||||||
impl Graph {
|
impl Graph {
|
||||||
|
pub fn new() -> Graph {
|
||||||
|
Graph {
|
||||||
|
incidence_headers: vec![],
|
||||||
|
next_incidences: vec![],
|
||||||
|
incidence_vertices: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn vertex_count(&self) -> usize {
|
pub fn vertex_count(&self) -> usize {
|
||||||
self.incidence_headers.len()
|
self.incidence_headers.len()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user