Graaf is a general-purpose lightweight graph library implemented in C++. Graaf allows users to easily create, modify, and query graphs. It is well-suited for various graph-based applications, including social network analysis, CNNs, and more.
The Graaf library is designed with generality in mind. As such, it comes with specializations for a directed_graph
as well as an undirected_graph
. Furthermore, it can be used to store user-defined vertex and edge classes:
graaf::undirected_graph<User, Connection> my_graph{};
const auto bob = my_graph.add_vertex(User{
.name = "Bob",
.age = 42
});
const auto alice = my_graph.add_vertex(User{
.name = "Alice",
.age = 33
});
my_graph.add_edge(bob, alice, Connection{
.type = connection_type::FRIENDS
});
Implementations for common graph algorithms are provided under the algorithm
namespace. For instance, there is support for traversing a graph using depth-first search and breadth-first search strategies.
const auto print_vertex_callback{[](const auto vertex) {
std::cout << vertex << std::endl;
}};
traverse<search_strategy::BFS>(my_graph, start_vertex, print_vertex_callback);
For more examples, take a look at our example section. More details can be found in our documentation.
The Graaf libary can be included as a header-only library. It requires a compiler with C++ 20 support and requires linking against fmt.
- C++ 20
- fmt/fmtlib
Download the header-only
library from our release page and add the include/graaflib
directory to your include path. You can now use Graaf in your source files:
// main.cpp
#include <graaflib/directed_graph>
For more details, see the installation README.
Alternatively, this project can be pulled in using CMake's FetchContent
:
include(FetchContent)
FetchContent_Declare(
graaflib
GIT_REPOSITORY https://github.com/bobluppes/graaf.git
GIT_TAG main
)
FetchContent_MakeAvailable(graaflib)
Now you can link your target against Graaf_lib
:
target_link_libraries(${PROJECT_NAME} PRIVATE Graaf_lib)
The Graaf library welcomes contributions!
If you're interested in improving, fixing bugs, or adding features, please refer to the wiki for guidelines. Check out our roadmap on YouTrack to stay up to date on planned features and improvements. We also have an issue tracker for bug reports and feature requests.
Feel free to join our Discord for assistance and a smooth contribution experience.
This project is licensed under the MIT license.