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:
2026-04-09 09:53:54 -04:00
parent 7d82612b69
commit e0c68e7cef
5 changed files with 95 additions and 27 deletions

28
.vscode/tasks.json vendored Normal file
View 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"
}

View File

@@ -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
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_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_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_edges(std::exchange(new_location.all_edges, nullptr)),
p_capacity(std::exchange(new_location.p_capacity, 0)),
@@ -27,19 +35,34 @@ Graph::Graph(Graph&& new_location) noexcept
// End : Construction & Deconstruction
// ----------------------- 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 -----------------------
// ----------------------- BEGIN : Getters -----------------------
Point* Graph::get_points() noexcept
Point* Flat_Buffer_Graph::get_points() noexcept
{
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;
@@ -53,7 +76,7 @@ Edge* Graph::get_p_edges(int p_index) noexcept
// ----------------------- 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;
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;
// 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
if (e_start < 0 || (size_t)e_start >= p_capacity ||
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];
}
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];
int current = p.first_edge;
int prev = -1;

View File

@@ -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
#include <new>
#include <utility>
@@ -19,7 +27,6 @@ struct Point {
bool is_active = false;
};
/** @struct Edge
* @brief Stores the end point and weight of the edge.
* @param end_point Index of the point this edge goes to.
@@ -32,7 +39,7 @@ struct Edge {
int next_edge = -1;
};
/** @class Graph
/** @class Flat_Buffer_Graph
* @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.
@@ -49,7 +56,7 @@ struct Edge {
* @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.
*/
class Graph {
class Flat_Buffer_Graph {
private:
int next_free_point = -1;
size_t num_points = 0;
@@ -67,23 +74,23 @@ private:
public:
/** Constructor
* @brief Creates a new Graph.
* @param max_points Maximum number of points in the Graph.
* @param max_edges Maximum number of edges in the Graph.
* @brief Creates a new Flat_Buffer_Graph.
* @param max_points Maximum number of points in the Flat_Buffer_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
* @brief Deletes all_points and all_edges from memory
*/
~Graph();
~Flat_Buffer_Graph();
/** Move Constructor
* @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.
*/
Graph(Graph&& new_location) noexcept;
Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept;
/** Debug Function: print_graph
* @brief Prints all points and their edges.
@@ -161,6 +168,6 @@ public:
bool delete_edge(int e_start, int e_end) noexcept;
//Enforcing deletions to prevent memory spikes.
Graph(const Graph&) = delete;
Graph& operator=(const Graph&) = delete;
Flat_Buffer_Graph(const Flat_Buffer_Graph&) = delete;
Flat_Buffer_Graph& operator=(const Flat_Buffer_Graph&) = delete;
};

View File

@@ -48,7 +48,7 @@ PROJECT_NAME = "Graph Theory"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER =
PROJECT_NUMBER = 1.0.0
# 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
@@ -215,7 +215,7 @@ SHORT_NAMES = NO
# explicit @brief command for a brief description.)
# 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
# such as

View File

@@ -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>
using namespace std;
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();
}