summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/IntervalMap.h
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2010-11-19 23:28:57 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2010-11-19 23:28:57 +0000
commit655fbb4f9b46ea93eddf0815eaed0020e9347416 (patch)
tree9492e0149af445cfaa703b4b7f6781ebeae62f24 /include/llvm/ADT/IntervalMap.h
parentdb52566d684a36cf1f320f91ca5c15d5cd075b95 (diff)
downloadllvm-655fbb4f9b46ea93eddf0815eaed0020e9347416.tar.gz
llvm-655fbb4f9b46ea93eddf0815eaed0020e9347416.tar.bz2
llvm-655fbb4f9b46ea93eddf0815eaed0020e9347416.tar.xz
Implement IntervalMap::clear().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/IntervalMap.h')
-rw-r--r--include/llvm/ADT/IntervalMap.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/llvm/ADT/IntervalMap.h b/include/llvm/ADT/IntervalMap.h
index dd4eec3c63..96b5161da7 100644
--- a/include/llvm/ADT/IntervalMap.h
+++ b/include/llvm/ADT/IntervalMap.h
@@ -806,7 +806,7 @@ private:
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 @@ private:
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 @@ private:
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 @@ public:
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 @@ visitNodes(void (IntervalMap::*f)(NodeRef, unsigned Height)) {
(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>::