[core] Switch to ankerl::unordered_dense

Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
x7z4w
2025-11-24 17:34:56 +00:00
parent 03132c6877
commit ef6522ed28
282 changed files with 4386 additions and 1456 deletions

View File

@@ -5,7 +5,8 @@
#include <map>
#include <string>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
using namespace base;
using namespace std;

View File

@@ -4,7 +4,8 @@
#include <list>
#include <set>
#include <unordered_map>
#include "3party/ankerl/unordered_dense.h"
#ifdef __clang__
#pragma clang diagnostic push
@@ -24,7 +25,7 @@ public:
FifoCacheTest(size_t capacity, typename FifoCache<Key, Value>::Loader const & loader) : m_cache(capacity, loader) {}
Value const & GetValue(Key const & key) { return m_cache.GetValue(key); }
unordered_map<Key, Value> const & GetMap() const { return m_cache.m_map; }
ankerl::unordered_dense::map<Key, Value> const & GetMap() const { return m_cache.m_map; }
boost::circular_buffer<Key> const & GetFifo() const { return m_cache.m_fifo; }
bool IsValid() const
@@ -67,7 +68,7 @@ UNIT_TEST(FifoCache)
TEST_EQUAL(cache.GetValue(2), 2, ());
TEST(cache.IsValid(), ());
{
unordered_map<Key, Value> expectedMap({{1 /* key */, 1 /* value */}, {2, 2}, {3, 3}});
ankerl::unordered_dense::map<Key, Value> expectedMap({{1 /* key */, 1 /* value */}, {2, 2}, {3, 3}});
TEST_EQUAL(cache.GetMap(), expectedMap, ());
list<Key> expectedList({2, 3, 1});
boost::circular_buffer<Key> expectedCB(expectedList.cbegin(), expectedList.cend());
@@ -77,7 +78,7 @@ UNIT_TEST(FifoCache)
TEST_EQUAL(cache.GetValue(7), 7, ());
TEST(cache.IsValid(), ());
{
unordered_map<Key, Value> expectedMap({{7 /* key */, 7 /* value */}, {2, 2}, {3, 3}});
ankerl::unordered_dense::map<Key, Value> expectedMap({{7 /* key */, 7 /* value */}, {2, 2}, {3, 3}});
TEST_EQUAL(cache.GetMap(), expectedMap, ());
list<Key> expectedList({7, 2, 3});
boost::circular_buffer<Key> expectedCB(expectedList.cbegin(), expectedList.cend());

View File

@@ -41,7 +41,7 @@ public:
size_t GetAge() const { return m_keyAge.m_age; }
std::map<size_t, Key> const & GetAgeToKey() const { return m_keyAge.m_ageToKey; }
std::unordered_map<Key, size_t> const & GetKeyToAge() const { return m_keyAge.m_keyToAge; }
ankerl::unordered_dense::map<Key, size_t> const & GetKeyToAge() const { return m_keyAge.m_keyToAge; }
private:
typename LruCache<Key, Value>::KeyAge m_keyAge;
@@ -49,7 +49,8 @@ private:
template <typename Key, typename Value>
void TestAge(LruCacheKeyAgeTest<Key, Value> const & keyAge, size_t expectedAge,
std::map<size_t, Key> const & expectedAgeToKey, std::unordered_map<Key, size_t> const & expectedKeyToAge)
std::map<size_t, Key> const & expectedAgeToKey,
ankerl::unordered_dense::map<Key, size_t> const & expectedKeyToAge)
{
TEST(keyAge.IsValid(), ());
TEST_EQUAL(keyAge.GetAge(), expectedAge, ());
@@ -70,49 +71,49 @@ UNIT_TEST(LruCacheAgeTest)
age.InsertKey(10);
{
std::map<size_t, Key> const expectedAgeToKey({{1 /* age */, 10 /* key */}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{10 /* key */, 1 /* age */}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{10 /* key */, 1 /* age */}});
TestAge(age, 1 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.InsertKey(9);
{
std::map<size_t, Key> const expectedAgeToKey({{1, 10}, {2, 9}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{10, 1}, {9, 2}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{10, 1}, {9, 2}});
TestAge(age, 2 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.RemoveLru();
{
std::map<size_t, Key> const expectedAgeToKey({{2, 9}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{9, 2}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{9, 2}});
TestAge(age, 2 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.InsertKey(11);
{
std::map<size_t, Key> const expectedAgeToKey({{2, 9}, {3, 11}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{9, 2}, {11, 3}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{9, 2}, {11, 3}});
TestAge(age, 3 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.UpdateAge(9);
{
std::map<size_t, Key> const expectedAgeToKey({{4, 9}, {3, 11}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{9, 4}, {11, 3}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{9, 4}, {11, 3}});
TestAge(age, 4 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.RemoveLru();
{
std::map<size_t, Key> const expectedAgeToKey({{4, 9}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{9, 4}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{9, 4}});
TestAge(age, 4 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
age.InsertKey(12);
{
std::map<size_t, Key> const expectedAgeToKey({{4, 9}, {5, 12}});
std::unordered_map<Key, size_t> const expectedKeyToAge({{9, 4}, {12, 5}});
ankerl::unordered_dense::map<Key, size_t> const expectedKeyToAge({{9, 4}, {12, 5}});
TestAge(age, 5 /* cache age */, expectedAgeToKey, expectedKeyToAge);
}
}

View File

@@ -7,9 +7,10 @@
#include <algorithm>
#include <iterator>
#include <random>
#include <unordered_map>
#include <vector>
#include "3party/ankerl/unordered_dense.h"
namespace small_set_test
{
using namespace base;
@@ -96,7 +97,7 @@ UNIT_TEST(SmallMap_Benchmark1)
{
// 1. Init maps.
// Dataset is similar to routing::VehicleModel.
std::unordered_map<uint32_t, bool> uMap = {
ankerl::unordered_dense::map<uint32_t, bool> uMap = {
{1, true}, {2, false}, {4, false}, {6, true}, {7, true}, {8, true}, {12, false},
{15, false}, {26, true}, {30, false}, {36, false}, {43, false}, {54, false}, {57, true},
{58, true}, {65, true}, {69, true}, {90, true}, {95, false}, {119, false}, {167, true},
@@ -138,7 +139,7 @@ UNIT_TEST(SmallMap_Benchmark2)
uint32_t i = 0;
// Dataset is similar to routing::VehicleModelFactory.
unordered_map<string, shared_ptr<int>> uMap = {
ankerl::unordered_dense::map<string, shared_ptr<int>> uMap = {
{"", make_shared<int>(i++)},
{"Australia", make_shared<int>(i++)},
{"Austria", make_shared<int>(i++)},
@@ -217,7 +218,7 @@ UNIT_TEST(SmallMap_Benchmark2)
UNIT_TEST(SmallMap_Benchmark3)
{
// Dataset is similar to routing::VehicleModel.m_surfaceFactors.
std::unordered_map<int, int> uMap = {
ankerl::unordered_dense::map<int, int> uMap = {
{1, 0}, {10, 1}, {100, 2}, {1000, 3},
};

View File

@@ -7,11 +7,11 @@
#include <cmath>
#include <fstream>
#include <limits>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include <sstream>
#include "3party/ankerl/unordered_dense.h"
/// internal function in base
namespace strings
@@ -28,7 +28,7 @@ UNIT_TEST(LowerUniChar)
TEST(file.is_open(), (kFile));
size_t fCount = 0, cCount = 0;
std::unordered_map<strings::UniChar, strings::UniString> m;
ankerl::unordered_dense::map<strings::UniChar, strings::UniString> m;
std::string line;
while (file.good())
{