*: combine dense hash map and identity when the key is a hashed string already

This commit is contained in:
Michele Caini
2021-11-30 09:43:47 +01:00
parent 55661883d9
commit 8de568c2fc
4 changed files with 10 additions and 6 deletions
+1
View File
@@ -4,6 +4,7 @@
* add examples (and credits) from @alanjfs :)
WIP:
* use identity with dense hash map: cache (review api with hashed string), registry
* fast-contains for sparse sets (low prio but nice-to-have)
* runtime components (registry), runtime events (dispatcher/emitter), runtime context variables ...
* runtime_view/registry, remove reference to basic_sparse_set<E>
+2 -1
View File
@@ -9,6 +9,7 @@
#include "../container/dense_hash_map.hpp"
#include "../core/type_info.hpp"
#include "../core/type_traits.hpp"
#include "../core/utility.hpp"
#include "fwd.hpp"
#include "helper.hpp"
@@ -477,7 +478,7 @@ public:
}
private:
dense_hash_map<id_type, std::vector<std::pair<std::size_t, bool>>> dependencies;
dense_hash_map<id_type, std::vector<std::pair<std::size_t, bool>>, identity> dependencies;
std::vector<vertex_data> vertices;
};
+3 -2
View File
@@ -10,6 +10,7 @@
#include "../container/dense_hash_map.hpp"
#include "../core/fwd.hpp"
#include "../core/type_info.hpp"
#include "../core/utility.hpp"
#include "sigh.hpp"
namespace entt {
@@ -85,7 +86,7 @@ class dispatcher {
template<typename Event>
[[nodiscard]] pool_handler<Event> &assure() {
if(auto &&ptr = pools[type_id<Event>().hash()]; !ptr) {
if(auto &&ptr = pools[type_hash<Event>::value()]; !ptr) {
auto *cpool = new pool_handler<Event>{};
ptr.reset(cpool);
return *cpool;
@@ -255,7 +256,7 @@ public:
}
private:
dense_hash_map<id_type, std::unique_ptr<basic_pool>> pools;
dense_hash_map<id_type, std::unique_ptr<basic_pool>, identity> pools;
};
} // namespace entt
+4 -3
View File
@@ -12,6 +12,7 @@
#include "../container/dense_hash_map.hpp"
#include "../core/fwd.hpp"
#include "../core/type_info.hpp"
#include "../core/utility.hpp"
namespace entt {
@@ -120,7 +121,7 @@ class emitter {
template<typename Event>
[[nodiscard]] pool_handler<Event> *assure() {
if(auto &&ptr = pools[type_id<Event>().hash()]; !ptr) {
if(auto &&ptr = pools[type_hash<Event>::value()]; !ptr) {
auto *cpool = new pool_handler<Event>{};
ptr.reset(cpool);
return cpool;
@@ -131,7 +132,7 @@ class emitter {
template<typename Event>
[[nodiscard]] const pool_handler<Event> *assure() const {
const auto it = pools.find(type_id<Event>().hash());
const auto it = pools.find(type_hash<Event>::value());
return (it == pools.cend()) ? nullptr : static_cast<const pool_handler<Event> *>(it->second.get());
}
@@ -307,7 +308,7 @@ public:
}
private:
dense_hash_map<id_type, std::unique_ptr<basic_pool>> pools{};
dense_hash_map<id_type, std::unique_ptr<basic_pool>, identity> pools{};
};
} // namespace entt