X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2Fsmall_vector_test.cpp;h=cf1642149bab854cd42c25f89fb1386fa050b5ce;hb=cd1bdc912603c0358ba733d379a74ae90ab3a437;hp=38e1d37be58dee1575bdef0fa528c9ee2ceb77ef;hpb=0ef8ce0d60996be2467fd4ccff324d4786243f27;p=folly.git diff --git a/folly/test/small_vector_test.cpp b/folly/test/small_vector_test.cpp index 38e1d37b..cf164214 100644 --- a/folly/test/small_vector_test.cpp +++ b/folly/test/small_vector_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2011-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -64,6 +65,43 @@ static_assert(!FOLLY_IS_TRIVIALLY_COPYABLE(std::unique_ptr), namespace { +template +using small_sorted_vector_map = folly::sorted_vector_map< + Key, + Value, + std::less, + std::allocator>, + void, + folly::small_vector, N>>; + +template +using noheap_sorted_vector_map = folly::sorted_vector_map< + Key, + Value, + std::less, + std::allocator>, + void, + folly::small_vector< + std::pair, + N, + folly::small_vector_policy::NoHeap>>; + +template +using small_sorted_vector_set = folly::sorted_vector_set< + T, + std::less, + std::allocator, + void, + folly::small_vector>; + +template +using noheap_sorted_vector_set = folly::sorted_vector_set< + T, + std::less, + std::allocator, + void, + folly::small_vector>; + struct NontrivialType { static int ctored; explicit NontrivialType() : a(0) {} @@ -169,14 +207,14 @@ struct TestBasicGuarantee { throwCounter = 1000; } - template + template void operator()(int insertCount, Operation const& op) { bool done = false; std::unique_ptr > workingVec; for (int counter = 1; !done; ++counter) { throwCounter = 1000; - workingVec.reset(new folly::small_vector(vec)); + workingVec = std::make_unique>(vec); throwCounter = counter; EXPECT_EQ(Thrower::alive, prepopulate * 2); try { @@ -198,7 +236,7 @@ struct TestBasicGuarantee { } }; -} +} // namespace TEST(small_vector, BasicGuarantee) { for (int prepop = 1; prepop < 30; ++prepop) { @@ -942,7 +980,7 @@ class Counter { return *this; } }; -} +} // namespace TEST(small_vector, EmplaceBackEfficiency) { small_vector test; @@ -996,3 +1034,51 @@ TEST(small_vector, CLVPushBackEfficiency) { EXPECT_EQ(test.size() - 1, counts.moveCount); EXPECT_LT(test.size(), test.capacity()); } + +TEST(small_vector, StorageForSortedVectorMap) { + small_sorted_vector_map test; + test.insert(std::make_pair(10, 10)); + EXPECT_EQ(test.size(), 1); + test.insert(std::make_pair(10, 10)); + EXPECT_EQ(test.size(), 1); + test.insert(std::make_pair(20, 10)); + EXPECT_EQ(test.size(), 2); + test.insert(std::make_pair(30, 10)); + EXPECT_EQ(test.size(), 3); +} + +TEST(small_vector, NoHeapStorageForSortedVectorMap) { + noheap_sorted_vector_map test; + test.insert(std::make_pair(10, 10)); + EXPECT_EQ(test.size(), 1); + test.insert(std::make_pair(10, 10)); + EXPECT_EQ(test.size(), 1); + test.insert(std::make_pair(20, 10)); + EXPECT_EQ(test.size(), 2); + EXPECT_THROW(test.insert(std::make_pair(30, 10)), std::length_error); + EXPECT_EQ(test.size(), 2); +} + +TEST(small_vector, StorageForSortedVectorSet) { + small_sorted_vector_set test; + test.insert(10); + EXPECT_EQ(test.size(), 1); + test.insert(10); + EXPECT_EQ(test.size(), 1); + test.insert(20); + EXPECT_EQ(test.size(), 2); + test.insert(30); + EXPECT_EQ(test.size(), 3); +} + +TEST(small_vector, NoHeapStorageForSortedVectorSet) { + noheap_sorted_vector_set test; + test.insert(10); + EXPECT_EQ(test.size(), 1); + test.insert(10); + EXPECT_EQ(test.size(), 1); + test.insert(20); + EXPECT_EQ(test.size(), 2); + EXPECT_THROW(test.insert(30), std::length_error); + EXPECT_EQ(test.size(), 2); +}