Add an all() method to BitVector, for testing whether all bits are set.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114830 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-09-27 15:48:37 +00:00
parent 4c6809d8e3
commit fab4c9e9df
4 changed files with 27 additions and 0 deletions

View File

@ -127,6 +127,12 @@ public:
return false;
}
/// all - Returns true if all bits are set.
bool all() const {
// TODO: Optimize this.
return count() == size();
}
/// none - Returns true if none of the bits are set.
bool none() const {
return !any();

View File

@ -187,6 +187,13 @@ public:
return getPointer()->any();
}
/// all - Returns true if all bits are set.
bool all() const {
if (isSmall())
return getSmallBits() == (uintptr_t(1) << getSmallSize()) - 1;
return getPointer()->all();
}
/// none - Returns true if none of the bits are set.
bool none() const {
if (isSmall())

View File

@ -22,6 +22,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(0U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_TRUE(Vec.empty());
@ -29,6 +30,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(5U, Vec.count());
EXPECT_EQ(5U, Vec.size());
EXPECT_TRUE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -36,6 +38,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(5U, Vec.count());
EXPECT_EQ(11U, Vec.size());
EXPECT_TRUE(Vec.any());
EXPECT_FALSE(Vec.all());
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -43,6 +46,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(6U, Inv.count());
EXPECT_EQ(11U, Inv.size());
EXPECT_TRUE(Inv.any());
EXPECT_FALSE(Inv.all());
EXPECT_FALSE(Inv.none());
EXPECT_FALSE(Inv.empty());
@ -123,6 +127,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(130U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_FALSE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -130,6 +135,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Inv.count());
EXPECT_EQ(0U, Inv.size());
EXPECT_FALSE(Inv.any());
EXPECT_TRUE(Inv.all());
EXPECT_TRUE(Inv.none());
EXPECT_TRUE(Inv.empty());
@ -137,6 +143,7 @@ TEST(BitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(0U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_TRUE(Vec.empty());
}

View File

@ -19,6 +19,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(0U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_TRUE(Vec.empty());
@ -26,6 +27,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(5U, Vec.count());
EXPECT_EQ(5U, Vec.size());
EXPECT_TRUE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -33,6 +35,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(5U, Vec.count());
EXPECT_EQ(11U, Vec.size());
EXPECT_TRUE(Vec.any());
EXPECT_FALSE(Vec.all());
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -40,6 +43,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(6U, Inv.count());
EXPECT_EQ(11U, Inv.size());
EXPECT_TRUE(Inv.any());
EXPECT_FALSE(Inv.all());
EXPECT_FALSE(Inv.none());
EXPECT_FALSE(Inv.empty());
@ -120,6 +124,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(130U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_FALSE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_FALSE(Vec.empty());
@ -127,6 +132,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Inv.count());
EXPECT_EQ(0U, Inv.size());
EXPECT_FALSE(Inv.any());
EXPECT_TRUE(Inv.all());
EXPECT_TRUE(Inv.none());
EXPECT_TRUE(Inv.empty());
@ -134,6 +140,7 @@ TEST(SmallBitVectorTest, TrivialOperation) {
EXPECT_EQ(0U, Vec.count());
EXPECT_EQ(0U, Vec.size());
EXPECT_FALSE(Vec.any());
EXPECT_TRUE(Vec.all());
EXPECT_TRUE(Vec.none());
EXPECT_TRUE(Vec.empty());
}