aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/ADT/SparseBitVector.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:01:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:01:22 +0000
commit71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch)
tree5343938942df402b49ec7300a1c25a2d4ccd5821 /include/llvm/ADT/SparseBitVector.h
parent31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff)
Diffstat (limited to 'include/llvm/ADT/SparseBitVector.h')
-rw-r--r--include/llvm/ADT/SparseBitVector.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/llvm/ADT/SparseBitVector.h b/include/llvm/ADT/SparseBitVector.h
index e2822c46e266..a82cef6028f9 100644
--- a/include/llvm/ADT/SparseBitVector.h
+++ b/include/llvm/ADT/SparseBitVector.h
@@ -132,6 +132,17 @@ public:
llvm_unreachable("Illegal empty element");
}
+ /// find_last - Returns the index of the last set bit.
+ int find_last() const {
+ for (unsigned I = 0; I < BITWORDS_PER_ELEMENT; ++I) {
+ unsigned Idx = BITWORDS_PER_ELEMENT - I - 1;
+ if (Bits[Idx] != 0)
+ return Idx * BITWORD_SIZE + BITWORD_SIZE -
+ countLeadingZeros(Bits[Idx]) - 1;
+ }
+ llvm_unreachable("Illegal empty element");
+ }
+
/// find_next - Returns the index of the next set bit starting from the
/// "Curr" bit. Returns -1 if the next set bit is not found.
int find_next(unsigned Curr) const {
@@ -768,6 +779,14 @@ public:
return (First.index() * ElementSize) + First.find_first();
}
+ // Return the last set bit in the bitmap. Return -1 if no bits are set.
+ int find_last() const {
+ if (Elements.empty())
+ return -1;
+ const SparseBitVectorElement<ElementSize> &Last = *(Elements.rbegin());
+ return (Last.index() * ElementSize) + Last.find_last();
+ }
+
// Return true if the SparseBitVector is empty
bool empty() const {
return Elements.empty();