/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <map>
#include <stdexcept>
-#include "folly/AtomicHashArray.h"
-#include "folly/Hash.h"
-#include "folly/Conv.h"
-#include "folly/Memory.h"
+#include <folly/AtomicHashArray.h>
+#include <folly/Hash.h>
+#include <folly/Conv.h>
+#include <folly/Memory.h>
#include <gtest/gtest.h>
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
T *allocate(size_t n) {
void *p = mmap(nullptr, n * sizeof(T), PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- if (!p) throw std::bad_alloc();
+ if (p == MAP_FAILED) throw std::bad_alloc();
return (T *)p;
}
void testNoncopyableMap() {
typedef AtomicHashArray<KeyT, std::unique_ptr<ValueT>, std::hash<KeyT>,
std::equal_to<KeyT>, Allocator> MyArr;
- auto arr = MyArr::create(150);
+ auto arr = MyArr::create(250);
for (int i = 0; i < 100; i++) {
arr->insert(make_pair(i,std::unique_ptr<ValueT>(new ValueT(i))));
}
- for (int i = 0; i < 100; i++) {
+ for (int i = 100; i < 150; i++) {
+ arr->emplace(i,new ValueT(i));
+ }
+ for (int i = 150; i < 200; i++) {
+ arr->emplace(i,new ValueT(i),std::default_delete<ValueT>());
+ }
+ for (int i = 0; i < 200; i++) {
auto ret = arr->find(i);
EXPECT_EQ(*(ret->second), i);
}
testMap<int64_t, string>();
testMap<int64_t, string, MmapAllocator<char>>();
}
+
+TEST(Aha, Create_cstr_i64) {
+ auto obj = AtomicHashArray<const char*, int64_t>::create(12);
+}