Maze Builder Docs 7.5.6
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{
11
12 class grid_interface;
13
19 {
20
21 public:
24 explicit distances(int32_t root_index);
25
29 int &operator[](int32_t index) noexcept;
30
34 const int &operator[](int32_t index) const noexcept;
35
38 void set(int32_t index, int distance) noexcept;
39
42 bool contains(int32_t index) const noexcept;
43
48 std::shared_ptr<distances> path_to(std::unique_ptr<grid_interface> const &g, int32_t goal_index) const noexcept;
49
52 std::pair<int32_t, int> max() const noexcept;
53
56 void collect_keys(std::vector<int32_t> &indices) const noexcept;
57
58 private:
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:19
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:6