mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Change paths cache storage stype
It's about 10% faster with a map of sets vs. a set of pairs.
This commit is contained in:
@@ -117,12 +117,24 @@ std::string describeEdgeType(EdgeType edgeType) {
|
||||
|
||||
bool PathsCache::IsPathCached(const vertex_t& fromVertex,
|
||||
const vertex_t& toVertex) const {
|
||||
return pathsCache_.count({fromVertex, toVertex});
|
||||
const auto descendents = pathsCache_.find(fromVertex);
|
||||
|
||||
if (descendents == pathsCache_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return descendents->second.count(toVertex);
|
||||
}
|
||||
|
||||
void PathsCache::CachePath(const vertex_t& fromVertex,
|
||||
const vertex_t& toVertex) {
|
||||
pathsCache_.insert({fromVertex, toVertex});
|
||||
auto descendents = pathsCache_.find(fromVertex);
|
||||
|
||||
if (descendents == pathsCache_.end()) {
|
||||
pathsCache_.emplace(fromVertex, std::unordered_set<vertex_t>({toVertex}));
|
||||
} else {
|
||||
descendents->second.insert(toVertex);
|
||||
}
|
||||
}
|
||||
|
||||
size_t PluginGraph::CountVertices() const {
|
||||
|
||||
@@ -39,19 +39,6 @@
|
||||
#include "api/sorting/plugin_sorting_data.h"
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
|
||||
namespace std {
|
||||
template<typename A, typename B>
|
||||
struct hash<pair<A, B>> {
|
||||
size_t operator()(const pair<A, B>& pair) const {
|
||||
size_t seed = 0;
|
||||
boost::hash_combine(seed, pair.first);
|
||||
boost::hash_combine(seed, pair.second);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace loot {
|
||||
typedef boost::adjacency_list<boost::listS,
|
||||
boost::listS,
|
||||
@@ -71,7 +58,7 @@ public:
|
||||
void CachePath(const vertex_t& fromVertex, const vertex_t& toVertex);
|
||||
|
||||
private:
|
||||
std::unordered_set<std::pair<vertex_t, vertex_t>> pathsCache_;
|
||||
std::unordered_map<vertex_t, std::unordered_set<vertex_t>> pathsCache_;
|
||||
};
|
||||
|
||||
class PluginGraph {
|
||||
|
||||
Reference in New Issue
Block a user