Compare commits

..

2 Commits

3 changed files with 22 additions and 20 deletions

View File

@@ -13,6 +13,8 @@
#include "ContainerOptions.hpp" #include "ContainerOptions.hpp"
#include "Hashmap.hpp" #include "Hashmap.hpp"
#include "Corrade/Containers/Array.h"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath> #include <cmath>
@@ -33,14 +35,14 @@ template <Concepts::Hashable AKey, Concepts::Hashable BKey, typename Value,
class DualkeyMap { class DualkeyMap {
public: public:
// Return Types // Return Types
template <typename OppositeKey, std::size_t keyCount> template <typename OppositeKey>
requires Concepts::Either<OppositeKey, AKey, BKey> requires Concepts::Either<OppositeKey, AKey, BKey>
struct MultiQueryResult { struct MultiQueryResult {
// Having to use pointers here over references was not fun // Having to use pointers here over references was not fun
// but it was for greater good // but it was for greater good
const OppositeKey *oppositeKey; const OppositeKey *oppositeKey;
Corrade::Containers::Array<Value *> valueQueryResults;
std::size_t howManyFound = 1; std::size_t howManyFound = 1;
std::array<Value *, keyCount> valueQueryResults;
}; };
using QueryResult = using QueryResult =
@@ -209,13 +211,12 @@ public:
std::size_t keyCount> std::size_t keyCount>
requires Concepts::Either<Key, AKey, BKey> requires Concepts::Either<Key, AKey, BKey>
[[nodiscard("Discarding a very expensive query!")]] [[nodiscard("Discarding a very expensive query!")]]
std::vector<MultiQueryResult<OppositeKey, keyCount>> std::vector<MultiQueryResult<OppositeKey>>
QueryWithAll(const Key (&keys)[keyCount]) { QueryWithAll(const Key (&keys)[keyCount]) {
std::vector<MultiQueryResult<OppositeKey, keyCount>> queryResult = std::vector<MultiQueryResult<OppositeKey>> queryResult =
queryWithMany<Key>(keys); queryWithMany<Key>(keys);
std::erase_if( std::erase_if(queryResult,
queryResult, [](const MultiQueryResult<OppositeKey> &queryRecord) {
[](const MultiQueryResult<OppositeKey, keyCount> &queryRecord) {
return queryRecord.howManyFound != keyCount; return queryRecord.howManyFound != keyCount;
}); });
return queryResult; return queryResult;
@@ -271,7 +272,7 @@ private:
template <typename Key, template <typename Key,
typename OppositeKey = Concepts::OppositeOf<Key, AKey, BKey>, typename OppositeKey = Concepts::OppositeOf<Key, AKey, BKey>,
std::size_t keyCount> std::size_t keyCount>
inline std::vector<MultiQueryResult<OppositeKey, keyCount>> inline std::vector<MultiQueryResult<OppositeKey>>
queryWithMany(const Key (&keys)[keyCount]) { queryWithMany(const Key (&keys)[keyCount]) {
constexpr bool searchingInFirstKey = std::is_same_v<Key, AKey>; constexpr bool searchingInFirstKey = std::is_same_v<Key, AKey>;
@@ -301,7 +302,7 @@ private:
Key *keyToCompare; Key *keyToCompare;
OppositeKey *oppositeKey; OppositeKey *oppositeKey;
Containers::Hashmap<OppositeKey, MultiQueryResult<OppositeKey, keyCount>, Containers::Hashmap<OppositeKey, MultiQueryResult<OppositeKey>,
{8.0f, 0.01f, 2.5f, 2048, 8}> // Aggressive hashmap :o {8.0f, 0.01f, 2.5f, 2048, 8}> // Aggressive hashmap :o
queryResults; queryResults;
@@ -334,8 +335,9 @@ private:
} }
queryResults queryResults
.Insert(*oppositeKey, .Insert(
MultiQueryResult<OppositeKey, keyCount>(oppositeKey)) *oppositeKey,
{oppositeKey, Corrade::Containers::Array<Value *>{keyCount}})
.valueQueryResults[index] = &hash->value; .valueQueryResults[index] = &hash->value;
} }
} }

View File

@@ -160,8 +160,8 @@ private:
// Repopulate and cleanup // Repopulate and cleanup
for (bucket &entry : oldStorage) { for (bucket &entry : oldStorage) {
for (const hashStorage &hash : entry) { for (hashStorage &hash : entry) {
Insert(hash.key, hash.value); Insert(std::move(hash.key), std::move(hash.value));
} }
entry.clear(); entry.clear();

View File

@@ -26,12 +26,12 @@ public:
LogLevel severity = LogLevel::Info, bool assertion = true); LogLevel severity = LogLevel::Info, bool assertion = true);
template <class... Args> template <class... Args>
static void LogFormatted(const char *format, static void LogFormatted(const char *format, const char *position,
Corrade::Containers::StringView position,
LogLevel severity, const Args &...args) { LogLevel severity, const Args &...args) {
Corrade::Containers::String formatted = static Corrade::Containers::String output{Corrade::ValueInit, 4096};
Corrade::Utility::format(format, args...); std::size_t size = Corrade::Utility::formatInto(output, format, args...);
Log(formatted, position, severity); Log(Corrade::Containers::StringView{output.begin(), size}, position,
severity);
} }
private: private: