diff options
author | hop311 <hop3114@gmail.com> | 2024-09-07 00:07:27 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-08 18:24:57 +0200 |
commit | 16349d6cad05497f983b1da123b6284ecfddd638 (patch) | |
tree | b22020c1221adc6633599a1ad53bf73bb62db0ad /src/openvic-simulation/history/HistoryMap.hpp | |
parent | b5407c8794c4626d010bd0856a146095daa1042d (diff) |
Calculate country industrial power (states still need factory data)
Diffstat (limited to 'src/openvic-simulation/history/HistoryMap.hpp')
-rw-r--r-- | src/openvic-simulation/history/HistoryMap.hpp | 27 |
1 files changed, 14 insertions, 13 deletions
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; - } }; } |