Skip to content

BitVecAll

Description

Check if all bits in bitvector match the given value.

Parameters

Name Direction Description
bv in Bitvector to check
value in Value to check against (true or false)

Usage example (from documentation)

  bool all_set = BitVecAll(&flags, true);

Success

Returns true when every bit equals value (vacuously true on an empty bitvector). The bitvector is not modified.

Failure

Returns false when at least one bit differs from value. The bitvector is not modified.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool BitVecAll(const BitVec *bv, bool value) {
        ValidateBitVec(bv);
    
        // This should cause LOG_FATAL and terminate the program
        BitVecAll(NULL, true);
    
        return true; // Should never reach here
            BitVecPush(&bv, true);
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
            BitVecPush(&bv, false);
        }
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        }
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
        BitVecPush(&bv, true);
    
        result = result && !BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
    
        result = result && !BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
    
        // Test empty bitvector - all predicates should return true for empty set
        result = result && BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        // Test empty bitvector - all predicates should return true for empty set
        result = result && BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
        // Test single element bitvector
        BitVecPush(&bv, true);
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        BitVecPush(&bv, true);
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
            BitVecPush(&bv, true); // All true
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
    
        // Change one bit to false
        // Change one bit to false
        BitVecSet(&bv, 500, false);
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecAll, BitVecAny, BitVecNone functions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
    
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
    
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
        BitVecPush(&bv, false);
    
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
    
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
        BitVecPush(&bv, true);
    
        result = result && !BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
    
        result = result && !BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
    
        // Test empty bitvector - all predicates should return true for empty set
        result = result && BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        // Test empty bitvector - all predicates should return true for empty set
        result = result && BitVecAll(&bv, true);
        result = result && BitVecAll(&bv, false);
        result = result && !BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
        // Test single element bitvector
        BitVecPush(&bv, true);
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        BitVecPush(&bv, true);
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        result = result && BitVecAny(&bv, true);
        result = result && !BitVecAny(&bv, false);
            BitVecPush(&bv, true); // All true
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
        }
        result = result && BitVecAll(&bv, true);
        result = result && !BitVecAll(&bv, false);
    
        // Change one bit to false
        // Change one bit to false
        BitVecSet(&bv, 500, false);
        result = result && !BitVecAll(&bv, true);
        result = result && BitVecAny(&bv, true);
        result = result && BitVecAny(&bv, false);
    
        // This should cause LOG_FATAL and terminate the program
        BitVecAll(NULL, true);
    
        return true; // Should never reach here
Last updated on