Social Network 1.0.0
The second major course output (MCO2) for CCDSALG.
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1/*
2 * Social Network uses graphs to represent relationships between users.
3 * Copyright (C) 2025 Raphael Panaligan Jek Degullado
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifndef SOCIAL_NETWORK_GRAPH_H_
32#define SOCIAL_NETWORK_GRAPH_H_
33
34#include <stdbool.h>
35#include <stddef.h>
36
38#define MAX_VERTEX_LABEL_LENGTH 8
39
41#define MAX_GRAPH_VERTEX_COUNT 20
42
45
62
69void initialize_graph(Graph *const graph, const size_t vertex_count);
70
76void clone_graph(const Graph *const graph, Graph *const new_graph);
77
85size_t get_vertex_index(const Graph *const graph, const Vertex vertex);
86
93bool has_vertex(const Graph *const graph, const Vertex vertex);
94
106void add_adjacency(Graph *const graph, const Vertex key_vertex, const Vertex adjacent_vertex);
107
114
121bool has_adjacency(const Vertex adjacencies[MAX_GRAPH_VERTEX_COUNT], const Vertex adjacent_vertex);
122
127void sort_adjacencies(Graph *const graph);
128
136
143void get_edges(const Graph *const graph, GraphEdge edges[], size_t *const edge_count);
144
153bool has_edge(const GraphEdge edges[], const size_t edge_count, const Vertex source_vertex,
154 const Vertex destination_vertex);
155
156#endif // SOCIAL_NETWORK_GRAPH_H_
157
158#ifdef __cplusplus
159}
160#endif
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.
void clone_graph(const Graph *const graph, Graph *const new_graph)
Clones the contents of a graph into another graph.
bool has_vertex(const Graph *const graph, const Vertex vertex)
Checks if a graph contains a vertex.
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.
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 sort_adjacencies(Graph *const graph)
Sorts the adjacency arrays by their keys alphabetically, and sorts their adjacent vertices alphabetic...
#define MAX_GRAPH_VERTEX_COUNT
The maximum number of vertices a graph can contain.
Definition graph.h:41
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.
#define MAX_VERTEX_LABEL_LENGTH
The maximum number of characters a vertex’ label can have.
Definition graph.h:38
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.
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_adjacency(const Vertex adjacencies[MAX_GRAPH_VERTEX_COUNT], const Vertex adjacent_vertex)
Checks if a key led array of adjacencies contains an adjacent vertex.
char Vertex[MAX_VERTEX_LABEL_LENGTH+1]
A string-labeled vertex in a graph.
Definition graph.h:44
A(n) (un)directed connection between two vertices in a graph.
Definition graph.h:130
Vertex destination
The second or destination vertex of the connection.
Definition graph.h:134
Vertex source
The first or source vertex of the connection.
Definition graph.h:132
A collection implementing the adjacency list data graph structure using arrays.
Definition graph.h:50
Vertex adjacencies_by_vertex[MAX_GRAPH_VERTEX_COUNT][MAX_GRAPH_VERTEX_COUNT]
The vertices adjacent to the vertices contained by the graph.
Definition graph.h:58
size_t vertex_count
The number of vertices the graph contains.
Definition graph.h:52
size_t adjacencies_length
The number of vertex adjacency arrays the graph contains.
Definition graph.h:60