Skip to content

Commit dbac867

Browse files
committed
aligned docs
1 parent 11f021d commit dbac867

2 files changed

Lines changed: 57 additions & 46 deletions

File tree

docs/algoithms.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ This section covers the specific types and type traits used for the algorithm im
3131
> [!NOTE]
3232
> All types listed below are defined in the `gl::algorithm` namespace
3333
34-
- `no_return` - A placeholder type to represent algorithms that do not return a value. It is primarily used in type traits to conditionally handle return types.
34+
- `result_discriminator` - An enumeration type used to discriminate whether the algorithm should return a result value or not.
35+
- **Members:**
36+
- `ret` - Indicates that the algorithm returns a value.
37+
- `noret` - Indicates that the algorithm does not return a value.
38+
- The `gl::algorithm` namespace [uses](https://en.cppreference.com/w/cpp/language/enum.html#using_enum_declaration) the `result_discriminator` enum, which allows for the usage of it's members directly from the `gl::algorithm` namespace, e.g. `gl::algorithm::noret`.
39+
3540
- `empty_callback` - Represents an empty callback, used as a default value where no callback functionality is needed.
3641

3742
- `vertex_callback`
@@ -68,6 +73,25 @@ This section covers the specific types and type traits used for the algorithm im
6873
- `edge: types::const_ref_wrap<EdgeType>` - a constant reference wrapper for the edge.
6974
- `source_id: types::id_type` - the ID of the source vertex of the held edge.
7075

76+
- `predicate_result`
77+
- *Description*: Represents the result of a predicate evaluation.
78+
- *Type definitions*:
79+
- `eval` - an enumeration type representing the result value.
80+
- `ok` - equivalent to `true`.
81+
- `not_ok` - equivalent to `false`.
82+
- `unknown` - represents an unknown result.
83+
- *Constructors*:
84+
- `predicate_result(const eval value)` - initializes the object with the given evaluation result.
85+
- `predicate_result(const bool value)` - initializes the object with the given boolean value.
86+
- If the value is `true`, initializes the object with `eval::ok`.
87+
- If the value is `false`, initializes the object with `eval::not_ok`.
88+
- *Member variables*:
89+
- `value: eval` - the evaluation result.
90+
- *Operators*:
91+
- `operator bool()` - returns `true` if the result is `eval::ok`, `false` otherwise.
92+
- `operator==(const eval& value) const` - returns `true` if the result's value is equal to the given value.
93+
- `operator=(const bool value)` - initializes the object with the given boolean value similarly to the boolean constructor.
94+
7195
- `predecessors_descriptor`
7296
- *Description*: A structure that holds a collection of predecessors for a set of vertices.
7397
- *Type definitions*:
@@ -93,18 +117,6 @@ This section covers the specific types and type traits used for the algorithm im
93117
> [!NOTE]
94118
> All concepts listed below are defined in the `gl::type_traits` namespace
95119
96-
- `c_alg_no_return_type`
97-
- *Description*: Checks if the type `T` is `algorithm::no_return`. Used to identify algorithms that do not return a value.
98-
- *Template parameters*:
99-
- `T` - the type to check.
100-
- *Equivalent to*: `std::same_as<T, algorithm::no_return>`
101-
102-
- `c_alg_return_graph_type`
103-
- *Description*: Checks if the type `T` is a valid return type for graph algorithms, i.e., either a graph type or `no_return`.
104-
- *Template parameters*:
105-
- `T` - the type to check.
106-
- *Equivalent to*: `c_graph<T> or c_alg_no_return_type<T>`
107-
108120
- `c_empty_callback`
109121
- *Description*: Checks if a callback type is `algorithm::empty_callback`. Used to determine when no callback is needed for an algorithm.
110122
- *Template parameters*:
@@ -169,7 +181,7 @@ This section covers the specific types and type traits used for the algorithm im
169181
- *Description*: Performs an iterative depth-first search (DFS) on the specified graph and conditionally returns a `predecessors_descriptor` instance.
170182

171183
- *Template parameters*:
172-
- `AlgReturnType: type_traits::c_alg_return_type` (default = `algorithm::default_return`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::default_return` or `algorithm::no_return`).
184+
- `ResultDiscriminator: result_discriminator` (default = `algorithm::ret`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::ret` or `algorithm::no_return`).
173185
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
174186
- `PreVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
175187
- `PostVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
@@ -181,7 +193,7 @@ This section covers the specific types and type traits used for the algorithm im
181193
- `post_visit: const PostVisitCallback&` (default = `{}`) - The callback function to be called after visiting a vertex.
182194

183195
- *Return type*:
184-
- `impl::alg_return_type<AlgReturnType, predecessors_descriptor>` - If `AlgReturnType` is `algorithm::no_return` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
196+
- `impl::alg_return_type<ResultDiscriminator, predecessors_descriptor>` - If `ResultDiscriminator` is `algorithm::noret` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
185197

186198
- *Defined in*: [gl/algorithm/depth_first_search.hpp](/include/gl/algorithm/depth_first_search.hpp)
187199

@@ -198,7 +210,7 @@ This section covers the specific types and type traits used for the algorithm im
198210
- *Description*: Performs an breadth-first search (BFS) on the specified graph and conditionally returns a `predecessors_descriptor` instance.
199211

200212
- *Template parameters*:
201-
- `AlgReturnType: type_traits::c_alg_return_type` (default = `algorithm::default_return`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::default_return` or `algorithm::no_return`).
213+
- `ResultDiscriminator: result_discriminator` (default = `algorithm::ret`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::ret` or `algorithm::no_return`).
202214
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
203215
- `PreVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
204216
- `PostVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
@@ -210,7 +222,7 @@ This section covers the specific types and type traits used for the algorithm im
210222
- `post_visit: const PostVisitCallback&` (default = `{}`) - The callback function to be called after visiting a vertex.
211223

212224
- *Return type*:
213-
- `impl::alg_return_type<AlgReturnType, predecessors_descriptor>` - If `AlgReturnType` is `algorithm::no_return` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
225+
- `impl::alg_return_type<ResultDiscriminator, predecessors_descriptor>` - If `ResultDiscriminator` is `algorithm::noret` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
214226

215227
- *Defined in*: [gl/algorithm/breadth_first_search.hpp](/include/gl/algorithm/breadth_first_search.hpp)
216228

@@ -401,7 +413,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
401413
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
402414
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
403415
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
404-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
416+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
405417
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
406418
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
407419

@@ -423,7 +435,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
423435
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
424436
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
425437
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
426-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
438+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
427439
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
428440
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
429441

@@ -452,7 +464,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
452464
- `InitQueueRangeType: type_traits::c_sized_range_of<algorithm::vertex_info>` (default = `std::vector<algorithm::vertex_info>`) - The type of the `vertex_info` range which will be inserted into the queue at the beginning of the algorithm.
453465
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
454466
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
455-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
467+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
456468
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
457469
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
458470

@@ -483,7 +495,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
483495
- `InitQueueRangeType: type_traits::c_sized_range_of<algorithm::vertex_info>` (default = `std::vector<algorithm::vertex_info>`) - The type of the `vertex_info` range which will be inserted into the queue at the beginning of the algorithm.
484496
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
485497
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
486-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
498+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
487499
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
488500
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
489501

include/gl/algorithm/types.hpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace gl {
1212

1313
namespace algorithm {
1414

15-
// TODO: align docs
1615
enum class result_discriminator : bool { ret = true, noret = false };
1716
using enum result_discriminator;
1817

@@ -36,6 +35,30 @@ struct edge_info {
3635
types::id_type source_id;
3736
};
3837

38+
struct predicate_result {
39+
enum class eval : std::uint8_t { ok, not_ok, unknown };
40+
using enum eval;
41+
42+
constexpr predicate_result(const eval value) : value(value) {}
43+
44+
constexpr predicate_result(const bool value) : value(value ? eval::ok : eval::not_ok) {}
45+
46+
constexpr predicate_result& operator=(const bool value) {
47+
this->value = value ? eval::ok : eval::not_ok;
48+
return *this;
49+
}
50+
51+
[[nodiscard]] constexpr operator bool() const {
52+
return this->value == eval::ok;
53+
}
54+
55+
[[nodiscard]] constexpr bool operator==(const eval value) const {
56+
return this->value == value;
57+
}
58+
59+
eval value;
60+
};
61+
3962
struct predecessors_descriptor {
4063
using predecessor_type = std::optional<types::id_type>;
4164

@@ -68,30 +91,6 @@ struct predecessors_descriptor {
6891
std::vector<predecessor_type> predecessors;
6992
};
7093

71-
struct predicate_result {
72-
enum class eval : std::uint8_t { ok, not_ok, unknown };
73-
using enum eval;
74-
75-
constexpr predicate_result(const eval value) : value(value) {}
76-
77-
constexpr predicate_result(const bool value) : value(value ? eval::ok : eval::not_ok) {}
78-
79-
constexpr predicate_result& operator=(const bool value) {
80-
this->value = value ? eval::ok : eval::not_ok;
81-
return *this;
82-
}
83-
84-
[[nodiscard]] constexpr operator bool() const {
85-
return this->value == eval::ok;
86-
}
87-
88-
[[nodiscard]] constexpr bool operator==(const eval value) const {
89-
return this->value == value;
90-
}
91-
92-
eval value;
93-
};
94-
9594
} // namespace algorithm
9695

9796
namespace type_traits {

0 commit comments

Comments
 (0)