The helper functions that are used for handling and interacting with graphs and their vertices.
More...
#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
#define | MAX_VERTEX_LABEL_LENGTH 8 |
| The maximum number of characters a vertex’ label can have.
|
#define | MAX_GRAPH_VERTEX_COUNT 20 |
| The maximum number of vertices a graph can contain.
|
|
void | initialize_graph (Graph *const graph, const size_t vertex_count) |
| Initializes a graph’s vertex adjacency arrays to their default values and sets its vertex count.
|
void | clone_graph (const Graph *const graph, Graph *const new_graph) |
| Clones the contents of a graph into another graph.
|
size_t | get_vertex_index (const Graph *const graph, const Vertex vertex) |
| Gets the index of the adjacency array of a vertex from a graph.
|
bool | has_vertex (const Graph *const graph, const Vertex vertex) |
| Checks if a graph contains a vertex.
|
void | add_adjacency (Graph *const graph, const Vertex key_vertex, const Vertex adjacent_vertex) |
| Adds an adjacency between a pair of vertices to a graph.
|
size_t | get_adjacency_count (const Vertex adjacencies[MAX_GRAPH_VERTEX_COUNT]) |
| Gets the total number of adjacencies in a key led array of adjacencies.
|
bool | has_adjacency (const Vertex adjacencies[MAX_GRAPH_VERTEX_COUNT], const Vertex adjacent_vertex) |
| Checks if a key led array of adjacencies contains an adjacent vertex.
|
void | sort_adjacencies (Graph *const graph) |
| Sorts the adjacency arrays by their keys alphabetically, and sorts their adjacent vertices alphabetically.
|
void | get_edges (const Graph *const graph, GraphEdge edges[], size_t *const edge_count) |
| Gets the edges formed by connections between vertices contained in a graph.
|
bool | has_edge (const GraphEdge edges[], const size_t edge_count, const Vertex source_vertex, const Vertex destination_vertex) |
| Checks if a pair of vertices already has a corresponding edge in an array of edges.
|
The helper functions that are used for handling and interacting with graphs and their vertices.
- Author
- Raphael Panaligan
-
Jek Degullado
- Copyright
- GNU AGPLv3
◆ add_adjacency()
void add_adjacency |
( |
Graph *const | graph, |
|
|
const Vertex | key_vertex, |
|
|
const Vertex | adjacent_vertex ) |
Adds an adjacency between a pair of vertices to a graph.
This adds the adjacent vertex to the array of the key vertex. If the array doesn’t exist, this creates the array before adding the adjacent vertex. If an adjacent vertex is not supplied, then this will still create the array for the key vertex if it doesn’t exist.
- Parameters
-
[in,out] | graph | The graph to add to. |
[in] | key_vertex | The key vertex of the adjacency. |
[in] | adjacent_vertex | The vertex adjacent to the key vertex. |
- Precondition
- The graph’s vertex count has been checked against and the number of vertices will not exceed MAX_GRAPH_VERTEX_COUNT.
◆ clone_graph()
void clone_graph |
( |
const Graph *const | graph, |
|
|
Graph *const | new_graph ) |
Clones the contents of a graph into another graph.
- Parameters
-
[in] | graph | The graph to clone from. |
[out] | new_graph | The graph to clone to. |
◆ get_adjacency_count()
size_t get_adjacency_count |
( |
const Vertex | adjacencies[MAX_GRAPH_VERTEX_COUNT] | ) |
|
Gets the total number of adjacencies in a key led array of adjacencies.
- Parameters
-
[in] | adjacencies | The key led adjacencies to get from. |
- Returns
- The total number of adjacencies in the key led array of adjacencies.
◆ get_edges()
void get_edges |
( |
const Graph *const | graph, |
|
|
GraphEdge | edges[], |
|
|
size_t *const | edge_count ) |
Gets the edges formed by connections between vertices contained in a graph.
- Parameters
-
[in] | graph | The graph to get from. |
[out] | edges | The edges of the graph. |
[out] | edge_count | The number of edges the graph has. |
◆ get_vertex_index()
size_t get_vertex_index |
( |
const Graph *const | graph, |
|
|
const Vertex | vertex ) |
Gets the index of the adjacency array of a vertex from a graph.
- Parameters
-
[in] | graph | The graph to get from. |
[in] | vertex | The vertex to get the index of. |
- Returns
- The index of the vertex’ adjacency array, or MAX_GRAPH_VERTEX_COUNT if the graph doesn’t contain the vertex.
◆ has_adjacency()
bool has_adjacency |
( |
const Vertex | adjacencies[MAX_GRAPH_VERTEX_COUNT], |
|
|
const Vertex | adjacent_vertex ) |
Checks if a key led array of adjacencies contains an adjacent vertex.
- Parameters
-
[in] | adjacencies | The key led adjacencies to check against. |
[in] | adjacent_vertex | The adjacent vertex to check for. |
- Returns
- Whether the key led array of adjacencies contains the adjacent vertex.
◆ has_edge()
bool has_edge |
( |
const GraphEdge | edges[], |
|
|
const size_t | edge_count, |
|
|
const Vertex | source_vertex, |
|
|
const Vertex | destination_vertex ) |
Checks if a pair of vertices already has a corresponding edge in an array of edges.
- Parameters
-
[in] | edges | The edges to check against. |
[in] | edge_count | The number of edges to check against. |
[in] | source_vertex | The first or source vertex to check for. |
[in] | destination_vertex | The second or destination vertex to check for. |
- Returns
- Whether the pair of vertices has a corresponding edge in the array of edges.
◆ has_vertex()
bool has_vertex |
( |
const Graph *const | graph, |
|
|
const Vertex | vertex ) |
Checks if a graph contains a vertex.
- Parameters
-
[in] | graph | The graph to check. |
[in] | vertex | The vertex to check for. |
- Returns
- Whether the graph contains the vertex.
◆ initialize_graph()
void initialize_graph |
( |
Graph *const | graph, |
|
|
const size_t | vertex_count ) |
Initializes a graph’s vertex adjacency arrays to their default values and sets its vertex count.
- Parameters
-
[in,out] | graph | The graph to initialize. |
| vertex_count | The number of vertices the graph should contain. |
- Precondition
- The vertex_count doesn’t exceed MAX_GRAPH_VERTEX_COUNT.
◆ sort_adjacencies()
void sort_adjacencies |
( |
Graph *const | graph | ) |
|
Sorts the adjacency arrays by their keys alphabetically, and sorts their adjacent vertices alphabetically.
- Parameters
-
[in,out] | graph | The graph to sort. |