[llvm-commits] [llvm] r119872 - in /llvm/trunk: include/llvm/ADT/IntervalMap.h unittests/ADT/IntervalMapTest.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Nov 19 15:28:57 PST 2010
Author: stoklund
Date: Fri Nov 19 17:28:57 2010
New Revision: 119872
URL: http://llvm.org/viewvc/llvm-project?rev=119872&view=rev
Log:
Implement IntervalMap::clear().
Modified:
llvm/trunk/include/llvm/ADT/IntervalMap.h
llvm/trunk/unittests/ADT/IntervalMapTest.cpp
Modified: llvm/trunk/include/llvm/ADT/IntervalMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntervalMap.h?rev=119872&r1=119871&r2=119872&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntervalMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IntervalMap.h Fri Nov 19 17:28:57 2010
@@ -806,7 +806,7 @@
Leaf *allocLeaf() {
return new(allocator.template Allocate<Leaf>()) Leaf();
}
- void freeLeaf(Leaf *P) {
+ void deleteLeaf(Leaf *P) {
P->~Leaf();
allocator.Deallocate(P);
}
@@ -814,7 +814,7 @@
Branch *allocBranch() {
return new(allocator.template Allocate<Branch>()) Branch();
}
- void freeBranch(Branch *P) {
+ void deleteBranch(Branch *P) {
P->~Branch();
allocator.Deallocate(P);
}
@@ -838,8 +838,8 @@
bool branched() const { return height > 0; }
ValT treeSafeLookup(KeyT x, ValT NotFound) const;
-
void visitNodes(void (IntervalMap::*f)(NodeRef, unsigned Level));
+ void deleteNode(NodeRef Node, unsigned Level);
public:
explicit IntervalMap(Allocator &a) : height(0), rootSize(0), allocator(a) {
@@ -881,6 +881,9 @@
find(a).insert(a, b, y);
}
+ /// clear - Remove all entries.
+ void clear();
+
class const_iterator;
class iterator;
friend class const_iterator;
@@ -1048,6 +1051,25 @@
(this->*f)(Refs[i], 0);
}
+template <typename KeyT, typename ValT, unsigned N, typename Traits>
+void IntervalMap<KeyT, ValT, N, Traits>::
+deleteNode(NodeRef Node, unsigned Level) {
+ if (Level)
+ deleteBranch(&Node.branch());
+ else
+ deleteLeaf(&Node.leaf());
+}
+
+template <typename KeyT, typename ValT, unsigned N, typename Traits>
+void IntervalMap<KeyT, ValT, N, Traits>::
+clear() {
+ if (branched()) {
+ visitNodes(&IntervalMap::deleteNode);
+ switchRootToLeaf();
+ }
+ rootSize = 0;
+}
+
#ifndef NDEBUG
template <typename KeyT, typename ValT, unsigned N, typename Traits>
void IntervalMap<KeyT, ValT, N, Traits>::
Modified: llvm/trunk/unittests/ADT/IntervalMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/IntervalMapTest.cpp?rev=119872&r1=119871&r2=119872&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/IntervalMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/IntervalMapTest.cpp Fri Nov 19 17:28:57 2010
@@ -315,6 +315,11 @@
EXPECT_EQ(320u, I.stop());
++I;
EXPECT_FALSE(I.valid());
+
+ // Test clear() on non-branched map.
+ map.clear();
+ EXPECT_TRUE(map.empty());
+ EXPECT_TRUE(map.begin() == map.end());
}
// Branched, non-coalescing tests.
@@ -362,6 +367,10 @@
}
EXPECT_TRUE(I == map.begin());
+ // Test clear() on branched map.
+ map.clear();
+ EXPECT_TRUE(map.empty());
+ EXPECT_TRUE(map.begin() == map.end());
}
} // namespace
More information about the llvm-commits
mailing list