diff --git a/src/Library/AttackLibrary.hpp b/src/Library/AttackLibrary.hpp index f506fd4..eb76230 100644 --- a/src/Library/AttackLibrary.hpp +++ b/src/Library/AttackLibrary.hpp @@ -11,7 +11,8 @@ namespace CreatureLib::Library { std::unordered_map _attacks; public: - AttackLibrary() = default; + AttackLibrary(size_t initialCapacity = 32) + : _attacks(std::unordered_map(initialCapacity)){}; ~AttackLibrary() { for (auto attack : _attacks) { diff --git a/src/Library/GrowthRates/GrowthRateLibrary.hpp b/src/Library/GrowthRates/GrowthRateLibrary.hpp index 2a7a008..1d4b6c6 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.hpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.hpp @@ -12,8 +12,11 @@ namespace CreatureLib::Library { std::unordered_map _growthRates; public: - ~GrowthRateLibrary(){ - for (auto gr: _growthRates){ + GrowthRateLibrary(size_t initialCapacity = 10) + : _growthRates(std::unordered_map(initialCapacity)) {} + + ~GrowthRateLibrary() { + for (auto gr : _growthRates) { delete gr.second; } } diff --git a/src/Library/ItemLibrary.hpp b/src/Library/ItemLibrary.hpp index d411de5..5b530e5 100644 --- a/src/Library/ItemLibrary.hpp +++ b/src/Library/ItemLibrary.hpp @@ -11,7 +11,8 @@ namespace CreatureLib::Library { std::unordered_map _items; public: - ItemLibrary() = default; + ItemLibrary(size_t initialCapacity = 32) + : _items(std::unordered_map(initialCapacity)){}; ~ItemLibrary() { _items.clear(); } [[nodiscard]] const Item* GetItem(const std::string& name) const; diff --git a/src/Library/SpeciesLibrary.hpp b/src/Library/SpeciesLibrary.hpp index 186cf4e..1658338 100644 --- a/src/Library/SpeciesLibrary.hpp +++ b/src/Library/SpeciesLibrary.hpp @@ -11,7 +11,8 @@ namespace CreatureLib::Library { std::unordered_map _species; public: - SpeciesLibrary() = default; + SpeciesLibrary(size_t initialCapacity = 32) + : _species(std::unordered_map(initialCapacity)){}; ~SpeciesLibrary() { for (auto s : _species) diff --git a/src/Library/TypeLibrary.hpp b/src/Library/TypeLibrary.hpp index 22758a2..f5aaa14 100644 --- a/src/Library/TypeLibrary.hpp +++ b/src/Library/TypeLibrary.hpp @@ -10,6 +10,8 @@ namespace CreatureLib::Library { std::vector> _effectiveness; public: + TypeLibrary(size_t initialCapacity = 20) : _types(std::unordered_map(initialCapacity)) {} + uint8_t GetTypeId(const std::string& s) const; float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const; float GetEffectiveness(uint8_t attacking, const std::vector& defensive) const;