Example #1
0
/********************************* operator* ******************************//**
 * Perform boolean intersection on two Sets
 * @param        B the Set to be intersect-ed with
 * @return        The intersection of Set `this` and Set `B`
 * @post        The two original Sets are unchanged
 */
SortSetArray SortSetArray::operator*(const SortSetArray& B) const {
    const SortSetArray * biggerSet = (arraySize > B.arraySize) ?(this):(&B);
    const SortSetArray * smallerSet = (arraySize > B.arraySize)?(&B):(this);

    int smallerSize = smallerSet->arraySize;
    //int biggerSize = biggerSet->arraySize;

    SortSetArray C;
    C.makeRoom(smallerSize);

    C.inputSize = 0;
    C.arraySize = smallerSize;

    // AND-ing the common part
    for(int i = 0; i < smallerSize; i++) {
        // intersection is AND
        C.numbers[i] = (biggerSet->numbers[i] && smallerSet->numbers[i]);

        // count 1 for every true pair found
        if (numbers[i] == true && B.numbers[i] == true)
            C.inputSize++;
    }

    return C;
}
Example #2
0
/********************************* operator+ ******************************//**
 * Perform boolean union on two Sets
 * @param        B the Set to be union-ed with
 * @return        The union of Set `this` and Set `B`
 * @post        The two original Sets are unchanged            
 */
SortSetArray SortSetArray::operator+(const SortSetArray& B) const {
    const SortSetArray * biggerSet = (arraySize > B.arraySize)?(this):(&B);
    const SortSetArray * smallerSet = (arraySize > B.arraySize)?(&B):(this);

    int smallerSize = smallerSet->arraySize;
    int biggerSize = biggerSet->arraySize;

    SortSetArray C;
    C.makeRoom(biggerSize);

    C.arraySize = biggerSize;
    C.inputSize = biggerSet->inputSize;

    // OR-ing the common part
    for(int i = 0; i < smallerSize; i++) {
        // union is OR
        C.numbers[i] = (biggerSet->numbers[i] || smallerSet->numbers[i]);

        // if smallerSet has unique items, then increase size
        if (smallerSet->numbers[i] == true && biggerSet->numbers[i] == false)
            C.inputSize++;
    }
    // copying the remainder of the larger array
    for(int i=smallerSize; i < biggerSize; i++) {
        C.numbers[i] = biggerSet->numbers[i];
    }

    return C;
}