p.enthalabs

GitHub - RANDOMFNP/Graphlib: Graphlib is a C++ library that empowers users to create and edit graphs!

Graphlib is a C++ library that empowers users to create and edit graphs!

If you want to contribute to GRAPHLIB, check out the CONTRIBUTING.md file!

If this product helped you, please leave a star! If it doesn't, tell me whats wrong, I respond to issues within 1-3 days!

DISCLAIMER: If this is a fork, the main repository is github.com/randomfnp/graphlib come check it out!

NEWS

[](https://github.com/RANDOMFNP/Graphlib#news) Switched license from AGPL v3 to Apache 2.0

Great first issues

[](https://github.com/RANDOMFNP/Graphlib#great-first-issues) Here I will post some of the best first issues I see and its status

- #2 -- Inefficiencies

Importing Graphlib 📦

[](https://github.com/RANDOMFNP/Graphlib#importing-graphlib-) For most applications, `#include "graphlib.hpp"` will suffice.

Linking without CMake 📦

[](https://github.com/RANDOMFNP/Graphlib#linking-without-cmake-)

Using g++

[](https://github.com/RANDOMFNP/Graphlib#using-g)

Example usage: `g++ program.cpp -I graphlib/include/ -I graphlib/detail/ -o program`, make sure to include graphlib/include/ and graphlib/detail/ **NOTE:** This is a C++ 20 (but soon to be 23) library and will not function if you are on too old of a g++ compiler, we recommend g++ 12 as a minimum

Using clang

[](https://github.com/RANDOMFNP/Graphlib#using-clang)

Example usage: `clang++ program.cpp -I graphlib/include/ -I ./graphlib/detail/ -o program`, make sure to include graphlib/include/ and graphlib/detail/ **NOTE:** This is C++ 20 (but soon to be 23) library and will not function if you are on too old of a clang compiler, we recommend clang 14 as a minimum

Using MSVC

[](https://github.com/RANDOMFNP/Graphlib#using-msvc) Example usage: `cl.exe /EHsc program.cpp /Fe:program.exe`**NOTE:** This is a C++ 20 (but soon to be 23) library and will not function if you are using too old of an MVSC compile, we recommend MSVC 19.44 as a minimum

Functions

[](https://github.com/RANDOMFNP/Graphlib#functions)

- node: AnyType

- weight: int/float

`graphlib::create_graph(std::unordered_map<node, std::vector<node>> graph, std::string output_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibcreate_graphstdunordered_mapnode-stdvectornode-graph-stdstring-output_file) create_graph() creates the initial graph containing the first node vector node pairs.

`graphlib::create_graph(std::unordered_map<node, std::vector<std::pair<node, weight>>> graph, std::string output_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibcreate_graphstdunordered_mapnode-stdvectorstdpairnode-weight-graph-stdstring-output_file) The weighted version of create_graph() creates the initial graph containing the first node vector node weight pairs.

`graphlib::add_nodes(std::unordered_map<node, std::vector<node>> graph, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibadd_nodesstdunordered_mapnode-stdvectornode-graph-stdstring-input_file) add_nodes() appends `graph` to the end of a file.

`void add_edge(std::vector<node> new_value, node key, std::unordered_map<node, std::vector<node>> graph, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#void-add_edgestdvectornode-new_value-node-key-stdunordered_mapnode-stdvectornode-graph-stdstring-input_file) The in-memory version of add_edge() takes all the normal arguments but the graph is taken as an argument as well.

`graphlib::add_nodes(std::unordered_map<node, std::vector<std::pair<node, weight> graph, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibadd_nodesstdunordered_mapnode-stdvectorstdpairnode-weight-graph-stdstring-input_file) The weighted version of add_nodes() appends `graph` to the end of a file.

`void add_edge(std::vector<std::pair<node, weights>> new_value, node key, std::unordered_map<node, std::vector<std::pair<node, weights>>> graph, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#void-add_edgestdvectorstdpairnode-weights-new_value-node-key-stdunordered_mapnode-stdvectorstdpairnode-weights-graph-stdstring-input_file) The in-memory and weighted version of add_edge() takes all the normal arguments but the graph is taken as an argument as well.

`graphlib::delete_instances(std::string node_to_delete, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibdelete_instancesstdstring-node_to_delete-stdstring-input_file) delete_instances() removes all instances of `node_to_delete` from the file.

`graphlib::delete_instances_weighted(std::string node_to_delete, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibdelete_instances_weightedstdstring-node_to_delete-stdstring-input_file) The weighted version of delete_instances() removes all instances of `node_to_delete` and its weight from the file.

`graphlib::add_edge(std::vector<node>, node key, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibadd_edgestdvectornode-node-key-stdstring-input_file) add_edge() appends the vector of nodes to the vector at location `key` and then writes it to the file.

`graphlib::add_edge(std::vector<std::pair<node, weight> node key, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibadd_edgestdvectorstdpairnode-weight-node-key-stdstring-input_file) The weighted version of add_edge() appends the vector of nodes to the vector at location `key` and then writes it to the file.

`graphlib::parse<type1(node)>(std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibparsetype1nodestdstring-input_file) parse() opens a file and returns a std::unordered_map<node, std::vector>.

`graphlib::parse_weighted<type1(node), type2(weight)>(std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibparse_weightedtype1node-type2weightstdstring-input_file) parse<type, weight>() opens a file with weights and returns a std::unordered_map<node, std::vector<std::pair<node, weight>>>.

`graphlib::print_graph(std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibprint_graphstdstring-input_file) print_graph() prints out the contents of a file.

Algorithms

[](https://github.com/RANDOMFNP/Graphlib#algorithms)

`graphlib::bfs_algorithm(node starting_node, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibbfs_algorithmnode-starting_node-stdstring-input_file) bfs_algorithm() runs BFS starting from `starting_node` to the end of the file.

`std::vector bfs_algorithm(node starting_node, std::unordered_map<node, std::vector> graph)

[](https://github.com/RANDOMFNP/Graphlib#stdvector-bfs_algorithmnode-starting_node-stdunordered_mapnode-stdvector-graph) The in-memory version of bfs_algorithm() runs BFS but takes the graph as an argument instead of the input file

`graphlib::dfs_algorithm(node starting_node, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibdfs_algorithmnode-starting_node-stdstring-input_file) dfs_algorithm() runs DFS starting from `starting_node` to the end of the file.

`dfs_algorithm(node starting_value, std::unordered_map<node, std::vector<node>> graph)`

[](https://github.com/RANDOMFNP/Graphlib#dfs_algorithmnode-starting_value-stdunordered_mapnode-stdvectornode-graph) The in-memory version of dfs_algorithm() runs DFS but takes the graph as an argument instead of the input file

`graphlib::dijkstras_algorithm(node starting_node, std::string input_file)`

[](https://github.com/RANDOMFNP/Graphlib#graphlibdijkstras_algorithmnode-starting_node-stdstring-input_file) dijkstras_algorithm() runs Dijkstra's algorithm from `starting_node` to the end of the file.

`dijkstras_algorithm(node starting_node, std::unordered_map<node, std::vector<std::pair<node, weights>>> graph)`

[](https://github.com/RANDOMFNP/Graphlib#dijkstras_algorithmnode-starting_node-stdunordered_mapnode-stdvectorstdpairnode-weights-graph) The in-memory version of dijkstras_algorithm() runs Dijkstra's algorithm but takes the graph as an argument instead of the input file

`get_neighbors(node key, std::unordered_map<node, std::vector<node>> graph)`

[](https://github.com/RANDOMFNP/Graphlib#get_neighborsnode-key-stdunordered_mapnode-stdvectornode-graph) get_neighbors() gets the neighbors of a certain key

`get_neighbors(node key, std::unordered_map<node, std::vector<std::pair<node, weights>>> graph)`

[](https://github.com/RANDOMFNP/Graphlib#get_neighborsnode-key-stdunordered_mapnode-stdvectorstdpairnode-weights-graph) The weighted version of get_neighbors() gets the neighbors of a certain key