objective c - How do I compare two bit vectors for equivalence? -
What is the most effective way to compare two bit vectors? In Objective-C, I am using CFBitvators and I am comparing each bit in both:
For (cfindx bitindexx = bit; index and lt; nmbit; beatindex + +) {If (CFBITVictorgettextx (this Watcator, Beat Index)! = CFBitVectorGetBitAtIndex (thatVector, bitIndex)) {return; }} Yes return; That works fine, but I was not sure there was no more efficient way to use bit operators.
One can do a bit- or operation on two CFBitVectorRef structs as described in. However, this is subject to failure at future time, because it is implementation-dependent. One of the safest ways to compare them can be one bit at one time described in OP. Here's a utility job that does the whole thing:
BOOL CFBitVectorEqualsCFBitVector (CFBitVectorRef thisVector, CFBitVectorRef thatVector) {CFIndex numbits = CFBitVectorGetCount (thisVector); If not (return numbits! = CFBitVectorGetCount (thisVector)); (CFIndex bitIndex = 0; bitIndex & lt; numbeits; bitIndex ++) {if (CFBitVectorGetBitAtIndex (thisVector, bitIndex)! = CFBitVectorGetBitAtIndex (thatVector, bitIndex)) {not return; }} Yes return; }
Comments
Post a Comment