Added some Debug functions in the header file to be implemented. Reconfigured javadocs to be more consistent and prettier.
This commit is contained in:
118
graph.h
118
graph.h
@@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
|
||||
|
||||
/** @struct{Point}
|
||||
* @property float x : width value
|
||||
* @property float y : height value
|
||||
* @property float z : Depth value
|
||||
* @property int first_edge : offset of the first edge in memory for a point
|
||||
* @property int e_count : number of edges for a point
|
||||
/** @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;
|
||||
@@ -20,49 +20,58 @@ struct Point {
|
||||
};
|
||||
|
||||
|
||||
/** Edge
|
||||
* @brief Stores the end point and weight of the edge
|
||||
* @param end_point Index of the point this edge goes to.
|
||||
/** @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_index = -1;
|
||||
int next_edge = -1;
|
||||
};
|
||||
|
||||
/** @class Graph
|
||||
* @brief Defines the default values for the private variables
|
||||
* @property all_points The buffer that stores all of the points in the graph
|
||||
* @property all_edges The buffer that stores all the edges in the graph
|
||||
* @property next_possible_edge The offset to the next possible edge memory location
|
||||
* @property p_capacity The total number of points able to be stored
|
||||
* @property e_capacity The total number of edges able to be stored
|
||||
* @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 Graph {
|
||||
private:
|
||||
Point* all_points = nullptr;
|
||||
Edge* all_edges = nullptr;
|
||||
|
||||
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 Graph object
|
||||
* @param max_points Maximum number of points in the Graph
|
||||
* @param max_edges Maximum number of edges in the GRAPH (not the point)
|
||||
* @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.
|
||||
*/
|
||||
Graph(size_t maxPoints, size_t maxEdges) noexcept;
|
||||
Graph(size_t p_capacity, size_t e_capacity) noexcept;
|
||||
|
||||
|
||||
/** Deconstructor
|
||||
@@ -75,48 +84,68 @@ public:
|
||||
* @param new_location The new memory location to move the graph to.
|
||||
*/
|
||||
Graph(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
|
||||
* @brief Gets the memory address of all of the points on given graph.
|
||||
*
|
||||
* @returns The address of the first Point in the 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
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @brief Removes a point from the graph.
|
||||
*
|
||||
* @param p_index The index of the point to be deleted
|
||||
* @returns True on successful deletion
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @returns A pointer to the newly added edge.
|
||||
**/
|
||||
Edge* add_edge(int e_start, int e_end, float weight) noexcept;
|
||||
|
||||
@@ -124,15 +153,14 @@ public:
|
||||
/** delete_edge
|
||||
* @brief Deletes on edge from Point A to Point B.
|
||||
*
|
||||
* This function uses a tombstone method to decide if a point is active or just sitting in available memory
|
||||
* @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
|
||||
* @return TRUE if the edge was found and deleted, FALSE otherwise.
|
||||
*/
|
||||
bool delete_edge(int e_start, int e_end) noexcept;
|
||||
|
||||
//Preventing mem-spikes by preventing copying and enforcing deletions.
|
||||
//Enforcing deletions to prevent memory spikes.
|
||||
Graph(const Graph&) = delete;
|
||||
Graph& operator=(const Graph&) = delete;
|
||||
};
|
||||
Reference in New Issue
Block a user