Skip to content
BitVecFindLast

BitVecFindLast

BitVecFindLast

Description

Find index of last occurrence of a specific bit value.

Parameters

Name Direction Description
bv in Bitvector to search in
value in Bit value to find (true or false)

Usage example (from documentation)

  u64 index = BitVecFindLast(&flags, false);

Returns

Index of last occurrence, or SIZE_MAX if not found

Usage example (Cross-references)

Usage examples (Cross-references)
        ValidateBitVec(bv);
    
        u64 pos = BitVecFindLast(bv, value);
        if (pos != SIZE_MAX) {
            BitVecRemove(bv, pos);
    }
    
    u64 BitVecFindLast(BitVec *bv, bool value) {
        ValidateBitVec(bv);
    
        // Test BitVecFindLast
        result = result && (BitVecFindLast(&bv, true) == 7);  // Last true at index 7
        result = result && (BitVecFindLast(&bv, false) == 6); // Last false at index 6
        // Test BitVecFindLast
        result = result && (BitVecFindLast(&bv, true) == 7);  // Last true at index 7
        result = result && (BitVecFindLast(&bv, false) == 6); // Last false at index 6
    
        // Test with all same values
        }
        result = result && (BitVecFind(&bv, true) == 0);
        result = result && (BitVecFindLast(&bv, true) == 4);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == 4);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        BitVecDeinit(&bv);
        result = result && (BitVecFind(&bv, true) == SIZE_MAX);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        // Test single element
        BitVecPush(&bv, true);
        result = result && (BitVecFind(&bv, true) == 0);
        result = result && (BitVecFindLast(&bv, true) == 0);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == 0);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        // Test with large bitvector
        }
        result = result && (BitVecFind(&bv, true) == 500);
        result = result && (BitVecFindLast(&bv, true) == 999);
    
        BitVecDeinit(&bv);
    // Test BitVecFind and BitVecFindLast functions
    bool test_bitvec_find_functions(void) {
        WriteFmt("Testing BitVecFind and BitVecFindLast functions\n");
    
        BitVec bv     = BitVecInit();
    
        // Test finding last true (should be at index 5)
        result = result && (BitVecFindLast(&bv, true) == 5);
    
        // Test finding last false (should be at index 7)
    
        // Test finding last false (should be at index 7)
        result = result && (BitVecFindLast(&bv, false) == 7);
    
        // Test with all same values
    
        result = result && (BitVecFind(&bv, true) == 0);
        result = result && (BitVecFindLast(&bv, true) == 2);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == 2);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        BitVecDeinit(&bv);
        result = result && (BitVecFind(&bv, true) == SIZE_MAX);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        // Test single element
        BitVecPush(&bv, true);
        result = result && (BitVecFind(&bv, true) == 0);
        result = result && (BitVecFindLast(&bv, true) == 0);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, true) == 0);
        result = result && (BitVecFind(&bv, false) == SIZE_MAX);
        result = result && (BitVecFindLast(&bv, false) == SIZE_MAX);
    
        // Test with large bitvector
        }
        result = result && (BitVecFind(&bv, true) == 500);
        result = result && (BitVecFindLast(&bv, true) == 999);
    
        BitVecDeinit(&bv);
Last updated on