Skip to content

Commit

Permalink
Map updates
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Oct 18, 2024
1 parent 68ae037 commit 18ca13f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Cache
using Lock = std::mutex;
using Locker = std::scoped_lock<Lock>;

mutable Lock _lock;
ankerl::unordered_dense::map<RE::FormID, std::string> _formIDToEditorIDMap;
mutable Lock _lock;
Map<RE::FormID, std::string> _formIDToEditorIDMap;
};
}
22 changes: 17 additions & 5 deletions src/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ namespace ini = clib_util::ini;
using namespace std::literals;
using namespace clib_util::singleton;

template <class K, class D>
using Map = ankerl::unordered_dense::map<K, D>;

struct string_hash
{
using is_transparent = void; // enable heterogeneous overloads
using is_avalanching = void; // mark class as high quality avalanching hash

[[nodiscard]] std::uint64_t operator()(std::string_view str) const noexcept
{
return ankerl::unordered_dense::hash<std::string_view>{}(str);
}
};

template <class D>
using StringMap = ankerl::unordered_dense::map<std::string, D, string_hash, std::equal_to<>>;

namespace stl
{
using namespace SKSE::stl;
Expand Down Expand Up @@ -54,11 +71,6 @@ namespace stl
{
write_vfunc<F, 0, T>();
}

inline std::string as_string(std::string_view a_view)
{
return { a_view.data(), a_view.size() };
}
}

#ifdef SKYRIM_AE
Expand Down
2 changes: 1 addition & 1 deletion src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Settings::Load()

bool Settings::IsTweakInstalled(std::string_view a_tweak)
{
const auto it = settingsMap.find(stl::as_string(a_tweak));
const auto it = settingsMap.find(a_tweak);
return it != settingsMap.end() ? it->second : false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ class Settings : public ISingleton<Settings>
Tweaks tweaks{};
Experimental experimental{};

ankerl::unordered_dense::map<std::string, bool> settingsMap{};
StringMap<bool> settingsMap{};
};

0 comments on commit 18ca13f

Please sign in to comment.