-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport_catalogue.h
82 lines (54 loc) · 2.85 KB
/
transport_catalogue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include <memory>
#include <utility>
#include <string>
#include <deque>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <iomanip>
#include "domain.h"
struct Hasher {
size_t operator()(const std::pair<std::shared_ptr<Stop>, std::shared_ptr<Stop>>& stops) const {
std::hash<std::string> hasher;
size_t result = 0;
result += hasher(stops.first.get()->name) + 12 * hasher(stops.second.get()->name);
result += stops.first.get()->coord_x + 24 * stops.second.get()->coord_x;
result += stops.first.get()->coord_y + 48 * stops.second.get()->coord_y;
return result;
}
};
class TransportCatalogue {
public:
TransportCatalogue() = default;
void AddStop(const std::vector<std::string>& words);
void AddBus(const std::vector<std::string>& words, bool is_loop);
std::shared_ptr<Bus> GetBus(const std::string& bus_name) const;
int GetDistanceBetweenTwoStops(const std::string& first_stop_name, const std::string& second_stop_name);
std::shared_ptr<std::set<std::string>> GetStopToBuses(const std::string& stop_name) const;
const std::map<std::string, std::shared_ptr<Stop>>& GetStops();
const std::map<std::string, std::shared_ptr<Bus>>& GetBuses();
const std::map<std::string, std::shared_ptr<std::set<std::string>>>& GetStopsToBuses();
const std::map<graph::VertexId, std::shared_ptr<Stop>>& GetStopIdToStops();
size_t GetStopsCount();
std::unordered_map<std::pair<std::shared_ptr<Stop>, std::shared_ptr<Stop>>, double, Hasher>& GetStopsPairToDistance();
std::shared_ptr<Stop> GetStopByName(const std::string& name);
void SetDistancesBetweenCurrentStopAndAnother(const std::string& current_stop, const std::string another_name, double distance);
private:
graph::VertexId stops_count_ = 0;
graph::VertexId buses_count_ = 0;
// stops_[название остановки] = указатель на остановку
std::map<std::string, std::shared_ptr<Stop>> stops_;
// buses_[название маршрута] = указатель на маршрут
std::map<std::string, std::shared_ptr<Bus>> buses_;
// stops_to_buses_[название остановки] = список названий маршрутов
std::map<std::string, std::shared_ptr<std::set<std::string>>> stops_to_buses_;
std::map<graph::VertexId, std::shared_ptr<Stop>> stop_id_to_stops_;
// stops_pair_to_distance_[две остановки] = расстояние между ними
std::unordered_map<std::pair<std::shared_ptr<Stop>, std::shared_ptr<Stop>>, double, Hasher> stops_pair_to_distance_;
void SetDistancesBetweenCurrentStopAndOtherOnes_(std::shared_ptr<Stop> current_stop, const std::vector<std::string>& words);
void ReadDistanceAndStopNameFromString_(std::pair<int, std::string>& distance_and_name, const std::string& line);
std::shared_ptr<Stop> GetPointerToStopByName_(const std::string& stop_name);
};