summaryrefslogtreecommitdiff
path: root/src/03/graph.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-09-27 13:11:12 -0600
committermo khan <mo.khan@gmail.com>2020-09-27 13:11:12 -0600
commitfc3968bcecc579c331ad01645def3f8e379984c4 (patch)
tree6e1b701c0b2458d5a6b1a49c2381b5e988353da1 /src/03/graph.c
parent1fdac316bde6e192a6ebf51148af0ee66a6ae831 (diff)
docs: document each function
Diffstat (limited to 'src/03/graph.c')
-rw-r--r--src/03/graph.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/03/graph.c b/src/03/graph.c
index 2286101..808043b 100644
--- a/src/03/graph.c
+++ b/src/03/graph.c
@@ -2,12 +2,23 @@
#include <stdio.h>
#include <stdlib.h>
+/**
+ * Creates a new Vertex for use in a Graph.
+ *
+ * @param label The label to attach to the node.
+ * @return Returns a new vertex
+ */
Vertex *vertex_initialize(char label) {
Vertex *item = malloc(sizeof(Vertex));
item->label = label;
return item;
};
+/**
+ * Initializes a new Graph
+ *
+ * @return Returns a new instance of a Graph.
+ */
Graph *graph_initialize(void) {
Graph *item = malloc(sizeof(Graph));
for (int i = 0; i < 128; ++i)
@@ -15,16 +26,42 @@ Graph *graph_initialize(void) {
return item;
}
+/**
+ * Inserts a new vertex into a graph with the provided label.
+ *
+ * @param graph The graph to insert a new vertex into
+ * @param label The label to apply to the new vertex.
+ * @return Returns the new vertex
+ */
Vertex *graph_add_vertex(Graph *graph, char label) {
Vertex *item = vertex_initialize(label);
graph->vertices[(int)label] = item;
return item;
}
+/**
+ * Updates a adjacency matrix to indicate that an edge exists
+ * between two vertexes.
+ *
+ * @param graph The graph to modify.
+ * @param a The vertex that points to vertex b.
+ * @param b The vertex that vertex a points to.
+ */
void graph_add_edge(Graph *graph, Vertex *a, Vertex *b) {
graph->edges[a->label][b->label] = true;
}
+/**
+ * Returns true or false to specify if vertex `a`
+ * in a graph is connected to vertex `b` in the same
+ * graph.
+ *
+ * @param graph The graph to investigate
+ * @param a The starting vertext to check
+ * @param b The vertex that vertex a might be pointing at.
+ * @return Returns true if an edge exists between the two vertexes otherwise
+ * false.
+ */
bool graph_has_edge(Graph *graph, Vertex *a, Vertex *b) {
return graph->edges[a->label][b->label];
}