Changed flat_buffer_graph to fb_graph for convenience. Moved fb_graph.cpp and .h files into their own directory. Created teh initial files for the fb_map which will be code for flat buffer hash map.
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* @author: Lewis Price
|
* @author: Lewis Price
|
||||||
* @date: 06-09-2026 (MM-DD-YYYY)
|
* @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.
|
* @brief: This file contains the class definition for the fb_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
|
* @version: 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Flat_Buffer_Graph.h"
|
#include "fb_graph.h"
|
||||||
|
|
||||||
// Begin : Construction & Deconstruction
|
// Begin : Construction & Deconstruction
|
||||||
Flat_Buffer_Graph::Flat_Buffer_Graph(size_t max_points, size_t max_edges) noexcept
|
fb_graph::fb_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] {};
|
||||||
@@ -21,13 +21,13 @@ Flat_Buffer_Graph::Flat_Buffer_Graph(size_t max_points, size_t max_edges) noexce
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Flat_Buffer_Graph::~Flat_Buffer_Graph()
|
fb_graph::~fb_graph()
|
||||||
{
|
{
|
||||||
delete[] all_points;
|
delete[] all_points;
|
||||||
delete[] all_edges;
|
delete[] all_edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
Flat_Buffer_Graph::Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept
|
fb_graph::fb_graph(fb_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)),
|
||||||
@@ -35,7 +35,7 @@ Flat_Buffer_Graph::Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept
|
|||||||
// End : Construction & Deconstruction
|
// End : Construction & Deconstruction
|
||||||
|
|
||||||
// ----------------------- BEGIN : Printing -----------------------
|
// ----------------------- BEGIN : Printing -----------------------
|
||||||
void Flat_Buffer_Graph::print_graph() noexcept
|
void fb_graph::print_graph() noexcept
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < p_capacity; ++i) {
|
for (size_t i = 0; i < p_capacity; ++i) {
|
||||||
Point& p = all_points[i];
|
Point& p = all_points[i];
|
||||||
@@ -57,12 +57,12 @@ void Flat_Buffer_Graph::print_graph() noexcept
|
|||||||
|
|
||||||
// ----------------------- BEGIN : Getters -----------------------
|
// ----------------------- BEGIN : Getters -----------------------
|
||||||
|
|
||||||
Point* Flat_Buffer_Graph::get_points() noexcept
|
Point* fb_graph::get_points() noexcept
|
||||||
{
|
{
|
||||||
return all_points;
|
return all_points;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edge* Flat_Buffer_Graph::get_p_edges(int p_index) noexcept
|
Edge* fb_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;
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ Edge* Flat_Buffer_Graph::get_p_edges(int p_index) noexcept
|
|||||||
|
|
||||||
// ----------------------- BEGIN : Mutators -----------------------
|
// ----------------------- BEGIN : Mutators -----------------------
|
||||||
|
|
||||||
Point* Flat_Buffer_Graph::add_point(std::string name, float x, float y, float z) noexcept {
|
Point* fb_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) {
|
||||||
@@ -100,7 +100,7 @@ Point* Flat_Buffer_Graph::add_point(std::string name, float x, float y, float z)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Flat_Buffer_Graph::delete_point(int p_index) {
|
bool fb_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!
|
||||||
@@ -119,7 +119,7 @@ bool Flat_Buffer_Graph::delete_point(int p_index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Edge* Flat_Buffer_Graph::add_edge(int e_start, int e_end, float weight) noexcept {
|
Edge* fb_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;
|
||||||
@@ -148,7 +148,7 @@ Edge* Flat_Buffer_Graph::add_edge(int e_start, int e_end, float weight) noexcept
|
|||||||
return &all_edges[target_edge];
|
return &all_edges[target_edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Flat_Buffer_Graph::delete_edge(int e_start, int e_end) noexcept {
|
bool fb_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,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author: Lewis Price
|
* @author: Lewis Price
|
||||||
* @date: 06-09-2026 (MM-DD-YYYY)
|
* @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.
|
* @brief: This file contains the class definition for the fb_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
|
* @version: 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ struct Edge {
|
|||||||
int next_edge = -1;
|
int next_edge = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @class Flat_Buffer_Graph
|
/** @class fb_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.
|
||||||
@@ -56,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 Flat_Buffer_Graph {
|
class fb_graph {
|
||||||
private:
|
private:
|
||||||
int next_free_point = -1;
|
int next_free_point = -1;
|
||||||
size_t num_points = 0;
|
size_t num_points = 0;
|
||||||
@@ -74,23 +74,23 @@ private:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* @brief Creates a new Flat_Buffer_Graph.
|
* @brief Creates a new fb_graph.
|
||||||
* @param max_points Maximum number of points in the Flat_Buffer_Graph.
|
* @param max_points Maximum number of points in the fb_graph.
|
||||||
* @param max_edges Maximum number of edges in the Flat_Buffer_Graph.
|
* @param max_edges Maximum number of edges in the fb_graph.
|
||||||
*/
|
*/
|
||||||
Flat_Buffer_Graph(size_t p_capacity, size_t e_capacity) noexcept;
|
fb_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
|
||||||
*/
|
*/
|
||||||
~Flat_Buffer_Graph();
|
~fb_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.
|
||||||
*/
|
*/
|
||||||
Flat_Buffer_Graph(Flat_Buffer_Graph&& new_location) noexcept;
|
fb_graph(fb_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.
|
||||||
@@ -168,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.
|
||||||
Flat_Buffer_Graph(const Flat_Buffer_Graph&) = delete;
|
fb_graph(const fb_graph&) = delete;
|
||||||
Flat_Buffer_Graph& operator=(const Flat_Buffer_Graph&) = delete;
|
fb_graph& operator=(const fb_graph&) = delete;
|
||||||
};
|
};
|
||||||
0
fb_map/fb_map.cpp
Normal file
0
fb_map/fb_map.cpp
Normal file
0
fb_map/fb_map.h
Normal file
0
fb_map/fb_map.h
Normal file
6
main.cpp
6
main.cpp
@@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* @author: Lewis Price
|
* @author: Lewis Price
|
||||||
* @date: 06-09-2026 (MM-DD-YYYY)
|
* @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.
|
* @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 fb_graph class.
|
||||||
* @
|
* @
|
||||||
* @version: 1.0.0
|
* @version: 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Flat_Buffer_Graph.h"
|
#include "fb_graph/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);
|
fb_graph* g = new fb_graph(5, 7);
|
||||||
g->add_point("Charlotte", 1.2222, 1.22222, 720.73425);
|
g->add_point("Charlotte", 1.2222, 1.22222, 720.73425);
|
||||||
g->add_point("Waco", 1.1111, 1.1111, 200.00);
|
g->add_point("Waco", 1.1111, 1.1111, 200.00);
|
||||||
g->add_edge(1, 1, 20);
|
g->add_edge(1, 1, 20);
|
||||||
|
|||||||
Reference in New Issue
Block a user