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

173
Flat_Buffer_Graph.h Normal file
View File

@@ -0,0 +1,173 @@
/**
* @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>
#include <string>
/** @struct Point
* @param x width value
* @param y heighth value
* @param z Depth value
* @param first_edge Offset of the first edge in memory for a point.
* @param e_count Number of edges for a point.
*/
struct Point {
std::string name;
float x, y, z;
int first_edge = -1;
int e_count = 0;
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.
* @param e_weight Weight of the edge.
* @param next_edge Memory location of the next edge in the Edge Buffer.
*/
struct Edge {
int end_point;
float e_weight;
int next_edge = -1;
};
/** @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.
* @param num_points The number of points currently being stored in the Point buffer.
*
* @param next_free_edge The index of the next memory locaiton in the Edge buffer where the next added edge will go.
* @param num_edges The number of edges currently being stored in the buffer.
*
* @param next_possible_edge The offset to the next possible edge memory location.
*
* @param p_capacity The total number of points able to be stored in the buffer.
* @param e_capacity The total number of edges able to be stored in the buffer.
*
* @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 Flat_Buffer_Graph {
private:
int next_free_point = -1;
size_t num_points = 0;
int next_free_edge = -1;
size_t num_edges = 0;
size_t next_possible_edge = 0;
size_t p_capacity = 0;
size_t e_capacity = 0;
Point* all_points = nullptr;
Edge* all_edges = nullptr;
public:
/** Constructor
* @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.
*/
Flat_Buffer_Graph(size_t p_capacity, size_t e_capacity) noexcept;
/** Deconstructor
* @brief Deletes all_points and all_edges from memory
*/
~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.
*/
Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept;
/** Debug Function: print_graph
* @brief Prints all points and their edges.
*
* @return Console print statement.
*/
void print_graph() noexcept;
/** Debug Function: print_points
* @brief Prints all points.
*
* @returns Console print statement.
*/
void print_points() noexcept;
/** Debug function: print_edges
* @brief Prints all edges.
*
* @returns Console print statement.
*/
void print_edges() noexcept;
/** Getter Function: get_points
* @brief Gets the memory address of all of the points on given graph.
*
* @returns The address of the first Point in the graph.
*/
Point* get_points() noexcept;
/** Getter Function: get_p_edges
* @brief Gets the address of the first edge for Point P at index p_index.
*
* @param p_index The index (int) of the point.
* @returns Edge* : the address of the first edge for p_index.
* */
Edge* get_p_edges(int p_index) noexcept;
/** add_point
* @brief Adds a point onto the graph.
*
* @param name The name of the point.
* @param x The width value.
* @param y The heighth value.
* @param z The depth value.
* @returns The memory location of the point.
*/
Point* add_point(std::string name, float x, float y, float z) noexcept;
/** delete_point
* @brief Removes a point from the graph.
*
* @param p_index The index of the point to be deleted.
* @returns True on successful deletion.
*/
bool delete_point(int p_index) noexcept;
/** add_edge
* @brief Adds an edge between two points.
*
* @param e_start The index of the starting point.
* @param e_end The index of the ending point.
*
* @returns A pointer to the newly added edge.
**/
Edge* add_edge(int e_start, int e_end, float weight) noexcept;
/** delete_edge
* @brief Deletes on edge from Point A to Point B.
*
* @param e_start The index of the starting point.
* @param e_end The index of the ending point.
*
* @return TRUE if the edge was found and deleted, FALSE otherwise.
*/
bool delete_edge(int e_start, int e_end) noexcept;
//Enforcing deletions to prevent memory spikes.
Flat_Buffer_Graph(const Flat_Buffer_Graph&) = delete;
Flat_Buffer_Graph& operator=(const Flat_Buffer_Graph&) = delete;
};