Altered file names so I can work on a basic, working verison of this project. Additionaly, I added author, date, version #, and briefs at the head of all code files.
This commit is contained in:
28
.vscode/tasks.json
vendored
Normal file
28
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "cppbuild",
|
||||||
|
"label": "C/C++: g++.exe build active file",
|
||||||
|
"command": "C:\\ProgramData\\mingw64\\mingw64\\bin\\g++.exe",
|
||||||
|
"args": [
|
||||||
|
"-fdiagnostics-color=always",
|
||||||
|
"-g",
|
||||||
|
"${file}",
|
||||||
|
"-o",
|
||||||
|
"${fileDirname}\\${fileBasenameNoExtension}.exe"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"cwd": "${fileDirname}"
|
||||||
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"detail": "Task generated by Debugger."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
||||||
@@ -1,7 +1,15 @@
|
|||||||
#include "Graph.h"
|
/**
|
||||||
|
* @author: Lewis Price
|
||||||
|
* @date: 06-09-2026 (MM-DD-YYYY)
|
||||||
|
* @brief: This file contains the class definition for the Flat_Buffer_Graph, which is a graph data structure that uses flat buffers to store points and edges. The class provides methods for adding and deleting points and edges, as well as printing the graph for debugging purposes.
|
||||||
|
* @version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Flat_Buffer_Graph.h"
|
||||||
|
|
||||||
// Begin : Construction & Deconstruction
|
// Begin : Construction & Deconstruction
|
||||||
Graph::Graph(size_t max_points, size_t max_edges) noexcept
|
Flat_Buffer_Graph::Flat_Buffer_Graph(size_t max_points, size_t max_edges) noexcept
|
||||||
{
|
{
|
||||||
all_points = new(std::nothrow) Point[max_points] {};
|
all_points = new(std::nothrow) Point[max_points] {};
|
||||||
all_edges = new(std::nothrow) Edge[max_edges] {};
|
all_edges = new(std::nothrow) Edge[max_edges] {};
|
||||||
@@ -13,13 +21,13 @@ Graph::Graph(size_t max_points, size_t max_edges) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph::~Graph()
|
Flat_Buffer_Graph::~Flat_Buffer_Graph()
|
||||||
{
|
{
|
||||||
delete[] all_points;
|
delete[] all_points;
|
||||||
delete[] all_edges;
|
delete[] all_edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graph::Graph(Graph&& new_location) noexcept
|
Flat_Buffer_Graph::Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept
|
||||||
: all_points(std::exchange(new_location.all_points, nullptr)),
|
: all_points(std::exchange(new_location.all_points, nullptr)),
|
||||||
all_edges(std::exchange(new_location.all_edges, nullptr)),
|
all_edges(std::exchange(new_location.all_edges, nullptr)),
|
||||||
p_capacity(std::exchange(new_location.p_capacity, 0)),
|
p_capacity(std::exchange(new_location.p_capacity, 0)),
|
||||||
@@ -27,19 +35,34 @@ Graph::Graph(Graph&& new_location) noexcept
|
|||||||
// End : Construction & Deconstruction
|
// End : Construction & Deconstruction
|
||||||
|
|
||||||
// ----------------------- BEGIN : Printing -----------------------
|
// ----------------------- BEGIN : Printing -----------------------
|
||||||
|
void Flat_Buffer_Graph::print_graph() noexcept
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < p_capacity; ++i) {
|
||||||
|
Point& p = all_points[i];
|
||||||
|
if (p.e_count == -1) continue;
|
||||||
|
|
||||||
|
printf("Point %zu: %s (x:%.2f, y:%.2f, z:%.2f)\n", i, p.name.c_str(), p.x, p.y, p.z);
|
||||||
|
|
||||||
|
int current_edge_idx = p.first_edge;
|
||||||
|
while (current_edge_idx != -1) {
|
||||||
|
Edge& e = all_edges[current_edge_idx];
|
||||||
|
printf(" -> Edge to Point %d [Weight: %.2f]\n", e.end_point, e.e_weight);
|
||||||
|
current_edge_idx = e.next_edge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------- END : Printing -----------------------
|
// ----------------------- END : Printing -----------------------
|
||||||
|
|
||||||
|
|
||||||
// ----------------------- BEGIN : Getters -----------------------
|
// ----------------------- BEGIN : Getters -----------------------
|
||||||
|
|
||||||
Point* Graph::get_points() noexcept
|
Point* Flat_Buffer_Graph::get_points() noexcept
|
||||||
{
|
{
|
||||||
return all_points;
|
return all_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edge* Graph::get_p_edges(int p_index) noexcept
|
Edge* Flat_Buffer_Graph::get_p_edges(int p_index) noexcept
|
||||||
{
|
{
|
||||||
if(p_index < 0 || (size_t)p_index >= p_capacity) return nullptr;
|
if(p_index < 0 || (size_t)p_index >= p_capacity) return nullptr;
|
||||||
|
|
||||||
@@ -53,7 +76,7 @@ Edge* Graph::get_p_edges(int p_index) noexcept
|
|||||||
|
|
||||||
// ----------------------- BEGIN : Mutators -----------------------
|
// ----------------------- BEGIN : Mutators -----------------------
|
||||||
|
|
||||||
Point* Graph::add_point(std::string name, float x, float y, float z) noexcept {
|
Point* Flat_Buffer_Graph::add_point(std::string name, float x, float y, float z) noexcept {
|
||||||
int target = -1;
|
int target = -1;
|
||||||
|
|
||||||
if (next_free_point != -1) {
|
if (next_free_point != -1) {
|
||||||
@@ -77,7 +100,7 @@ Point* Graph::add_point(std::string name, float x, float y, float z) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Graph::delete_point(int p_index) {
|
bool Flat_Buffer_Graph::delete_point(int p_index) {
|
||||||
if (p_index < 0 || (size_t)p_index >= p_capacity) return false;
|
if (p_index < 0 || (size_t)p_index >= p_capacity) return false;
|
||||||
|
|
||||||
// 1. IMPORTANT: Clean up all edges belonging to this point first!
|
// 1. IMPORTANT: Clean up all edges belonging to this point first!
|
||||||
@@ -96,7 +119,7 @@ bool Graph::delete_point(int p_index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Edge* Graph::add_edge(int e_start, int e_end, float weight) noexcept {
|
Edge* Flat_Buffer_Graph::add_edge(int e_start, int e_end, float weight) noexcept {
|
||||||
// Validation: Ensure indices are within bounds
|
// Validation: Ensure indices are within bounds
|
||||||
if (e_start < 0 || (size_t)e_start >= p_capacity ||
|
if (e_start < 0 || (size_t)e_start >= p_capacity ||
|
||||||
e_end < 0 || (size_t)e_end >= p_capacity) return nullptr;
|
e_end < 0 || (size_t)e_end >= p_capacity) return nullptr;
|
||||||
@@ -125,7 +148,7 @@ Edge* Graph::add_edge(int e_start, int e_end, float weight) noexcept {
|
|||||||
return &all_edges[target_edge];
|
return &all_edges[target_edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Graph::delete_edge(int e_start, int e_end) noexcept {
|
bool Flat_Buffer_Graph::delete_edge(int e_start, int e_end) noexcept {
|
||||||
Point& p = all_points[e_start];
|
Point& p = all_points[e_start];
|
||||||
int current = p.first_edge;
|
int current = p.first_edge;
|
||||||
int prev = -1;
|
int prev = -1;
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @author: Lewis Price
|
||||||
|
* @date: 06-09-2026 (MM-DD-YYYY)
|
||||||
|
* @brief: This file contains the class definition for the Flat_Buffer_Graph, which is a graph data structure that uses flat buffers to store points and edges. The class provides methods for adding and deleting points and edges, as well as printing the graph for debugging purposes.
|
||||||
|
* @version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -19,7 +27,6 @@ struct Point {
|
|||||||
bool is_active = false;
|
bool is_active = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @struct Edge
|
/** @struct Edge
|
||||||
* @brief Stores the end point and weight of the edge.
|
* @brief Stores the end point and weight of the edge.
|
||||||
* @param end_point Index of the point this edge goes to.
|
* @param end_point Index of the point this edge goes to.
|
||||||
@@ -32,7 +39,7 @@ struct Edge {
|
|||||||
int next_edge = -1;
|
int next_edge = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @class Graph
|
/** @class Flat_Buffer_Graph
|
||||||
* @brief Defines the default values for the private variables.
|
* @brief Defines the default values for the private variables.
|
||||||
*
|
*
|
||||||
* @param next_free_point The index of the next memory location in the Point buffer, where the next added point will go.
|
* @param next_free_point The index of the next memory location in the Point buffer, where the next added point will go.
|
||||||
@@ -49,7 +56,7 @@ struct Edge {
|
|||||||
* @param all_points The buffer that stores all of the points in the graph.
|
* @param all_points The buffer that stores all of the points in the graph.
|
||||||
* @param all_edges The buffer that stores all the edges in the graph.
|
* @param all_edges The buffer that stores all the edges in the graph.
|
||||||
*/
|
*/
|
||||||
class Graph {
|
class Flat_Buffer_Graph {
|
||||||
private:
|
private:
|
||||||
int next_free_point = -1;
|
int next_free_point = -1;
|
||||||
size_t num_points = 0;
|
size_t num_points = 0;
|
||||||
@@ -67,23 +74,23 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* @brief Creates a new Graph.
|
* @brief Creates a new Flat_Buffer_Graph.
|
||||||
* @param max_points Maximum number of points in the Graph.
|
* @param max_points Maximum number of points in the Flat_Buffer_Graph.
|
||||||
* @param max_edges Maximum number of edges in the Graph.
|
* @param max_edges Maximum number of edges in the Flat_Buffer_Graph.
|
||||||
*/
|
*/
|
||||||
Graph(size_t p_capacity, size_t e_capacity) noexcept;
|
Flat_Buffer_Graph(size_t p_capacity, size_t e_capacity) noexcept;
|
||||||
|
|
||||||
|
|
||||||
/** Deconstructor
|
/** Deconstructor
|
||||||
* @brief Deletes all_points and all_edges from memory
|
* @brief Deletes all_points and all_edges from memory
|
||||||
*/
|
*/
|
||||||
~Graph();
|
~Flat_Buffer_Graph();
|
||||||
|
|
||||||
/** Move Constructor
|
/** Move Constructor
|
||||||
* @brief Instructions to move the current graph object from one memory location to another without copying.
|
* @brief Instructions to move the current graph object from one memory location to another without copying.
|
||||||
* @param new_location The new memory location to move the graph to.
|
* @param new_location The new memory location to move the graph to.
|
||||||
*/
|
*/
|
||||||
Graph(Graph&& new_location) noexcept;
|
Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept;
|
||||||
|
|
||||||
/** Debug Function: print_graph
|
/** Debug Function: print_graph
|
||||||
* @brief Prints all points and their edges.
|
* @brief Prints all points and their edges.
|
||||||
@@ -161,6 +168,6 @@ public:
|
|||||||
bool delete_edge(int e_start, int e_end) noexcept;
|
bool delete_edge(int e_start, int e_end) noexcept;
|
||||||
|
|
||||||
//Enforcing deletions to prevent memory spikes.
|
//Enforcing deletions to prevent memory spikes.
|
||||||
Graph(const Graph&) = delete;
|
Flat_Buffer_Graph(const Flat_Buffer_Graph&) = delete;
|
||||||
Graph& operator=(const Graph&) = delete;
|
Flat_Buffer_Graph& operator=(const Flat_Buffer_Graph&) = delete;
|
||||||
};
|
};
|
||||||
@@ -48,13 +48,13 @@ PROJECT_NAME = "Graph Theory"
|
|||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER =
|
PROJECT_NUMBER = 1.0.0
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewers a
|
# for a project that appears at the top of each page and should give viewers a
|
||||||
# quick idea about the purpose of the project. Keep the description short.
|
# quick idea about the purpose of the project. Keep the description short.
|
||||||
|
|
||||||
PROJECT_BRIEF =
|
PROJECT_BRIEF =
|
||||||
|
|
||||||
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
|
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
|
||||||
# in the documentation. The maximum height of the logo should not exceed 55
|
# in the documentation. The maximum height of the logo should not exceed 55
|
||||||
@@ -215,7 +215,7 @@ SHORT_NAMES = NO
|
|||||||
# explicit @brief command for a brief description.)
|
# explicit @brief command for a brief description.)
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
JAVADOC_AUTOBRIEF = NO
|
JAVADOC_AUTOBRIEF = YES
|
||||||
|
|
||||||
# If the JAVADOC_BANNER tag is set to YES then Doxygen will interpret a line
|
# If the JAVADOC_BANNER tag is set to YES then Doxygen will interpret a line
|
||||||
# such as
|
# such as
|
||||||
|
|||||||
16
main.cpp
16
main.cpp
@@ -1,10 +1,20 @@
|
|||||||
// Linked List Cycle.cpp :
|
/**
|
||||||
|
* @author: Lewis Price
|
||||||
|
* @date: 06-09-2026 (MM-DD-YYYY)
|
||||||
|
* @brief: This file contains the code required for running the Graph Theory project. It includes the main function and several test case graphs to demonstrate the functionality of the Flat_Buffer_Graph class.
|
||||||
|
* @
|
||||||
|
* @version: 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Graph.h"
|
#include "Flat_Buffer_Graph.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
Flat_Buffer_Graph* g = new Flat_Buffer_Graph(5, 7);
|
||||||
|
g->add_point("Charlotte", 1.2222, 1.22222, 720.73425);
|
||||||
|
g->add_point("Waco", 1.1111, 1.1111, 200.00);
|
||||||
|
g->add_edge(1, 1, 20);
|
||||||
|
g->print_graph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user