aegisgraph
A high-performance, secure C++ graph library using adjacency lists
Loading...
Searching...
No Matches
Graph.hpp
Go to the documentation of this file.
1
18#ifndef GRAPH_H
19#define GRAPH_H
20
21#include <string>
22#include <vector>
23#include <unordered_map>
24#include <unordered_set>
25#include <mutex>
26#include <memory>
27#include <shared_mutex>
28#include <utility>
29#include "absl/container/flat_hash_map.h"
30
31#include <utility> // For std::pair
32
33struct PairHash {
34 template <class T1, class T2>
35 size_t operator()(const std::pair<T1, T2>& p) const noexcept {
36 return absl::HashOf(p.first, p.second);
37 }
38};
39
40class Graph {
41public:
42 Graph() = default;
43
48 void load_graph(const std::string& filepath);
49
55 const std::vector<int>& get_neighbors(int node) const;
56
61 void add_node(int node);
62
67 void delete_node(int node);
68
77void save_graph(const std::string& filename) const;
78
79private:
80 absl::flat_hash_map<int, std::shared_ptr<const std::vector<int>>> adj_list;
81 static const std::vector<int> static_empty_vector; // Single shared instance
82 mutable std::shared_mutex adj_list_mutex; // Thread-safe access control
83
84
90 bool validate_filepath(const std::string& path) const;
91};
92
93#endif // GRAPH_H
Definition Graph.hpp:40
void save_graph(const std::string &filename) const
Save the graph to a file in edge list format.
Definition Graph.cpp:171
void delete_node(int node)
Deletes a node and its edges from the graph.
Definition Graph.cpp:148
void load_graph(const std::string &filepath)
Loads an edge list from a file into an adjacency list.
Definition Graph.cpp:66
const std::vector< int > & get_neighbors(int node) const
Gets the neighbors of a given node.
Definition Graph.cpp:133
void add_node(int node)
Adds a node to the graph.
Definition Graph.cpp:143
Definition Graph.hpp:33