aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/types/IdentifierRegistry.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-26 00:25:12 +0200
committer Hop311 <hop3114@gmail.com>2023-09-03 12:53:52 +0200
commit366f1b3941315641bdcb0ee98465b4d2134eee86 (patch)
treeebb1e95b5e874c6eab09f19a323d721fd1fdac1b /src/openvic/types/IdentifierRegistry.hpp
parentefa88c722fcb6c8fea7a86e1b3b8a83f1f59eb31 (diff)
Followup big dataloader commit
Diffstat (limited to 'src/openvic/types/IdentifierRegistry.hpp')
-rw-r--r--src/openvic/types/IdentifierRegistry.hpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/openvic/types/IdentifierRegistry.hpp b/src/openvic/types/IdentifierRegistry.hpp
index e5ac94b..989db01 100644
--- a/src/openvic/types/IdentifierRegistry.hpp
+++ b/src/openvic/types/IdentifierRegistry.hpp
@@ -64,7 +64,9 @@ namespace OpenVic {
HasIdentifierAndColour& operator=(HasIdentifierAndColour&&) = delete;
};
- using distribution_t = std::unordered_map<HasIdentifierAndColour const*, float>;
+ using distribution_t = std::map<HasIdentifierAndColour const*, float>;
+
+ distribution_t::value_type get_largest_item(distribution_t const& dist);
/*
* Template for a list of objects with unique string identifiers that can
@@ -102,7 +104,7 @@ namespace OpenVic {
Logger::error("Failed to lock ", name, " registry - already locked!");
} else {
locked = true;
- if (log) Logger::info("Locked ", name, " registry after registering ", get_item_count(), " items");
+ if (log) Logger::info("Locked ", name, " registry after registering ", size(), " items");
}
}
bool is_locked() const {
@@ -113,9 +115,19 @@ namespace OpenVic {
items.clear();
locked = false;
}
- size_t get_item_count() const {
+ size_t size() const {
return items.size();
}
+ bool empty() const {
+ return items.empty();
+ }
+ void reserve(size_t size) {
+ if (locked) {
+ Logger::error("Failed to reserve space for ", size, " items in ", name, " registry - already locked!");
+ } else {
+ items.reserve(size);
+ }
+ }
T* get_item_by_identifier(const std::string_view identifier) {
const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier);
if (it != identifier_index_map.end()) return &items[it->second];