aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp4
-rw-r--r--src/openvic-simulation/history/HistoryMap.hpp27
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp6
3 files changed, 22 insertions, 15 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 145d26b..04f6292 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -191,6 +191,10 @@ void CountryHistoryManager::reserve_more_country_histories(size_t size) {
}
void CountryHistoryManager::lock_country_histories() {
+ for (auto [country, history_map] : mutable_iterator(country_histories)) {
+ history_map.sort_entries();
+ }
+
Logger::info("Locked country history registry after registering ", country_histories.size(), " items");
locked = true;
}
diff --git a/src/openvic-simulation/history/HistoryMap.hpp b/src/openvic-simulation/history/HistoryMap.hpp
index 1d6ec03..b062b0f 100644
--- a/src/openvic-simulation/history/HistoryMap.hpp
+++ b/src/openvic-simulation/history/HistoryMap.hpp
@@ -104,6 +104,20 @@ namespace OpenVic {
}
public:
+ void sort_entries() {
+ std::vector<Date> keys;
+ keys.reserve(entries.size());
+ for (typename decltype(entries)::value_type const& entry : entries) {
+ keys.push_back(entry.first);
+ }
+ std::sort(keys.begin(), keys.end());
+ ordered_map<Date, std::unique_ptr<entry_type>> new_entries;
+ for (Date const& key : keys) {
+ new_entries.emplace(key, std::move(entries[key]));
+ }
+ entries = std::move(new_entries);
+ }
+
/* Returns history entry at specific date, if date doesn't have an entry returns nullptr. */
entry_type const* get_entry(Date date) const {
typename decltype(entries)::const_iterator it = entries.find(date);
@@ -112,18 +126,5 @@ namespace OpenVic {
}
return nullptr;
}
- /* Returns history entries up to date as an ordered list of entries. */
- std::vector<entry_type const*> get_entries_up_to(Date end) const {
- std::vector<entry_type const*> ret;
- for (typename decltype(entries)::value_type const& entry : entries) {
- if (entry.first <= end) {
- ret.push_back(entry.second.get());
- }
- }
- std::sort(ret.begin(), ret.end(), [](entry_type const* lhs, entry_type const* rhs) -> bool {
- return lhs->get_date() < rhs->get_date();
- });
- return ret;
- }
};
}
diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp
index ca0bf4e..ef8793b 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -157,8 +157,10 @@ void ProvinceHistoryManager::lock_province_histories(MapDefinition const& map_de
std::vector<ProvinceDefinition> const& provinces = map_definition.get_province_definitions();
std::vector<bool> province_checklist(provinces.size());
- for (decltype(province_histories)::value_type const& entry : province_histories) {
- province_checklist[entry.first->get_index() - 1] = true;
+ for (auto [province, history_map] : mutable_iterator(province_histories)) {
+ province_checklist[province->get_index() - 1] = true;
+
+ history_map.sort_entries();
}
size_t missing = 0;