Commit 0efd32c4 authored by Alex Snast's avatar Alex Snast Committed by Facebook GitHub Bot

add heterogeneous access support to EvictingCacheMap

Summary:
Heterogeneous access is described [here](https://github.com/facebook/folly/blob/master/folly/container/F14.md#heterogeneous-key-type-with-transparent-hash-and-equality) and this diff adds this capability to EvictingCacheMap.

See `HeterogeneousAccess` test from EvictingCacheMapTest.cpp for usage example.

Reviewed By: yfeldblum

Differential Revision: D26879601

fbshipit-source-id: 027352f2daa6773ab981b924732e1056550f6ea2
parent 0fbe9c5b
This diff is collapsed.
......@@ -713,3 +713,54 @@ TEST(EvictingCacheMap, IteratorConversion) {
EXPECT_FALSE((std::is_convertible<cri, ri>::value));
EXPECT_TRUE((std::is_convertible<cri, cri>::value));
}
TEST(EvictingCacheMap, HeterogeneousAccess) {
constexpr std::array pieces{
std::pair{"one"_sp, 1},
std::pair{"two"_sp, 2},
std::pair{"three"_sp, 3},
};
constexpr std::array charstars{
std::pair{"four", 4},
std::pair{"five", 5},
std::pair{"six", 6},
std::pair{"seven", 7},
};
EvictingCacheMap<std::string, int> map(0);
for (auto&& [key, value] : pieces) {
auto [_, inserted] = map.insert(key, value);
EXPECT_TRUE(inserted);
}
for (auto&& [key, value] : charstars) {
map.set(key, value);
}
for (auto&& [key, value] : pieces) {
auto exists = map.exists(key);
EXPECT_TRUE(exists);
auto iter = map.find(key);
EXPECT_TRUE(iter != map.end());
EXPECT_EQ(iter->second, value);
iter = map.findWithoutPromotion(key);
EXPECT_TRUE(iter != map.end());
EXPECT_EQ(iter->second, value);
}
for (auto&& [key, value] : charstars) {
auto result = map.get(key);
EXPECT_EQ(result, value);
result = map.getWithoutPromotion(key);
EXPECT_EQ(result, value);
}
for (auto&& [key, _] : pieces) {
auto erased = map.erase(key);
EXPECT_TRUE(erased);
erased = map.erase(key);
EXPECT_FALSE(erased);
}
for (auto&& [key, _] : charstars) {
map.erase(map.findWithoutPromotion(key));
}
EXPECT_TRUE(map.empty());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment