aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/HistoryMap.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-09-10 00:04:30 +0200
committer GitHub <noreply@github.com>2024-09-10 00:04:30 +0200
commit7a9206e3869fbb659d296b854c90f5c81755a5ca (patch)
tree1e00781e634cbb7ea6f31343f6751f7755bd53ef /src/openvic-simulation/history/HistoryMap.hpp
parent79dbf71dd23623059ea9eabd87956f93604be1ed (diff)
parentd67cd2d08fe2859809e35b93f5a8358c48a3705e (diff)
Merge pull request #195 from OpenVicProject/ranking
Ranking System
Diffstat (limited to 'src/openvic-simulation/history/HistoryMap.hpp')
-rw-r--r--src/openvic-simulation/history/HistoryMap.hpp27
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;
- }
};
}