<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">TBH I was just following what we did for SmallDenseMap. I am fine making this change.<div class=""><br class=""></div><div class="">Michael</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 31, 2014, at 6:44 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Wed, Dec 31, 2014 at 3:33 PM, Michael Gottesman<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:mgottesman@apple.com" target="_blank" class="">mgottesman@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Author: mgottesman<br class="">Date: Wed Dec 31 17:33:21 2014<br class="">New Revision: 225054<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=225054&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=225054&view=rev</a><br class="">Log:<br class="">Add a SmallMapVector class that is a MapVector with a Map of SmallDenseMap and a Vector of SmallVector.<br class=""><br class="">Modified:<br class=""> <span class="Apple-converted-space"> </span>llvm/trunk/include/llvm/ADT/MapVector.h<br class=""> <span class="Apple-converted-space"> </span>llvm/trunk/unittests/ADT/MapVectorTest.cpp<br class=""><br class="">Modified: llvm/trunk/include/llvm/ADT/MapVector.h<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=225054&r1=225053&r2=225054&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=225054&r1=225053&r2=225054&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/ADT/MapVector.h (original)<br class="">+++ llvm/trunk/include/llvm/ADT/MapVector.h Wed Dec 31 17:33:21 2014<br class="">@@ -18,6 +18,7 @@<br class=""> #define LLVM_ADT_MAPVECTOR_H<br class=""><br class=""> #include "llvm/ADT/DenseMap.h"<br class="">+#include "llvm/ADT/SmallVector.h"<br class=""> #include <vector><br class=""><br class=""> namespace llvm {<br class="">@@ -181,6 +182,16 @@ void MapVector<KeyT, ValueT, MapType, Ve<br class=""> Vector.erase(O, Vector.end());<br class=""> }<br class=""><br class="">+/// \brief A MapVector that performs no allocations if smaller than a certain<br class="">+/// size.<br class="">+template <typename KeyT, typename ValueT, unsigned N><br class="">+class SmallMapVector<br class="">+ : public MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,<br class="">+ SmallVector<std::pair<KeyT, ValueT>, N>> {<br class=""></blockquote><div class=""><br class=""></div><div class="">Should this be an alias template instead? (or is that not supported on all our compilers? (I imagine it probably isn't supported on MSVC?))</div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+public:<br class="">+ SmallMapVector() {}<br class=""></blockquote><div class=""><br class="">This is just the default, isn't it? Perhaps you could omit it (I'd probably just make SmallMapVector a struct instead of a class - with no members and rely on the implicit public-ness of inheritance in structs)<br class=""><br class="">- David<br class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">+};<br class="">+<br class=""> } // end namespace llvm<br class=""><br class=""> #endif<br class=""><br class="">Modified: llvm/trunk/unittests/ADT/MapVectorTest.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=225054&r1=225053&r2=225054&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=225054&r1=225053&r2=225054&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/unittests/ADT/MapVectorTest.cpp (original)<br class="">+++ llvm/trunk/unittests/ADT/MapVectorTest.cpp Wed Dec 31 17:33:21 2014<br class="">@@ -122,3 +122,221 @@ TEST(MapVectorTest, iteration_test) {<br class=""> count--;<br class=""> }<br class=""> }<br class="">+<br class="">+TEST(SmallMapVectorSmallTest, insert_pop) {<br class="">+ SmallMapVector<int, int, 32> MV;<br class="">+ std::pair<SmallMapVector<int, int, 32>::iterator, bool> R;<br class="">+<br class="">+ R = MV.insert(std::make_pair(1, 2));<br class="">+ ASSERT_EQ(R.first, MV.begin());<br class="">+ EXPECT_EQ(R.first->first, 1);<br class="">+ EXPECT_EQ(R.first->second, 2);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ R = MV.insert(std::make_pair(1, 3));<br class="">+ ASSERT_EQ(R.first, MV.begin());<br class="">+ EXPECT_EQ(R.first->first, 1);<br class="">+ EXPECT_EQ(R.first->second, 2);<br class="">+ EXPECT_FALSE(R.second);<br class="">+<br class="">+ R = MV.insert(std::make_pair(4, 5));<br class="">+ ASSERT_NE(R.first, MV.end());<br class="">+ EXPECT_EQ(R.first->first, 4);<br class="">+ EXPECT_EQ(R.first->second, 5);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ EXPECT_EQ(MV.size(), 2u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+ EXPECT_EQ(MV[4], 5);<br class="">+<br class="">+ MV.pop_back();<br class="">+ EXPECT_EQ(MV.size(), 1u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+<br class="">+ R = MV.insert(std::make_pair(4, 7));<br class="">+ ASSERT_NE(R.first, MV.end());<br class="">+ EXPECT_EQ(R.first->first, 4);<br class="">+ EXPECT_EQ(R.first->second, 7);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ EXPECT_EQ(MV.size(), 2u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+ EXPECT_EQ(MV[4], 7);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorSmallTest, erase) {<br class="">+ SmallMapVector<int, int, 32> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 2));<br class="">+ MV.insert(std::make_pair(3, 4));<br class="">+ MV.insert(std::make_pair(5, 6));<br class="">+ ASSERT_EQ(MV.size(), 3u);<br class="">+<br class="">+ MV.erase(MV.find(1));<br class="">+ ASSERT_EQ(MV.size(), 2u);<br class="">+ ASSERT_EQ(MV.find(1), MV.end());<br class="">+ ASSERT_EQ(MV[3], 4);<br class="">+ ASSERT_EQ(MV[5], 6);<br class="">+<br class="">+ ASSERT_EQ(MV.erase(3), 1u);<br class="">+ ASSERT_EQ(MV.size(), 1u);<br class="">+ ASSERT_EQ(MV.find(3), MV.end());<br class="">+ ASSERT_EQ(MV[5], 6);<br class="">+<br class="">+ ASSERT_EQ(MV.erase(79), 0u);<br class="">+ ASSERT_EQ(MV.size(), 1u);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorSmallTest, remove_if) {<br class="">+ SmallMapVector<int, int, 32> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 11));<br class="">+ MV.insert(std::make_pair(2, 12));<br class="">+ MV.insert(std::make_pair(3, 13));<br class="">+ MV.insert(std::make_pair(4, 14));<br class="">+ MV.insert(std::make_pair(5, 15));<br class="">+ MV.insert(std::make_pair(6, 16));<br class="">+ ASSERT_EQ(MV.size(), 6u);<br class="">+<br class="">+ MV.remove_if([](const std::pair<int, int> &Val) { return Val.second % 2; });<br class="">+ ASSERT_EQ(MV.size(), 3u);<br class="">+ ASSERT_EQ(MV.find(1), MV.end());<br class="">+ ASSERT_EQ(MV.find(3), MV.end());<br class="">+ ASSERT_EQ(MV.find(5), MV.end());<br class="">+ ASSERT_EQ(MV[2], 12);<br class="">+ ASSERT_EQ(MV[4], 14);<br class="">+ ASSERT_EQ(MV[6], 16);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorSmallTest, iteration_test) {<br class="">+ SmallMapVector<int, int, 32> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 11));<br class="">+ MV.insert(std::make_pair(2, 12));<br class="">+ MV.insert(std::make_pair(3, 13));<br class="">+ MV.insert(std::make_pair(4, 14));<br class="">+ MV.insert(std::make_pair(5, 15));<br class="">+ MV.insert(std::make_pair(6, 16));<br class="">+ ASSERT_EQ(MV.size(), 6u);<br class="">+<br class="">+ int count = 1;<br class="">+ for (auto P : make_range(MV.begin(), MV.end())) {<br class="">+ ASSERT_EQ(P.first, count);<br class="">+ count++;<br class="">+ }<br class="">+<br class="">+ count = 6;<br class="">+ for (auto P : make_range(MV.rbegin(), MV.rend())) {<br class="">+ ASSERT_EQ(P.first, count);<br class="">+ count--;<br class="">+ }<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorLargeTest, insert_pop) {<br class="">+ SmallMapVector<int, int, 1> MV;<br class="">+ std::pair<SmallMapVector<int, int, 1>::iterator, bool> R;<br class="">+<br class="">+ R = MV.insert(std::make_pair(1, 2));<br class="">+ ASSERT_EQ(R.first, MV.begin());<br class="">+ EXPECT_EQ(R.first->first, 1);<br class="">+ EXPECT_EQ(R.first->second, 2);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ R = MV.insert(std::make_pair(1, 3));<br class="">+ ASSERT_EQ(R.first, MV.begin());<br class="">+ EXPECT_EQ(R.first->first, 1);<br class="">+ EXPECT_EQ(R.first->second, 2);<br class="">+ EXPECT_FALSE(R.second);<br class="">+<br class="">+ R = MV.insert(std::make_pair(4, 5));<br class="">+ ASSERT_NE(R.first, MV.end());<br class="">+ EXPECT_EQ(R.first->first, 4);<br class="">+ EXPECT_EQ(R.first->second, 5);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ EXPECT_EQ(MV.size(), 2u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+ EXPECT_EQ(MV[4], 5);<br class="">+<br class="">+ MV.pop_back();<br class="">+ EXPECT_EQ(MV.size(), 1u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+<br class="">+ R = MV.insert(std::make_pair(4, 7));<br class="">+ ASSERT_NE(R.first, MV.end());<br class="">+ EXPECT_EQ(R.first->first, 4);<br class="">+ EXPECT_EQ(R.first->second, 7);<br class="">+ EXPECT_TRUE(R.second);<br class="">+<br class="">+ EXPECT_EQ(MV.size(), 2u);<br class="">+ EXPECT_EQ(MV[1], 2);<br class="">+ EXPECT_EQ(MV[4], 7);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorLargeTest, erase) {<br class="">+ SmallMapVector<int, int, 1> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 2));<br class="">+ MV.insert(std::make_pair(3, 4));<br class="">+ MV.insert(std::make_pair(5, 6));<br class="">+ ASSERT_EQ(MV.size(), 3u);<br class="">+<br class="">+ MV.erase(MV.find(1));<br class="">+ ASSERT_EQ(MV.size(), 2u);<br class="">+ ASSERT_EQ(MV.find(1), MV.end());<br class="">+ ASSERT_EQ(MV[3], 4);<br class="">+ ASSERT_EQ(MV[5], 6);<br class="">+<br class="">+ ASSERT_EQ(MV.erase(3), 1u);<br class="">+ ASSERT_EQ(MV.size(), 1u);<br class="">+ ASSERT_EQ(MV.find(3), MV.end());<br class="">+ ASSERT_EQ(MV[5], 6);<br class="">+<br class="">+ ASSERT_EQ(MV.erase(79), 0u);<br class="">+ ASSERT_EQ(MV.size(), 1u);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorLargeTest, remove_if) {<br class="">+ SmallMapVector<int, int, 1> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 11));<br class="">+ MV.insert(std::make_pair(2, 12));<br class="">+ MV.insert(std::make_pair(3, 13));<br class="">+ MV.insert(std::make_pair(4, 14));<br class="">+ MV.insert(std::make_pair(5, 15));<br class="">+ MV.insert(std::make_pair(6, 16));<br class="">+ ASSERT_EQ(MV.size(), 6u);<br class="">+<br class="">+ MV.remove_if([](const std::pair<int, int> &Val) { return Val.second % 2; });<br class="">+ ASSERT_EQ(MV.size(), 3u);<br class="">+ ASSERT_EQ(MV.find(1), MV.end());<br class="">+ ASSERT_EQ(MV.find(3), MV.end());<br class="">+ ASSERT_EQ(MV.find(5), MV.end());<br class="">+ ASSERT_EQ(MV[2], 12);<br class="">+ ASSERT_EQ(MV[4], 14);<br class="">+ ASSERT_EQ(MV[6], 16);<br class="">+}<br class="">+<br class="">+TEST(SmallMapVectorLargeTest, iteration_test) {<br class="">+ SmallMapVector<int, int, 1> MV;<br class="">+<br class="">+ MV.insert(std::make_pair(1, 11));<br class="">+ MV.insert(std::make_pair(2, 12));<br class="">+ MV.insert(std::make_pair(3, 13));<br class="">+ MV.insert(std::make_pair(4, 14));<br class="">+ MV.insert(std::make_pair(5, 15));<br class="">+ MV.insert(std::make_pair(6, 16));<br class="">+ ASSERT_EQ(MV.size(), 6u);<br class="">+<br class="">+ int count = 1;<br class="">+ for (auto P : make_range(MV.begin(), MV.end())) {<br class="">+ ASSERT_EQ(P.first, count);<br class="">+ count++;<br class="">+ }<br class="">+<br class="">+ count = 6;<br class="">+ for (auto P : make_range(MV.rbegin(), MV.rend())) {<br class="">+ ASSERT_EQ(P.first, count);<br class="">+ count--;<br class="">+ }<br class="">+}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></blockquote></div></div></blockquote></div><br class=""></div></body></html>