* limitations under the License.
*/
-#include <sys/mman.h>
-
#include <cstddef>
#include <map>
#include <stdexcept>
#include <folly/AtomicHashArray.h>
-#include <folly/Hash.h>
#include <folly/Conv.h>
+#include <folly/Hash.h>
#include <folly/Memory.h>
+#include <folly/portability/SysMman.h>
#include <gtest/gtest.h>
-#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
-#define MAP_ANONYMOUS MAP_ANON
-#endif
-
using namespace std;
using namespace folly;
T *allocate(size_t n) {
void *p = mmap(nullptr, n * sizeof(T), PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED) throw std::bad_alloc();
return (T *)p;
}
TEST(Aha, LookupAny) {
auto arr = AHACstrInt::create(12);
- arr->insert(std::make_pair(strdup("f"), 42));
+ char* f_char = strdup("f");
+ SCOPE_EXIT { free(f_char); };
+ arr->insert(std::make_pair(f_char, 42));
+
EXPECT_EQ(42, arr->find("f")->second);
{
// Look up a single char, successfully.
EXPECT_TRUE(res.first != arr->end());
}
- for (auto it : *arr) free(it.first);
+ for (auto it : *arr) {
+ free(it.first);
+ }
+}
+
+using AHAIntCInt = AtomicHashArray<int64_t, const int32_t>;
+
+TEST(Aha, ConstValue) {
+ auto aha = AHAIntCInt::create(10);
+ aha->emplace(1, 2);
}