From 328eb0d3282a34b7a96bdc18df463227b98f25fc Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 19 Nov 2010 23:28:53 +0000 Subject: [PATCH] Support backwards iteration starting from end(). llvm-svn: 119871 --- include/llvm/ADT/IntervalMap.h | 2 +- unittests/ADT/IntervalMapTest.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/IntervalMap.h b/include/llvm/ADT/IntervalMap.h index b128f31a8d2..dd4eec3c63c 100644 --- a/include/llvm/ADT/IntervalMap.h +++ b/include/llvm/ADT/IntervalMap.h @@ -1235,7 +1235,7 @@ public: if (!branched()) { assert(rootOffset && "Cannot decrement begin()"); --rootOffset; - } else if (treeLeafOffset()) + } else if (valid() && treeLeafOffset()) --treeLeafOffset(); else treeDecrement(); diff --git a/unittests/ADT/IntervalMapTest.cpp b/unittests/ADT/IntervalMapTest.cpp index 5c8b61f278d..c7def84340a 100644 --- a/unittests/ADT/IntervalMapTest.cpp +++ b/unittests/ADT/IntervalMapTest.cpp @@ -352,6 +352,16 @@ TEST(IntervalMapTest, Branched) { EXPECT_FALSE(I.valid()); EXPECT_TRUE(I == map.end()); + // Backwards iteration. + for (unsigned i = 99; i; --i) { + --I; + ASSERT_TRUE(I.valid()); + EXPECT_EQ(10*i, I.start()); + EXPECT_EQ(10*i+5, I.stop()); + EXPECT_EQ(i, *I); + } + EXPECT_TRUE(I == map.begin()); + } } // namespace