/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// @author: Xin Liu <xliux@fb.com>
+#include <folly/ConcurrentSkipList.h>
+
#include <atomic>
#include <memory>
#include <set>
-#include <vector>
-#include <thread>
#include <system_error>
+#include <thread>
+#include <vector>
#include <glog/logging.h>
-#include <gflags/gflags.h>
-#include <folly/Arena.h>
-#include <folly/ConcurrentSkipList.h>
-#include <folly/Foreach.h>
#include <folly/Memory.h>
#include <folly/String.h>
-
-#include <gtest/gtest.h>
+#include <folly/container/Foreach.h>
+#include <folly/memory/Arena.h>
+#include <folly/portability/GFlags.h>
+#include <folly/portability/GTest.h>
DEFINE_int32(num_threads, 12, "num concurrent threads to test");
int64_t sum = 0;
SkipListAccessor::Skipper skipper(skipList);
FOR_EACH(it, *values) {
- if (skipper.to(*it)) sum += *it;
+ if (skipper.to(*it)) {
+ sum += *it;
+ }
}
VLOG(20) << "sum = " << sum;
}
skipList.add(3);
CHECK(skipList.contains(3));
int pos = 0;
- FOR_EACH(it, skipList) {
- LOG(INFO) << "pos= " << pos++ << " value= " << *it;
+ for (auto entry : skipList) {
+ LOG(INFO) << "pos= " << pos++ << " value= " << entry;
}
}
struct UniquePtrComp {
bool operator ()(
const std::unique_ptr<int> &x, const std::unique_ptr<int> &y) const {
- if (!x) return false;
- if (!y) return true;
+ if (!x) {
+ return false;
+ }
+ if (!y) {
+ return true;
+ }
return *x < *y;
}
};
static const int N = 10;
for (int i = 0; i < N; ++i) {
- accessor.insert(std::unique_ptr<int>(new int(i)));
+ accessor.insert(std::make_unique<int>(i));
}
for (int i = 0; i < N; ++i) {
template <typename ParentAlloc>
void NonTrivialDeallocationWithParanoid() {
using Alloc = ParanoidArenaAlloc<ParentAlloc>;
- using SkipListType =
+ using ParanoidSkipListType =
ConcurrentSkipList<NonTrivialValue, std::less<NonTrivialValue>, Alloc>;
ParentAlloc parentAlloc;
Alloc paranoidAlloc(&parentAlloc);
- auto list = SkipListType::createInstance(10, paranoidAlloc);
+ auto list = ParanoidSkipListType::createInstance(10, paranoidAlloc);
TestNonTrivialDeallocation(list);
EXPECT_TRUE(paranoidAlloc.isEmpty());
}
}
TEST(ConcurrentSkipList, NonTrivialDeallocationWithSysArena) {
- using SkipListType =
+ using SysArenaSkipListType =
ConcurrentSkipList<NonTrivialValue, std::less<NonTrivialValue>, SysArena>;
- auto list = SkipListType::createInstance(10);
+ auto list = SysArenaSkipListType::createInstance(10);
TestNonTrivialDeallocation(list);
}
-} // namespace
+} // namespace
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);