30 using namespace folly;
45 return std::addressof(x);
49 return std::addressof(x);
62 return !(*
this == other);
69 template <
class...
Args>
71 new (p)
T(std::forward<Args>(args)...);
82 PROT_READ | PROT_WRITE,
83 MAP_PRIVATE | MAP_ANONYMOUS,
86 if (p == MAP_FAILED) {
87 throw std::bad_alloc();
93 munmap(p, n *
sizeof(
T));
97 template <
class KeyT,
class ValueT>
99 return pair<KeyT, ValueT>(
106 class Allocator = std::allocator<char>,
117 auto arr = MyArr::create(150);
118 map<KeyT, ValueT> ref;
119 for (
int i = 0;
i < 100; ++
i) {
120 auto e = createEntry<KeyT, ValueT>(
i);
121 auto ret = arr->insert(e);
122 EXPECT_EQ(!ref.count(e.first), ret.second);
125 if (ret.first == arr->end()) {
130 EXPECT_EQ(ref.find(e.first)->second, ret.first->second);
133 for (
int i = 125;
i > 0;
i -= 10) {
134 auto e = createEntry<KeyT, ValueT>(
i);
135 auto ret = arr->erase(e.first);
136 auto refRet = ref.erase(e.first);
141 for (
int i = 155;
i > 0;
i -= 10) {
142 auto e = createEntry<KeyT, ValueT>(
i);
143 auto ret = arr->insert(e);
144 auto refRet = ref.insert(e);
150 for (
const auto& e : ref) {
151 auto ret = arr->find(e.first);
152 if (ret == arr->end()) {
164 class Allocator = std::allocator<char>,
169 std::unique_ptr<ValueT>,
176 auto arr = MyArr::create(250);
177 for (
int i = 0;
i < 100;
i++) {
178 arr->insert(make_pair(
i, std::make_unique<ValueT>(
i)));
180 for (
int i = 100;
i < 150;
i++) {
183 for (
int i = 150;
i < 200;
i++) {
184 arr->emplace(
i,
new ValueT(
i), std::default_delete<ValueT>());
186 for (
int i = 0;
i < 200;
i++) {
187 auto ret = arr->find(
i);
192 TEST(Aha, InsertErase_i32_i32) {
193 testMap<int32_t, int32_t>();
194 testMap<int32_t, int32_t, MmapAllocator<char>>();
198 std::allocator<char>,
205 testNoncopyableMap<int32_t, int32_t>();
206 testNoncopyableMap<int32_t, int32_t, MmapAllocator<char>>();
210 std::allocator<char>,
218 TEST(Aha, InsertErase_i64_i32) {
219 testMap<int64_t, int32_t>();
220 testMap<int64_t, int32_t, MmapAllocator<char>>();
224 std::allocator<char>,
231 testNoncopyableMap<int64_t, int32_t>();
232 testNoncopyableMap<int64_t, int32_t, MmapAllocator<char>>();
236 std::allocator<char>,
244 TEST(Aha, InsertErase_i64_i64) {
245 testMap<int64_t, int64_t>();
246 testMap<int64_t, int64_t, MmapAllocator<char>>();
250 std::allocator<char>,
257 testNoncopyableMap<int64_t, int64_t>();
258 testNoncopyableMap<int64_t, int64_t, MmapAllocator<char>>();
262 std::allocator<char>,
270 TEST(Aha, InsertErase_i32_i64) {
271 testMap<int32_t, int64_t>();
272 testMap<int32_t, int64_t, MmapAllocator<char>>();
276 std::allocator<char>,
283 testNoncopyableMap<int32_t, int64_t>();
284 testNoncopyableMap<int32_t, int64_t, MmapAllocator<char>>();
288 std::allocator<char>,
296 TEST(Aha, InsertErase_i32_str) {
297 testMap<int32_t, string>();
298 testMap<int32_t, string, MmapAllocator<char>>();
302 std::allocator<char>,
310 TEST(Aha, InsertErase_i64_str) {
311 testMap<int64_t, string>();
312 testMap<int64_t, string, MmapAllocator<char>>();
316 std::allocator<char>,
335 return legalKey(a) && (strcmp(a, b) == 0);
338 return legalKey(a) && (a[0] !=
'\0') && (a[0] == b);
350 result +=
static_cast<size_t>(*(a++));
355 return static_cast<size_t>(
a);
359 for (
const auto&
ch : a) {
360 result +=
static_cast<size_t>(
ch);
369 return strndup(&a, 1);
395 char* f_char = strdup(
"f");
399 arr->insert(std::make_pair(f_char, 42));
404 auto it = arr->find(
'f');
409 auto it = arr->find(
'g');
414 auto res = arr->emplace(
'h', static_cast<int64_t>(123));
422 auto res = arr->emplace(
'f', static_cast<int64_t>(123));
427 for (
auto it : *arr) {
size_t operator()(char *a)
AHACstrInt::Config cstrIntCfg
pair< KeyT, ValueT > createEntry(int i)
void deallocate(T *p, size_t n)
const T & const_reference
char * operator()(const char &a)
#define EXPECT_EQ(val1, val2)
void testNoncopyableMap()
static bool legalKey(char *a)
bool operator()(char *a, const char &b)
constexpr size_type size() const
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
uint32_t jenkins_rev_mix32(uint32_t key) noexcept
char * operator()(const StringPiece a)
size_t operator()(const StringPiece a)
bool operator==(const MmapAllocator< T > &) const
TEST(Aha, InsertErase_i32_i32)
ptrdiff_t difference_type
bool operator()(char *a, const StringPiece b)
void construct(T *p, Args &&...args)
constexpr Iter begin() const
#define EXPECT_TRUE(condition)
static SmartPtr create(size_t maxSize, const Config &c=Config())
const T * address(const T &x) const
size_t operator()(const char &a)
#define EXPECT_FALSE(condition)
bool operator()(char *a, char *b)
bool operator!=(const MmapAllocator< T > &other) const
AtomicHashArray< char *, int64_t, HashTraits, EqTraits, MmapAllocator< char >, AtomicHashArrayQuadraticProbeFcn, KeyConvertTraits > AHACstrInt