Commit 4aa9b357 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/container/

Summary: [Folly] Apply `clang-format` to `folly/container/`.

Reviewed By: shixiao

Differential Revision: D9672403

fbshipit-source-id: da8e2a10eafcc8a278c002223cfeec055936d0bc
parent 062bb26d
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
namespace folly { namespace folly {
/* using override */ using std::size;
/* using override */ using std::empty;
/* using override */ using std::data; /* using override */ using std::data;
/* using override */ using std::empty;
/* using override */ using std::size;
} } // namespace folly
#else #else
...@@ -84,6 +84,6 @@ constexpr E const* data(std::initializer_list<E> il) noexcept { ...@@ -84,6 +84,6 @@ constexpr E const* data(std::initializer_list<E> il) noexcept {
return il.begin(); return il.begin();
} }
} } // namespace folly
#endif #endif
...@@ -115,32 +115,28 @@ class EvictingCacheMap { ...@@ -115,32 +115,28 @@ class EvictingCacheMap {
// iterator base : returns TPair on dereference // iterator base : returns TPair on dereference
template <typename Value, typename TIterator> template <typename Value, typename TIterator>
class iterator_base class iterator_base : public boost::iterator_adaptor<
: public boost::iterator_adaptor<iterator_base<Value, TIterator>, iterator_base<Value, TIterator>,
TIterator, TIterator,
Value, Value,
boost::bidirectional_traversal_tag > { boost::bidirectional_traversal_tag> {
public: public:
iterator_base() { iterator_base() {}
}
explicit iterator_base(TIterator it) explicit iterator_base(TIterator it)
: iterator_base::iterator_adaptor_(it) { : iterator_base::iterator_adaptor_(it) {}
}
Value& dereference() const { Value& dereference() const {
return this->base_reference()->pr; return this->base_reference()->pr;
} }
}; };
// iterators // iterators
typedef iterator_base< typedef iterator_base<TPair, typename NodeList::iterator> iterator;
TPair, typename NodeList::iterator> iterator; typedef iterator_base<const TPair, typename NodeList::const_iterator>
typedef iterator_base< const_iterator;
const TPair, typename NodeList::const_iterator> const_iterator; typedef iterator_base<TPair, typename NodeList::reverse_iterator>
typedef iterator_base< reverse_iterator;
TPair, typename NodeList::reverse_iterator> reverse_iterator; typedef iterator_base<const TPair, typename NodeList::const_reverse_iterator>
typedef iterator_base< const_reverse_iterator;
const TPair,
typename NodeList::const_reverse_iterator> const_reverse_iterator;
// the default map typedefs // the default map typedefs
using key_type = TKey; using key_type = TKey;
...@@ -315,7 +311,8 @@ class EvictingCacheMap { ...@@ -315,7 +311,8 @@ class EvictingCacheMap {
* a value that already exists. * a value that already exists.
* @param pruneHook callback to use on eviction (if it occurs). * @param pruneHook callback to use on eviction (if it occurs).
*/ */
void set(const TKey& key, void set(
const TKey& key,
TValue value, TValue value,
bool promote = true, bool promote = true,
PruneHookCall pruneHook = nullptr) { PruneHookCall pruneHook = nullptr) {
...@@ -373,7 +370,6 @@ class EvictingCacheMap { ...@@ -373,7 +370,6 @@ class EvictingCacheMap {
pruneHook_ = pruneHook; pruneHook_ = pruneHook;
} }
/** /**
* Prune the minimum of pruneSize and size() from the back of the LRU. * Prune the minimum of pruneSize and size() from the back of the LRU.
* Will throw if pruneHook throws. * Will throw if pruneHook throws.
...@@ -481,12 +477,14 @@ class EvictingCacheMap { ...@@ -481,12 +477,14 @@ class EvictingCacheMap {
* @param pruneHook a custom pruneHook function * @param pruneHook a custom pruneHook function
* @param failSafe true if exceptions are to ignored, false by default * @param failSafe true if exceptions are to ignored, false by default
*/ */
void pruneWithFailSafeOption(std::size_t pruneSize, void pruneWithFailSafeOption(
PruneHookCall pruneHook, bool failSafe) { std::size_t pruneSize,
PruneHookCall pruneHook,
bool failSafe) {
auto& ph = (nullptr == pruneHook) ? pruneHook_ : pruneHook; auto& ph = (nullptr == pruneHook) ? pruneHook_ : pruneHook;
for (std::size_t i = 0; i < pruneSize && !lru_.empty(); i++) { for (std::size_t i = 0; i < pruneSize && !lru_.empty(); i++) {
auto *node = &(*lru_.rbegin()); auto* node = &(*lru_.rbegin());
std::unique_ptr<Node> nptr(node); std::unique_ptr<Node> nptr(node);
lru_.erase(lru_.iterator_to(*node)); lru_.erase(lru_.iterator_to(*node));
......
...@@ -141,11 +141,10 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index); ...@@ -141,11 +141,10 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
* If you need access to the iterators please write an explicit iterator loop * If you need access to the iterators please write an explicit iterator loop
*/ */
#define FOR_EACH(i, c) \ #define FOR_EACH(i, c) \
if (bool _FE_ANON(s1_) = false) {} else \ if (bool _FE_ANON(s1_) = false) { \
for (auto && _FE_ANON(s2_) = (c); \ } else \
!_FE_ANON(s1_); _FE_ANON(s1_) = true) \ for (auto&& _FE_ANON(s2_) = (c); !_FE_ANON(s1_); _FE_ANON(s1_) = true) \
for (auto i = _FE_ANON(s2_).begin(); \ for (auto i = _FE_ANON(s2_).begin(); i != _FE_ANON(s2_).end(); ++i)
i != _FE_ANON(s2_).end(); ++i)
/* /*
* If you just want the element values, please use this (ranges-v3) construct: * If you just want the element values, please use this (ranges-v3) construct:
...@@ -155,11 +154,10 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index); ...@@ -155,11 +154,10 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
* If you need access to the iterators please write an explicit iterator loop * If you need access to the iterators please write an explicit iterator loop
*/ */
#define FOR_EACH_R(i, c) \ #define FOR_EACH_R(i, c) \
if (bool _FE_ANON(s1_) = false) {} else \ if (bool _FE_ANON(s1_) = false) { \
for (auto && _FE_ANON(s2_) = (c); \ } else \
!_FE_ANON(s1_); _FE_ANON(s1_) = true) \ for (auto&& _FE_ANON(s2_) = (c); !_FE_ANON(s1_); _FE_ANON(s1_) = true) \
for (auto i = _FE_ANON(s2_).rbegin(); \ for (auto i = _FE_ANON(s2_).rbegin(); i != _FE_ANON(s2_).rend(); ++i)
i != _FE_ANON(s2_).rend(); ++i)
/* /*
* If you just want the element values, please use this construct: * If you just want the element values, please use this construct:
...@@ -170,13 +168,14 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index); ...@@ -170,13 +168,14 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
* and use a counter variable * and use a counter variable
*/ */
#define FOR_EACH_ENUMERATE(count, i, c) \ #define FOR_EACH_ENUMERATE(count, i, c) \
if (bool _FE_ANON(s1_) = false) {} else \ if (bool _FE_ANON(s1_) = false) { \
for (auto && FOR_EACH_state2 = (c); \ } else \
!_FE_ANON(s1_); _FE_ANON(s1_) = true) \ for (auto&& FOR_EACH_state2 = (c); !_FE_ANON(s1_); _FE_ANON(s1_) = true) \
if (size_t _FE_ANON(n1_) = 0) {} else \ if (size_t _FE_ANON(n1_) = 0) { \
if (const size_t& count = _FE_ANON(n1_)) {} else \ } else if (const size_t& count = _FE_ANON(n1_)) { \
for (auto i = FOR_EACH_state2.begin(); \ } else \
i != FOR_EACH_state2.end(); ++_FE_ANON(n1_), ++i) for (auto i = FOR_EACH_state2.begin(); i != FOR_EACH_state2.end(); \
++_FE_ANON(n1_), ++i)
/** /**
* If you just want the keys, please use this (ranges-v3) construct: * If you just want the keys, please use this (ranges-v3) construct:
* *
...@@ -196,27 +195,29 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index); ...@@ -196,27 +195,29 @@ FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
* *
*/ */
#define FOR_EACH_KV(k, v, c) \ #define FOR_EACH_KV(k, v, c) \
if (unsigned int _FE_ANON(s1_) = 0) {} else \ if (unsigned int _FE_ANON(s1_) = 0) { \
for (auto && _FE_ANON(s2_) = (c); \ } else \
!_FE_ANON(s1_); _FE_ANON(s1_) = 1) \ for (auto&& _FE_ANON(s2_) = (c); !_FE_ANON(s1_); _FE_ANON(s1_) = 1) \
for (auto _FE_ANON(s3_) = _FE_ANON(s2_).begin(); \ for (auto _FE_ANON(s3_) = _FE_ANON(s2_).begin(); \
_FE_ANON(s3_) != _FE_ANON(s2_).end(); \ _FE_ANON(s3_) != _FE_ANON(s2_).end(); \
_FE_ANON(s1_) == 2 \ _FE_ANON(s1_) == 2 ? ((_FE_ANON(s1_) = 0), ++_FE_ANON(s3_)) \
? ((_FE_ANON(s1_) = 0), ++_FE_ANON(s3_)) \
: (_FE_ANON(s3_) = _FE_ANON(s2_).end())) \ : (_FE_ANON(s3_) = _FE_ANON(s2_).end())) \
for (auto &k = _FE_ANON(s3_)->first; \ for (auto& k = _FE_ANON(s3_)->first; !_FE_ANON(s1_); ++_FE_ANON(s1_)) \
!_FE_ANON(s1_); ++_FE_ANON(s1_)) \ for (auto& v = _FE_ANON(s3_)->second; !_FE_ANON(s1_); ++_FE_ANON(s1_))
for (auto &v = _FE_ANON(s3_)->second; \
!_FE_ANON(s1_); ++_FE_ANON(s1_))
namespace folly { namespace detail { namespace folly {
namespace detail {
// Boost 1.48 lacks has_less, we emulate a subset of it here. // Boost 1.48 lacks has_less, we emulate a subset of it here.
template <typename T, typename U> template <typename T, typename U>
class HasLess { class HasLess {
struct BiggerThanChar { char unused[2]; }; struct BiggerThanChar {
template <typename C, typename D> static char test(decltype(C() < D())*); char unused[2];
template <typename, typename> static BiggerThanChar test(...); };
template <typename C, typename D>
static char test(decltype(C() < D())*);
template <typename, typename>
static BiggerThanChar test(...);
public: public:
enum { value = sizeof(test<T, U>(nullptr)) == 1 }; enum { value = sizeof(test<T, U>(nullptr)) == 1 };
...@@ -269,10 +270,8 @@ notThereYet(T& iter, const U& end) { ...@@ -269,10 +270,8 @@ notThereYet(T& iter, const U& end) {
template <class T, class U> template <class T, class U>
typename std::enable_if< typename std::enable_if<
!( !((std::is_arithmetic<T>::value && std::is_arithmetic<U>::value) ||
(std::is_arithmetic<T>::value && std::is_arithmetic<U>::value) || (std::is_pointer<T>::value && std::is_pointer<U>::value)),
(std::is_pointer<T>::value && std::is_pointer<U>::value)
),
bool>::type bool>::type
notThereYet(T& iter, const U& end) { notThereYet(T& iter, const U& end) {
return iter != end; return iter != end;
...@@ -280,20 +279,21 @@ notThereYet(T& iter, const U& end) { ...@@ -280,20 +279,21 @@ notThereYet(T& iter, const U& end) {
#endif #endif
/** /**
* downTo is similar to notThereYet, but in reverse - it helps the * downTo is similar to notThereYet, but in reverse - it helps the
* FOR_EACH_RANGE_R macro. * FOR_EACH_RANGE_R macro.
*/ */
template <class T, class U> template <class T, class U>
typename std::enable_if<HasLess<U, T>::value, bool>::type typename std::enable_if<HasLess<U, T>::value, bool>::type downTo(
downTo(T& iter, const U& begin) { T& iter,
const U& begin) {
return begin < iter--; return begin < iter--;
} }
template <class T, class U> template <class T, class U>
typename std::enable_if<!HasLess<U, T>::value, bool>::type typename std::enable_if<!HasLess<U, T>::value, bool>::type downTo(
downTo(T& iter, const U& begin) { T& iter,
const U& begin) {
if (iter == begin) { if (iter == begin) {
return false; return false;
} }
......
...@@ -43,9 +43,13 @@ ...@@ -43,9 +43,13 @@
namespace folly { namespace folly {
template <class InputIt1, class InputIt2, class OutputIt, class Compare> template <class InputIt1, class InputIt2, class OutputIt, class Compare>
OutputIt merge(InputIt1 first1, InputIt1 last1, OutputIt merge(
InputIt2 first2, InputIt2 last2, InputIt1 first1,
OutputIt d_first, Compare comp) { InputIt1 last1,
InputIt2 first2,
InputIt2 last2,
OutputIt d_first,
Compare comp) {
for (; first1 != last1; ++d_first) { for (; first1 != last1; ++d_first) {
if (first2 == last2) { if (first2 == last2) {
return std::copy(first1, last1, d_first); return std::copy(first1, last1, d_first);
...@@ -62,8 +66,11 @@ OutputIt merge(InputIt1 first1, InputIt1 last1, ...@@ -62,8 +66,11 @@ OutputIt merge(InputIt1 first1, InputIt1 last1,
} }
template <class InputIt1, class InputIt2, class OutputIt> template <class InputIt1, class InputIt2, class OutputIt>
OutputIt merge(InputIt1 first1, InputIt1 last1, OutputIt merge(
InputIt2 first2, InputIt2 last2, InputIt1 first1,
InputIt1 last1,
InputIt2 first2,
InputIt2 last2,
OutputIt d_first) { OutputIt d_first) {
for (; first1 != last1; ++d_first) { for (; first1 != last1; ++d_first) {
if (first2 == last2) { if (first2 == last2) {
......
...@@ -51,7 +51,7 @@ class SparseByteSet { ...@@ -51,7 +51,7 @@ class SparseByteSet {
static constexpr uint16_t kCapacity = 256; static constexpr uint16_t kCapacity = 256;
// No init of byte-arrays required! // No init of byte-arrays required!
SparseByteSet() : size_(0) { } SparseByteSet() : size_(0) {}
/*** /***
* add(byte) * add(byte)
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
namespace folly { namespace folly {
template <class BaseIter> class BitIterator; template <class BaseIter>
class BitIterator;
namespace bititerator_detail { namespace bititerator_detail {
...@@ -34,7 +35,7 @@ namespace bititerator_detail { ...@@ -34,7 +35,7 @@ namespace bititerator_detail {
template <class Ref, class Value> template <class Ref, class Value>
class BitReference { class BitReference {
public: public:
BitReference(Ref r, size_t bit) : ref_(r), bit_(bit) { } BitReference(Ref r, size_t bit) : ref_(r), bit_(bit) {}
/* implicit */ operator bool() const { /* implicit */ operator bool() const {
return ref_ & (one_ << bit_); return ref_ & (one_ << bit_);
...@@ -82,9 +83,9 @@ struct BitIteratorBase { ...@@ -82,9 +83,9 @@ struct BitIteratorBase {
boost::use_default, // CategoryOrTraversal boost::use_default, // CategoryOrTraversal
bititerator_detail::BitReference< bititerator_detail::BitReference<
typename std::iterator_traits<BaseIter>::reference, typename std::iterator_traits<BaseIter>::reference,
typename std::iterator_traits<BaseIter>::value_type typename std::iterator_traits<BaseIter>::value_type>, // Reference
>, // Reference ssize_t>
ssize_t> type; type;
}; };
} // namespace bititerator_detail } // namespace bititerator_detail
......
...@@ -77,7 +77,6 @@ TEST(EvictingCacheMap, SanityTest) { ...@@ -77,7 +77,6 @@ TEST(EvictingCacheMap, SanityTest) {
EXPECT_FALSE(map.exists(1)); EXPECT_FALSE(map.exists(1));
} }
TEST(EvictingCacheMap, PruneTest) { TEST(EvictingCacheMap, PruneTest) {
EvictingCacheMap<int, int> map(0); EvictingCacheMap<int, int> map(0);
EXPECT_EQ(0, map.size()); EXPECT_EQ(0, map.size());
...@@ -309,7 +308,7 @@ TEST(EvictingCacheMap, SetClearSize) { ...@@ -309,7 +308,7 @@ TEST(EvictingCacheMap, SetClearSize) {
TEST(EvictingCacheMap, DestructorInvocationTest) { TEST(EvictingCacheMap, DestructorInvocationTest) {
struct SumInt { struct SumInt {
SumInt(int val_, int* ref_) : val(val_), ref(ref_) { } SumInt(int val_, int* ref_) : val(val_), ref(ref_) {}
~SumInt() { ~SumInt() {
*ref += val; *ref += val;
} }
...@@ -535,7 +534,7 @@ TEST(EvictingCacheMap, FindTest) { ...@@ -535,7 +534,7 @@ TEST(EvictingCacheMap, FindTest) {
EXPECT_EQ(i, it->first); EXPECT_EQ(i, it->first);
EXPECT_EQ(i, it->second); EXPECT_EQ(i, it->second);
} else { } else {
EXPECT_TRUE( map.find(i) == map.end()); EXPECT_TRUE(map.find(i) == map.end());
} }
} }
for (int i = nItems * 2 - 1; i >= 0; i--) { for (int i = nItems * 2 - 1; i >= 0; i--) {
......
...@@ -280,9 +280,11 @@ BENCHMARK(ForEachKVNoMacroAssign, iters) { ...@@ -280,9 +280,11 @@ BENCHMARK(ForEachKVNoMacroAssign, iters) {
int sumKeys = 0; int sumKeys = 0;
std::string sumValues; std::string sumValues;
BENCHMARK_SUSPEND { setupBenchmark(iters); } BENCHMARK_SUSPEND {
setupBenchmark(iters);
}
FOR_EACH(iter, bmMap) { FOR_EACH (iter, bmMap) {
const int k = iter->first; const int k = iter->first;
const std::string v = iter->second; const std::string v = iter->second;
sumKeys += k; sumKeys += k;
...@@ -294,9 +296,11 @@ BENCHMARK(ForEachKVNoMacroNoAssign, iters) { ...@@ -294,9 +296,11 @@ BENCHMARK(ForEachKVNoMacroNoAssign, iters) {
int sumKeys = 0; int sumKeys = 0;
std::string sumValues; std::string sumValues;
BENCHMARK_SUSPEND { setupBenchmark(iters); } BENCHMARK_SUSPEND {
setupBenchmark(iters);
}
FOR_EACH(iter, bmMap) { FOR_EACH (iter, bmMap) {
sumKeys += iter->first; sumKeys += iter->first;
sumValues += iter->second; sumValues += iter->second;
} }
...@@ -306,7 +310,9 @@ BENCHMARK(ForEachKVMacro, iters) { ...@@ -306,7 +310,9 @@ BENCHMARK(ForEachKVMacro, iters) {
int sumKeys = 0; int sumKeys = 0;
std::string sumValues; std::string sumValues;
BENCHMARK_SUSPEND { setupBenchmark(iters); } BENCHMARK_SUSPEND {
setupBenchmark(iters);
}
FOR_EACH_KV (k, v, bmMap) { FOR_EACH_KV (k, v, bmMap) {
sumKeys += k; sumKeys += k;
......
...@@ -323,9 +323,7 @@ TEST(ForEach, FetchTestPreferIterator) { ...@@ -323,9 +323,7 @@ TEST(ForEach, FetchTestPreferIterator) {
TEST(Foreach, ForEachRvalue) { TEST(Foreach, ForEachRvalue) {
const char* const hello = "hello"; const char* const hello = "hello";
int n = 0; int n = 0;
FOR_EACH(it, std::string(hello)) { FOR_EACH (it, std::string(hello)) { ++n; }
++n;
}
EXPECT_EQ(strlen(hello), n); EXPECT_EQ(strlen(hello), n);
FOR_EACH_R (it, std::string(hello)) { FOR_EACH_R (it, std::string(hello)) {
--n; --n;
...@@ -337,10 +335,8 @@ TEST(Foreach, ForEachRvalue) { ...@@ -337,10 +335,8 @@ TEST(Foreach, ForEachRvalue) {
TEST(Foreach, ForEachNested) { TEST(Foreach, ForEachNested) {
const std::string hello = "hello"; const std::string hello = "hello";
size_t n = 0; size_t n = 0;
FOR_EACH(i, hello) { FOR_EACH (i, hello) {
FOR_EACH(j, hello) { FOR_EACH (j, hello) { ++n; }
++n;
}
} }
auto len = hello.size(); auto len = hello.size();
EXPECT_EQ(len * len, n); EXPECT_EQ(len * len, n);
...@@ -451,25 +447,17 @@ TEST(Foreach, ForEachEnumerateBreak) { ...@@ -451,25 +447,17 @@ TEST(Foreach, ForEachEnumerateBreak) {
TEST(Foreach, ForEachRangeR) { TEST(Foreach, ForEachRangeR) {
int sum = 0; int sum = 0;
FOR_EACH_RANGE_R (i, 0, 0) { FOR_EACH_RANGE_R (i, 0, 0) { sum += i; }
sum += i;
}
EXPECT_EQ(0, sum); EXPECT_EQ(0, sum);
FOR_EACH_RANGE_R (i, 0, -1) { FOR_EACH_RANGE_R (i, 0, -1) { sum += i; }
sum += i;
}
EXPECT_EQ(0, sum); EXPECT_EQ(0, sum);
FOR_EACH_RANGE_R (i, 0, 5) { FOR_EACH_RANGE_R (i, 0, 5) { sum += i; }
sum += i;
}
EXPECT_EQ(10, sum); EXPECT_EQ(10, sum);
std::list<int> lst = { 0, 1, 2, 3, 4 }; std::list<int> lst = {0, 1, 2, 3, 4};
sum = 0; sum = 0;
FOR_EACH_RANGE_R (i, lst.begin(), lst.end()) { FOR_EACH_RANGE_R (i, lst.begin(), lst.end()) { sum += *i; }
sum += *i;
}
EXPECT_EQ(10, sum); EXPECT_EQ(10, sum);
} }
...@@ -26,9 +26,7 @@ TEST(MergeTest, NonOverlapping) { ...@@ -26,9 +26,7 @@ TEST(MergeTest, NonOverlapping) {
std::vector<int> b = {1, 3, 5, 7}; std::vector<int> b = {1, 3, 5, 7};
std::vector<int> c; std::vector<int> c;
folly::merge(a.begin(), a.end(), folly::merge(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(c));
b.begin(), b.end(),
std::back_inserter(c));
EXPECT_EQ(8, c.size()); EXPECT_EQ(8, c.size());
for (size_t i = 0; i < 8; ++i) { for (size_t i = 0; i < 8; ++i) {
EXPECT_EQ(i, c[i]); EXPECT_EQ(i, c[i]);
...@@ -40,9 +38,8 @@ TEST(MergeTest, OverlappingInSingleInputRange) { ...@@ -40,9 +38,8 @@ TEST(MergeTest, OverlappingInSingleInputRange) {
std::vector<std::pair<int, int>> b = {{2, 2}, {3, 3}}; std::vector<std::pair<int, int>> b = {{2, 2}, {3, 3}};
std::map<int, int> c; std::map<int, int> c;
folly::merge(a.begin(), a.end(), folly::merge(
b.begin(), b.end(), a.begin(), a.end(), b.begin(), b.end(), std::inserter(c, c.begin()));
std::inserter(c, c.begin()));
EXPECT_EQ(3, c.size()); EXPECT_EQ(3, c.size());
// First value is inserted, second is not // First value is inserted, second is not
...@@ -57,9 +54,8 @@ TEST(MergeTest, OverlappingInDifferentInputRange) { ...@@ -57,9 +54,8 @@ TEST(MergeTest, OverlappingInDifferentInputRange) {
std::vector<std::pair<int, int>> b = {{0, 2}, {3, 3}}; std::vector<std::pair<int, int>> b = {{0, 2}, {3, 3}};
std::map<int, int> c; std::map<int, int> c;
folly::merge(a.begin(), a.end(), folly::merge(
b.begin(), b.end(), a.begin(), a.end(), b.begin(), b.end(), std::inserter(c, c.begin()));
std::inserter(c, c.begin()));
EXPECT_EQ(3, c.size()); EXPECT_EQ(3, c.size());
// Value from a is inserted, value from b is not. // Value from a is inserted, value from b is not.
......
...@@ -45,6 +45,7 @@ class BitSetWrapper { ...@@ -45,6 +45,7 @@ class BitSetWrapper {
inline bool contains(uint8_t i) { inline bool contains(uint8_t i) {
return rep_[i]; return rep_[i];
} }
private: private:
bitset<256> rep_; bitset<256> rep_;
}; };
...@@ -63,6 +64,7 @@ class BoolArraySet { ...@@ -63,6 +64,7 @@ class BoolArraySet {
inline bool contains(uint8_t i) { inline bool contains(uint8_t i) {
return rep_[i]; return rep_[i];
} }
private: private:
bool rep_[256]; bool rep_[256];
}; };
...@@ -86,7 +88,7 @@ void rand_bench(int iters, size_t size_add, size_t size_contains) { ...@@ -86,7 +88,7 @@ void rand_bench(int iters, size_t size_add, size_t size_contains) {
for (auto b : seq_add) { for (auto b : seq_add) {
coll.add(b); coll.add(b);
} }
bool q {}; bool q{};
for (auto b : seq_contains) { for (auto b : seq_contains) {
q ^= coll.contains(b); q ^= coll.contains(b);
} }
...@@ -119,32 +121,28 @@ void setup_rand_bench() { ...@@ -119,32 +121,28 @@ void setup_rand_bench() {
tie(size_add, size_contains) = kvp; tie(size_add, size_contains) = kvp;
addBenchmark( addBenchmark(
__FILE__, __FILE__,
sformat("bitset_rand_bench({}, {})", sformat("bitset_rand_bench({}, {})", size_add, size_contains).c_str(),
size_add, size_contains).c_str(),
[=](int iters) { [=](int iters) {
rand_bench<BitSetWrapper>(iters, size_add, size_contains); rand_bench<BitSetWrapper>(iters, size_add, size_contains);
return iters; return iters;
}); });
addBenchmark( addBenchmark(
__FILE__, __FILE__,
sformat("%bool_array_set_rand_bench({}, {})", sformat("%bool_array_set_rand_bench({}, {})", size_add, size_contains)
size_add, size_contains).c_str(), .c_str(),
[=](int iters) { [=](int iters) {
rand_bench<BoolArraySet>(iters, size_add, size_contains); rand_bench<BoolArraySet>(iters, size_add, size_contains);
return iters; return iters;
}); });
addBenchmark( addBenchmark(
__FILE__, __FILE__,
sformat("%sparse_byte_set_rand_bench({}, {})", sformat("%sparse_byte_set_rand_bench({}, {})", size_add, size_contains)
size_add, size_contains).c_str(), .c_str(),
[=](int iters) { [=](int iters) {
rand_bench<SparseByteSet>(iters, size_add, size_contains); rand_bench<SparseByteSet>(iters, size_add, size_contains);
return iters; return iters;
}); });
addBenchmark( addBenchmark(__FILE__, "-", [](int) { return 0; });
__FILE__,
"-",
[](int) { return 0; });
} }
} }
......
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