From 655fbb4f9b46ea93eddf0815eaed0020e9347416 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 19 Nov 2010 23:28:57 +0000 Subject: Implement IntervalMap::clear(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119872 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/IntervalMap.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'include/llvm/ADT/IntervalMap.h') 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(); } - 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(); } - 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 +void IntervalMap:: +deleteNode(NodeRef Node, unsigned Level) { + if (Level) + deleteBranch(&Node.branch()); + else + deleteLeaf(&Node.leaf()); +} + +template +void IntervalMap:: +clear() { + if (branched()) { + visitNodes(&IntervalMap::deleteNode); + switchRootToLeaf(); + } + rootSize = 0; +} + #ifndef NDEBUG template void IntervalMap:: -- cgit v1.2.3