Maze Builder Docs 8.2.1
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
9#include <MazeBuilder/cell.h>
11
14namespace mazes
15{
16 class grid_interface;
17
22 {
23 public:
26 explicit distances(std::int32_t root_index);
27
31 int& operator[](std::int32_t index) noexcept;
32
36 const int& operator[](std::int32_t index) const noexcept;
37
41 void set(std::int32_t index, int distance) noexcept;
42
45 [[nodiscard]] bool contains(std::int32_t index) const noexcept;
46
49 [[nodiscard]] std::pair<std::int32_t, int> max() const noexcept;
50
53 void collect_keys(std::vector<std::int32_t>& indices) const noexcept;
54
60 static std::shared_ptr<distances> path_to(grid_interface* g, std::int32_t start_index,
61 std::int32_t goal_index) noexcept;
62
63 private:
64 std::unordered_map<std::int32_t, int> m_cells;
65
66 std::int32_t m_root_index;
67 }; // class distances
68} // namespace mazes
69
70#endif // DISTANCES_H
A class that manages distances associated with cells in a grid.
Definition distances.h:22
static std::shared_ptr< distances > path_to(grid_interface *g, std::int32_t start_index, std::int32_t goal_index) noexcept
Computes the shortest path to a goal cell index within a distances object.
std::pair< std::int32_t, int > max() const noexcept
Computes the maximum distance and cell index in a distances object.
const int & operator[](std::int32_t index) const noexcept
Accesses the value associated with a given cell index.
bool contains(std::int32_t index) const noexcept
Checks if a given cell index is contained in the distances object.
distances(std::int32_t root_index)
Constructor that initializes the distances object with a given root index.
void set(std::int32_t index, int distance) noexcept
Sets the distance of a cell by index.
void collect_keys(std::vector< std::int32_t > &indices) const noexcept
Collects all cell indices stored in the distances object.
int & operator[](std::int32_t index) noexcept
Overloaded operator to access the distance of a cell by index.
Interface for the grid class.
Definition grid_interface.h:20