/* * Do the bit sets union and return a new set with the result */ BitArray * bitArrayUnion (BitArray * set1, BitArray * set2) { //#ifdef _OPENMP //#else SIZET i; BitArray * result; assert( set1!= NULL && set2 != NULL ); result = newBitArray(set1->size); for (i = 0; i < set1->length; i++){ result->data[i] = set1->data[i] | set2->data[i]; } return result; //#endif }
void sumBitArray(bitArray *r , const bitArray * a , const bitArray * b){ int l = (a->length > b->length) ? a->length : b->length; bitArray * tmp = newBitArray(l); if(a->length > b->length) memcpy(tmp->array , a->array , sizeof(bit) * l); else memcpy(tmp->array , b->array , sizeof(bit) * l); int i , e = (a->length < b->length) ? a->length : b->length; for(i = 0; i < e; i++) tmp->array[i] = a->array[i] ^ b->array[i]; copyBitArray(r , tmp); deleteBitArray(tmp); }
void mulBitArray(bitArray *r , const bitArray * a , const bitArray * b){ int aG = getGradeBitArray(a); int bG = getGradeBitArray(b); int l = aG + bG + 1; //length of the result bitArray * tmp = newBitArray(l); int i; for(i = 0; i <= aG; i++) //for each bit of a { if(a->array[i] == 1) { int j , c = i; //current bit of tmp for(j = 0; j <= bG; j++) //for each bit of b tmp->array[c++] ^= b->array[j]; } } copyBitArray(r , tmp); deleteBitArray(tmp); }