Skip to content

Commit 87241cd

Browse files
authored
YT-CPPGL-56: Replace the usage of pointers for vertex and edge storage to simple composite types [Part 3]
- Aligned the graph's adjacency storage types to store only edge IDs instead of edge pointers - Removed the `iterator_range`, `dereferencing_iterator` and `non_null_iterator` types and replaced them with standard library views - Removed the reference wrapper and optional reference wrapper type aliases - Introduced an `invalid_id` constant and aligned the vertex and edge descriptor types to use this constant for default construction - Enabled copy and move constructors and operators for both vertex and edge descriptor types - Removed the `edge_info` type used for graph MST finding
1 parent ff16472 commit 87241cd

47 files changed

Lines changed: 2128 additions & 3165 deletions

Some content is hidden

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

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ The instructions and requirements of working on the `CPP-GL` project can be foun
128128

129129
## Compiler support
130130

131-
<!--TODO: verify whether the min compiler version is correct for C++23-->
132131
| Compiler | Min version |
133132
| :-: | :-: |
134133
| GNU G++ | 14 |

docs/additional_functionality.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Additional functionality
22

33
- [Force inlining](#force-inlining)
4+
- [Ranges utility](#ranges-utility)
45

56
<br />
67

@@ -16,3 +17,44 @@ To enable the force inlining functionality you have to add the following in your
1617

1718
> [!NOTE]
1819
> Force inlining is supported only for the GNU G++ and CLang++ compilers.
20+
21+
<br />
22+
<br />
23+
24+
## Ranges utility
25+
26+
Small helpers for working with C++20 ranges.
27+
28+
> [!NOTE]
29+
> - Header: [gl/util/ranges.hpp](/include/gl/util/ranges.hpp)
30+
> - Namespace: `gl::util`
31+
32+
### View adapters
33+
34+
- **`deref_view`**
35+
- *Description*: A transform view that dereferences pointer-like elements in a range. Useful for turning a range of pointers or smart pointers into a range of references.
36+
- *Usage*: `range | gl::util::deref_view`
37+
- *Works with*: `T*`, `std::unique_ptr<T>`, `std::shared_ptr<T>`, and generally pointer-like objects supporting unary `*`.
38+
- *Return type*: A lazy transformed view whose reference type is `decltype(*p)` of the underlying elements.
39+
- *Example*:
40+
```cpp
41+
std::vector<std::unique_ptr<int>> v; /* ... */
42+
for (int& x : v | gl::util::deref_view) {
43+
// use x as an int&
44+
}
45+
```
46+
47+
### Functions
48+
49+
- **`range_size(r)`**
50+
- *Template parameters*:
51+
- `R: std::ranges::range`
52+
- *Description*: Returns the size of a range. If `R` models `std::ranges::sized_range`, it forwards to `std::ranges::size(r)` in O(1). Otherwise, it computes `std::ranges::distance(std::begin(r), std::end(r))` in O(n).
53+
- *Parameters*:
54+
- `r: R&&` – the input range.
55+
- *Return type*: Same type as produced by `std::ranges::size(r)` for sized ranges or `std::ranges::distance(...)` otherwise.
56+
- *Complexity*: O(1) for sized ranges; O(n) otherwise.
57+
- *Exceptions*: No specific exceptions; propagates iterator operations if they throw.
58+
59+
> [!CAUTION]
60+
> For non-sized, single-pass/input ranges `range_size` will consume the range when computing distance.

docs/algorithms.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ This section covers the specific types and type traits used for the algorithm im
6262
- `id: types::id_type` - the ID of the vertex.
6363
- `source_id: types::id_type` - the ID of the source vertex, typically used during algorithms.
6464

65-
- `edge_info`
66-
- *Description*: Holds information about an edge, including the edge itself and its source vertex's ID.
67-
- *Template parameters*:
68-
- `EdgeType: type_traits::c_instantiation_of<edge_descriptor>` - the type of the edge.
69-
- *Constructors*:
70-
- `vertex_info(types::id_type id)` - initializes the object with the same value for `id` and `source_id` representing a starting vertex
71-
- `vertex_info(types::id_type id, types::id_type source_id)`
72-
- *Member variables*:
73-
- `edge: types::const_ref_wrap<EdgeType>` - a constant reference wrapper for the edge.
74-
- `source_id: types::id_type` - the ID of the source vertex of the held edge.
75-
7665
- `predicate_result`
7766
- *Description*: Represents the result of a predicate evaluation.
7867
- *Type definitions*:
@@ -383,7 +372,7 @@ This section covers the specific types and type traits used for the algorithm im
383372
> - *Constructors*:
384373
> - `mst_descriptor(types::size_type n_vertices)` - Initializes an empty `edges` list with the capacity of $\text{n-vertices} - 1$ and the total weight is set to $0$.
385374
> - *Member variables*:
386-
> - `edges: std::vector<types::const_ref_wrap<edge_type>>` - A list of constant edge references representing the edges of the spanning tree.
375+
> - `edges: std::vector<edge_type>` - A list of edges of the spanning tree.
387376
> - `weight: weight_type` - The total weight of all edges of the spanning tree.
388377
389378
<br />

docs/core_util_types.md

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

docs/dev_notes.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ Here you can find the necessery information to be able to work on the project
44

55
<br />
66

7-
## Building and testing
7+
## Building and Testing
88

99
> [!NOTE]
1010
> The project uses [doctest](https://github.com/doctest/doctest) framework for unit testing, however it is already installed in the [tests/external](/tests/external/) directory, so there is no need to install it sepparately.
1111
12-
### Build the testing executable
12+
### Build the testing executables
1313

1414
```shell
15-
cmake -B build
16-
cd build
17-
make # -j <n>
15+
cmake -B build -DBUILD_TESTS=ON
16+
cmake --build build # -j<n>
1817
```
1918

20-
This will build the test executable `run` in the `<project-root>/build/tests` directory.
19+
This will build the test executables `gl` (GL module tests) and `hgl` (HGL module tests) in the `<project-root>/build/tests` directory.
2120

2221
### Run the tests
2322

2423
```shell
25-
cd build
26-
./tests/run # -ts=<test-suite-name>
24+
./build/tests/gl # -ts=<test-suite-name>
25+
./build/tests/hgl # -ts=<test-suite-name>
2726
```
2827

2928
> [!NOTE]

0 commit comments

Comments
 (0)