Skip to content

Commit d2f4b51

Browse files
authored
YT-CPPGL-61: Prepare the GL module's documentation
- Updated the project license - Added the Doxyfile and mkdocs.yml configuration files and a Makefile with documentation targets - Added documentation comments to the public API elements of the GL module - Prepared the tutorial pages and images for the GL module's documenation - Defined a utility script for generating documentation pages for the library's concepts - Renamed the `return_type` and `non_void_return_type` and related utility to use the `result` naming - Modified the PFS template implementation to accept arbitrary* search nodes - Renamed the `enqueue vertex predicate` types and arguments for algorithm templates to use the (search) node naming - Fixed the Dijkstra's algorithm implementation to properly utilize custom PFS search nodes and properly handle distance comparison within the min heap - Removed unused/redundant elements
1 parent 0027f14 commit d2f4b51

110 files changed

Lines changed: 12504 additions & 1043 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99

1010
# documentation files
1111
documentation/
12+
site/
13+
mike-*.yml
14+
docs/cpp-gl/
1215

1316
# python temporary files
1417
**/__pycache__/
18+
.ruff_cache/
19+
.venv/
1520

1621
# other
1722
*tmp*/

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.14

Doxyfile

Lines changed: 2801 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE renamed to LICENSE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
MIT License
1+
#### MIT License
22

3-
Copyright (c) 2024 Jakub Musiał
4-
Project: "CPP-GL: General purpose header-only template graph library for C++23 and newer standards."
5-
https://github.com/SpectraL519/cpp-gl
3+
Copyright (c) 2024-2026 Jakub Musiał
4+
Project: "CPP-GL: General-purpose Template Graph and Hypergraph Library for Modern C++"
5+
URL: https://github.com/SpectraL519/cpp-gl
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Default to 'dev' if TAGS is not specified on the command line
2+
TAGS ?= dev
3+
4+
.PHONY: docs serve-docs clean-docs clean
5+
6+
# Example usage: `make docs TAGS="v2.0.0 latest --update-aliases"`
7+
docs: clean-docs
8+
@echo "==> Deploying MkDocs documentation locally via mike (Tags: $(TAGS))..."
9+
doxygen Doxyfile
10+
uv run python docs/scripts/gen_concept_docs.py --config docs/config/concepts.json --xml documentation/xml --out docs/cpp-gl
11+
uv run mike deploy $(TAGS)
12+
@echo "==> Documentation deployed to local gh-pages branch."
13+
14+
serve-docs: docs
15+
@echo "==> Serving versioned MkDocs documentation locally via mike..."
16+
uv run mike serve
17+
18+
clean-docs:
19+
@echo "==> Cleaning documentation build directories..."
20+
rm -rf docs/cpp-gl/
21+
rm -rf site/
22+
rm -rf documentation/
23+
24+
clean: clean-docs

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
<div align="center">
1010

11-
[![g++](https://github.com/SpectraL519/cpp-gl/actions/workflows/gpp.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/g++)
12-
[![clang++](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang++)
13-
[![format](https://github.com/SpectraL519/cpp-gl/actions/workflows/format.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/format)
14-
[![benchmarks](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml)
11+
[![G++](https://github.com/SpectraL519/cpp-gl/actions/workflows/gpp.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/gpp.yaml)
12+
[![Clang++](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang.yaml)
13+
[![Code Formatting](https://github.com/SpectraL519/cpp-gl/actions/workflows/format.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/format.yaml)
14+
[![Benchmarks Smoke Test](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/benchmarks.yaml)
1515

1616
</div>
1717

@@ -108,4 +108,4 @@ target_link_libraries(my_project PRIVATE cpp-gl)
108108

109109
## Licence
110110

111-
The `CPP-GL` project uses the [MIT Licence](https://mit-license.org/) which can be found in the [LICENCE](/LICENSE) file
111+
The `CPP-GL` project uses the [MIT Licence](https://mit-license.org/) which can be found in the [LICENCE](/LICENSE.md#mit-licence) file

docs/config/concepts.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"index": {
3+
"title": "Concepts API Reference",
4+
"anchor": "concepts-api-reference",
5+
"description": "This page serves as the central index for all C++20 concepts defined within the library."
6+
},
7+
"groups": {
8+
"GL": {
9+
"prefix": "gl::",
10+
"filename": "gl_concepts.md",
11+
"anchor": "gl-concepts-documentation",
12+
"title": "GL Concepts",
13+
"description": "This page documents the C++20 concepts defined within the GL module of the library."
14+
},
15+
"HGL": {
16+
"prefix": "hgl::",
17+
"filename": "hgl_concepts.md",
18+
"anchor": "hgl-concepts-documentation",
19+
"title": "HGL Concepts",
20+
"description": "This page documents the C++20 concepts defined within the HGL module of the library."
21+
}
22+
}
23+
}

docs/config/groups.dox

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/// @defgroup GL Graph Library (GL)
2+
/// @brief The top-level module defining the general-purpose C++ template graph library.
3+
///
4+
/// This module provides a comprehensive suite of memory-efficient graph representations,
5+
/// highly customizable algorithms, topology generators, and robust I/O facilities. Designed
6+
/// strictly around modern C++ paradigms, the library heavily leverages templates and concepts
7+
/// to deliver an API that is exceptionally fast, generic, and type-safe.
8+
9+
/// @defgroup GL-Core Core Graph Components
10+
/// @ingroup GL
11+
/// @brief Fundamental graph data structures, element descriptors, and configuration tags.
12+
///
13+
/// This group establishes the primary user interface for the library, centered around the highly
14+
/// configurable @ref gl::graph "graph" class. It provides the core data types, such as vertex
15+
/// and edge descriptors, required to safely navigate and manipulate graph elements.
16+
///
17+
/// Furthermore, this module defines the declarative tags (e.g., directedness and backend
18+
/// implementation types) that dictate both the behavioral semantics and the underlying memory
19+
/// layout of the instantiated graphs.
20+
21+
/// @defgroup GL-Algorithm Graph Algorithms
22+
/// @ingroup GL
23+
/// @brief Generic graph algorithms, foundational search templates, and related utilities.
24+
///
25+
/// This module provides a dual-layered approach to graph algorithms. At its core, it features highly
26+
/// generic and extensible search templates (such as BFS, DFS, and Priority-First Search). These
27+
/// templates serve as the foundational building blocks of the library, empowering users to inject
28+
/// custom behavior via callbacks and predicates to build entirely new algorithms with minimal effort.
29+
///
30+
/// Alongside these templates, the module offers a suite of concrete, ready-to-use algorithms.
31+
/// Rather than a flat list of functions, the algorithms are categorized into broad domains,
32+
/// including basic graph traversal, pathfinding, minimum spanning trees, and topological
33+
/// operations like sorting and coloring. All implementations are designed to operate seamlessly
34+
/// with generic graph types and property maps.
35+
36+
/// @defgroup GL-Topology Graph Topologies
37+
/// @ingroup GL
38+
/// @brief Generators and evaluators for standard structural graph topologies.
39+
///
40+
/// A collection of lightweight utilities designed to quickly instantiate classic graph topologies.
41+
/// Featuring out-of-the-box support for cliques (complete graphs), bipartite graphs, binary trees,
42+
/// paths, and cycles, these generators are ideal for rapid prototyping, algorithm benchmarking,
43+
/// and automated testing.
44+
45+
/// @defgroup GL-IO I/O Utility
46+
/// @ingroup GL
47+
/// @brief Comprehensive I/O stream support, parsing algorithms, and range-based formatting.
48+
///
49+
/// This group provides the necessary infrastructure to seamlessly serialize, deserialize, and
50+
/// visualize complex graph structures. By offering a robust set of stream manipulators, formatting
51+
/// traits, and configuration options, it allows users to easily translate in-memory graphs to
52+
/// and from standard streams, files, or custom string representations.
53+
54+
/// @defgroup GL-Traits Traits & Concepts
55+
/// @ingroup GL
56+
/// @brief Type traits, template constraints, and compile-time metaprogramming utilities.
57+
///
58+
/// Encapsulating the `gl::traits` namespace, these components form the strict conceptual backbone
59+
/// of the library. They are used extensively to constrain template parameters, safely query type
60+
/// properties at compile time, and ensure that user-provided graphs and property maps meet
61+
/// required structural and behavioral contracts.
62+
///
63+
/// @section concepts_link Detailed Concept Specifications
64+
/// For a detailed list of all GL module's concepts and their formal requirements, please refer to
65+
/// the [GL Concepts Documentation](gl_concepts.md#gl-concepts-documentation) page.
66+
67+
/// @defgroup GL-Types Generic Types
68+
/// @ingroup GL
69+
/// @brief Independent, high-performance data structures and utility types.
70+
///
71+
/// This module houses a variety of general-purpose data structures and types. While it features
72+
/// highly optimized memory containers (such as @ref gl::flat_matrix "flat_matrix" and
73+
/// @ref gl::flat_jagged_vector "flat_jagged_vector") that serve as the contiguous-memory backbones
74+
/// for the library's graphs, it also encompasses other fundamental type utilities. Because all
75+
/// components in this group are carefully decoupled from graph-specific logic, they can be seamlessly
76+
/// extracted and utilized in broader C++ programming contexts.
77+
78+
/// @defgroup GL-Util General Utilities
79+
/// @ingroup GL
80+
/// @brief Practical, domain-agnostic C++ helpers, mathematical functions, and polyfills.
81+
///
82+
/// While originally engineered to support the library's internal algorithms and graph modeling
83+
/// operations, these utilities are completely independent of graph theory semantics. They provide
84+
/// a curated set of highly reusable, general-purpose tools that can smoothly integrate into any
85+
/// modern C++ codebase.

docs/gl/advanced.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Advanced Features
2+
3+
The CPP-GL library is designed to be highly configurable, allowing developers to tune the library's internal behavior to meet strict performance and architectural requirements.
4+
5+
This page outlines the advanced configuration toggles and features available in the library.
6+
7+
---
8+
9+
## Forced Function Inlining
10+
11+
By default, C++ compilers use their own internal heuristics to decide whether a function marked with the `inline` keyword should actually be inlined. While modern compilers are generally excellent at this, relying purely on default cost models can sometimes leave small, heavily utilized accessors or structural traversal utilities un-inlined.
12+
13+
To guarantee zero-overhead abstraction in the most performance-critical code paths, CPP-GL provides an opt-in macro to forcibly inline a carefully selected set of core library methods.
14+
15+
### Enabling Forced Inlining
16+
17+
You can enable this feature by defining the `GL_CONFIG_FORCE_INLINE` macro. For consistent behavior across translation units, it is highly recommended to define this globally through your build system rather than in individual source files.
18+
19+
**Via CMake (Recommended):**
20+
21+
```cmake
22+
target_compile_definitions(my_application PRIVATE GL_CONFIG_FORCE_INLINE)
23+
```
24+
25+
**Via Code:**
26+
27+
If you must define it in code, ensure it is defined before including any CPP-GL headers.
28+
29+
```cpp
30+
#define GL_CONFIG_FORCE_INLINE
31+
#include <gl/graph.hpp>
32+
```
33+
34+
### How it Works
35+
36+
When `GL_CONFIG_FORCE_INLINE` is active, the library applies compiler-specific attributes, such as `[[clang::always_inline]]` for Clang or `[[gnu::always_inline]]` for GCC, to critical internal functions. This bypasses the compiler's standard inlining heuristics. If the macro is left undefined, the library safely falls back to using the standard C++ inline keyword.
37+
38+
> [!WARNING] Performance Trade-offs
39+
>
40+
> Forcing the compiler to inline functions is a double-edged sword. While it eliminates function call overhead and can expose more optimization opportunities (like constant propagation), it can also lead to significant code bloat.
41+
>
42+
> Excessively large binaries can cause instruction cache (i-cache) misses, which may ultimately degrade performance rather than improve it. Always profile and benchmark your application with and without `GL_CONFIG_FORCE_INLINE` to ensure it provides a tangible benefit for your specific workload.

docs/gl/algorithms/overview.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Algorithms Overview
2+
3+
The CPP-GL algorithms module is designed with a strict architectural separation of concerns. Rather than writing monolithic functions that handle both search mechanics and specific problem-solving logic, the library splits graph processing into two distinct layers: **Generic Templates (Engines)** and **Concrete Algorithms**.
4+
5+
This separation ensures maximum code reuse, provides strict zero-cost abstractions, and allows power users to inject highly customized logic directly into the traversal control flow.
6+
7+
## The Architectural Separation
8+
9+
### 1. The Generic Templates (Engines)
10+
11+
Located at the lowest level, the generic templates define the strict structural execution of a search. They know nothing about *shortest paths*, *spanning trees*, or *cycle detection*. Their only responsibility is to manage the pending elements (a queue, stack, or priority queue) and invoke a series of user-provided callback hooks at specific moments during the traversal.
12+
13+
The core generic templates include:
14+
15+
- [**`bfs`**](templates.md#the-core-engines): A queue-based Breadth-First Search engine.
16+
- [**`dfs`**](templates.md#the-core-engines): A stack-based, iterative Depth-First Search engine.
17+
- [**`r_dfs`**](templates.md#the-core-engines): A recursive Depth-First Search engine utilizing the call stack.
18+
- [**`pfs`**](templates.md#the-core-engines): A priority-queue-based Priority-First Search engine for custom heuristics.
19+
20+
### 2. The Concrete Algorithms
21+
22+
Concrete algorithms (like `dijkstra_shortest_paths`, `topological_sort`, or `breadth_first_search`) are essentially lightweight wrappers around the generic engines. They are responsible for:
23+
- Allocating and managing memory for algorithm state tracking (e.g., `std::vector<bool> visited` arrays, distance maps).
24+
- Defining the specific logic inside the lambda callbacks and predicates.
25+
- Managing the final return types and structures.
26+
27+
By separating these layers, CPP-GL guarantees that all algorithms inherently benefit from the exact same optimized design and element management.
28+
29+
## Core Algorithm Elements
30+
31+
To interact with the generic templates or understand the concrete algorithms, you must be familiar with a few foundational types and tags used uniformly across the library.
32+
33+
### Zero-Cost Callbacks
34+
35+
The generic engines accept up to 5 or 6 different callbacks per invocation. However, forcing the compiler to execute or optimize away empty lambdas (e.g., `[]{}`) can add overhead in debug builds and slow down compilation.
36+
37+
To solve this, CPP-GL uses the [**gl::algorithm::empty_callback**](../../cpp-gl/structgl_1_1algorithm_1_1empty__callback.md) tag. If a hook is not needed, the engine receives this tag, and compile-time evaluation (`if constexpr`) completely optimizes away that branch of execution.
38+
39+
### Tri-State Control Flow
40+
41+
When evaluating adjacent edges during a search, algorithms often need more control than a simple `true`/`false`. The [**gl::algorithm::decision**](../../cpp-gl/structgl_1_1algorithm_1_1decision.md) struct provides a tri-state evaluation:
42+
43+
- `decision::accept`: Proceed with the element (e.g., push it to the queue).
44+
- `decision::reject`: Skip this specific element, but continue the search.
45+
- `decision::abort`: Instantly terminate the entire algorithm.
46+
47+
For convenience, `decision` implicitly constructs from a boolean, where `true` maps to `accept` and `false` maps to `reject`. Furthermore, `decision` provides a boolean conversion operator, allowing it to be seamlessly evaluated in standard conditional statements (`if (enqueue_decision) { ... }`).
48+
49+
### The Search Node
50+
51+
By default, the active container of a search engine stores [**gl::algorithm::search_node<G>**](../../cpp-gl/structgl_1_1algorithm_1_1search__node.md) structures. This is a lightweight pair containing:
52+
53+
1. `vertex_id`: The vertex currently being visited.
54+
2. `pred_id`: The vertex from which this current vertex was reached (its parent in the traversal tree).
55+
56+
If a vertex is the starting point of a search, its `pred_id` is set to itself, making it a "root" node. The library provides the [**gl::algorithm::no_root**](../../cpp-gl/group__GL-Algorithm.md#variable-no_root) tag to explicitly identify states where a node lacks a predecessor.
57+
58+
### The Result Discriminator
59+
60+
Certain algorithms can either return a fully constructed result (like a tree mapping every vertex to its predecessor) or run purely for side-effects (like executing a lambda on every visited node).
61+
62+
CPP-GL manages this via the [**gl::algorithm::result_discriminator**](../../cpp-gl/group__GL-Algorithm.md#enum-result_discriminator) enum.
63+
- `ret`: The algorithm will allocate memory and return a stateful object (e.g., `predecessors_map<G>`).
64+
- `noret`: The algorithm will execute purely for side-effects and return `void` (or a simple success boolean).
65+
66+
## Available Concrete Algorithms
67+
68+
Explore the specific layers of the algorithm module below:
69+
70+
- [**The Generic Templates**](templates.md): A detailed explanation of the core traversal engines and their execution sequence.
71+
- [**Concrete Traversals**](traversal.md): Standard wrappers for basic component discovery and state-tracked searching.
72+
- [**Pathfinding**](pathfinding.md): Algorithms for finding the shortest path between nodes (e.g., Dijkstra).
73+
- [**Spanning Trees**](spanning_trees.md): Algorithms for finding Minimum Spanning Trees (e.g., Prim's).
74+
- [**Topological Algorithms**](topological_algs.md): Structural algorithms like topological sorting and bipartite coloring.

0 commit comments

Comments
 (0)