Initial release #1

Merged
warrence merged 102 commits from dev into main 2026-06-30 10:26:52 +02:00
2 changed files with 23 additions and 23 deletions
Showing only changes of commit ab830ed221 - Show all commits
+18 -18
View File
@@ -22,7 +22,7 @@ struct IncidenceEntry {
neighbor: Vertex,
}
struct VertexNeighborIterator<'a> {
graph: &'a Graph,
graph: &'a AppendGraph,
incidence: Option<Incidence>,
}
@@ -42,15 +42,15 @@ impl<'a> Iterator for VertexNeighborIterator<'a> {
// TODO: Add function to delete vertices.
// TODO: Add function to delete edges.
// TODO: Add iterator of edges.
pub struct Graph {
pub struct AppendGraph {
// TODO: Index 'incidence_headers' by a 'Vertex' instead of 'Vertex.0'?
vertices: Vec<VertexIncidenceHeader>,
incidences: Vec<IncidenceEntry>,
}
impl Graph {
pub fn new() -> Graph {
Graph {
impl AppendGraph {
pub fn new() -> Self {
Self {
vertices: vec![],
incidences: vec![],
}
@@ -66,7 +66,7 @@ impl Graph {
}
}
impl GraphTopology for Graph {
impl GraphTopology for AppendGraph {
type Vertex = Vertex;
type Edge = Incidence;
@@ -119,14 +119,14 @@ mod tests {
#[test]
fn add_vertex() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v = graph.add_vertex();
assert_ne!(graph.add_vertex(), v, "unexpected duplicate vertex");
}
#[test]
fn vertex_count_empty() {
let graph = Graph::new();
let graph = AppendGraph::new();
assert_eq!(graph.vertex_count(), 0, "unexpected vertex count");
}
@@ -138,7 +138,7 @@ mod tests {
#[test]
fn edge_count_empty() {
let graph = Graph::new();
let graph = AppendGraph::new();
assert_eq!(graph.edge_count(), 0, "unexpected edge count");
}
@@ -150,7 +150,7 @@ mod tests {
#[test]
fn degree_zero() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v = graph.add_vertex();
assert_eq!(graph.degree(v), 0, "unexpected non-zero degree");
}
@@ -171,7 +171,7 @@ mod tests {
#[test]
fn are_adjacent_vertex_self() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v = graph.add_vertex();
assert_eq!(
graph.are_adjacent(v, v),
@@ -182,7 +182,7 @@ mod tests {
#[test]
fn are_adjacent_single_edge() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v1 = graph.add_vertex();
let v2 = graph.add_vertex();
assert!(!graph.are_adjacent(v1, v2), "should not be adjacent");
@@ -239,7 +239,7 @@ mod tests {
#[test]
fn vertices_empty() {
let graph = Graph::new();
let graph = AppendGraph::new();
assert_eq!(
graph.vertices().count(),
0,
@@ -264,7 +264,7 @@ mod tests {
#[test]
fn neighbors_empty() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let vertex = graph.add_vertex();
assert_eq!(
graph.neighbors(vertex).count(),
@@ -297,7 +297,7 @@ mod tests {
#[test]
fn loop_edge() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v = graph.add_vertex();
graph.add_edge(v, v);
assert_eq!(graph.vertex_count(), 1, "unexpected vertex count");
@@ -325,7 +325,7 @@ mod tests {
#[test]
fn multiple_edges() {
let mult = 3;
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let vertices = [graph.add_vertex(), graph.add_vertex()];
for _ in 0..mult {
graph.add_edge(vertices[0], vertices[1]);
@@ -364,8 +364,8 @@ mod tests {
}
}
fn make_test_graph() -> (Graph, [Vertex; 10]) {
let mut graph = Graph::new();
fn make_test_graph() -> (AppendGraph, [Vertex; 10]) {
let mut graph = AppendGraph::new();
let vertices: [Vertex; 10] = core::array::from_fn(|_| graph.add_vertex());
graph.add_edge(vertices[0], vertices[1]);
graph.add_edge(vertices[1], vertices[2]);
+5 -5
View File
@@ -1,10 +1,10 @@
use grapherity::algorithms;
use grapherity::models::Graph;
use grapherity::models::AppendGraph;
use grapherity::traits::GraphTopology;
#[test]
fn dijkstra_single_vertex() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v1 = graph.add_vertex();
let (distances, predecessors) = algorithms::dijkstra(&graph, v1);
assert_eq!(
@@ -30,7 +30,7 @@ fn dijkstra_single_vertex() {
#[test]
fn dijkstra_disconnected() {
let mut graph = Graph::new();
let mut graph = AppendGraph::new();
let v1 = graph.add_vertex();
graph.add_vertex();
let (distances, predecessors) = algorithms::dijkstra(&graph, v1);
@@ -107,8 +107,8 @@ fn dijkstra() {
}
}
fn make_test_graph() -> (Graph, [<Graph as GraphTopology>::Vertex; 10]) {
let mut graph = Graph::new();
fn make_test_graph() -> (AppendGraph, [<AppendGraph as GraphTopology>::Vertex; 10]) {
let mut graph = AppendGraph::new();
let vertices = core::array::from_fn::<_, 10, _>(|_| graph.add_vertex());
graph.add_edge(vertices[0], vertices[1]);
graph.add_edge(vertices[1], vertices[2]);