Maze Builder Docs 6.7.5
Loading...
Searching...
No Matches
distances.h
Go to the documentation of this file.
1#ifndef DISTANCES_H
2#define DISTANCES_H
3
4#include <cstdint>
5#include <memory>
6#include <unordered_map>
7#include <vector>
8
9namespace mazes {
10
11class grid_interface;
12
17class distances {
18
19public:
20
23 explicit distances(int32_t root_index);
24
28 int& operator[](int32_t index) noexcept;
29
33 const int& operator[](int32_t index) const noexcept;
34
37 void set(int32_t index, int distance) noexcept;
38
41 bool contains(int32_t index) const noexcept;
42
47 std::shared_ptr<distances> path_to(std::unique_ptr<grid_interface> const& g, int32_t goal_index) const noexcept;
48
51 std::pair<int32_t, int> max() const noexcept;
52
55 void collect_keys(std::vector<int32_t>& indices) const noexcept;
56
57private:
58
59 std::unordered_map<int32_t, int> m_cells;
60
61 int32_t m_root_index;
62}; // class distances
63
64} // namespace mazes
65
66#endif // DISTANCES_H
A class that manages distances associated with cells in a grid.
Definition distances.h:17
void set(int32_t index, int distance) noexcept
Sets the distance of a cell by index.
std::pair< int32_t, int > max() const noexcept
Computes the maximum distance and cell index in a distances object.
distances(int32_t root_index)
Constructor that initializes the distances object with a given root index.
int & operator[](int32_t index) noexcept
Overloaded operator to access the distance of a cell by index.
std::shared_ptr< distances > path_to(std::unique_ptr< grid_interface > const &g, int32_t goal_index) const noexcept
Computes the shortest path to a goal cell index within a distances object.
bool contains(int32_t index) const noexcept
Checks if a given cell index is contained in the distances object.
const int & operator[](int32_t index) const noexcept
Accesses the value associated with a given cell index.
void collect_keys(std::vector< int32_t > &indices) const noexcept
Collects all cell indices stored in the distances object.
Namespace for the maze builder.
Definition algo_interface.h:9