Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
  /** Insert Eratosthenes Sieve
	@brief inserts primes into an array using the Sieve of Eratosthenes
	@param upperBound the maximum for the prime numbers
	@param arrayCreation the array to insert primes into
  */
  void insertEratosthenesSieve(int upperBound, SortSetArray &arrayCreation){
 
	int upperBoundSquareRoot = (int) sqrt((double) upperBound);

	bool *isComposite = new bool [upperBound + 1];

	memset(isComposite, 0, sizeof(bool) * (upperBound + 1));

	for (int cycle = 2; cycle <= upperBoundSquareRoot; cycle++){
		if (!isComposite[cycle]){

			arrayCreation.insert(cycle);
			
			for (int marker = cycle*cycle; marker <= upperBound; marker += cycle ){
					isComposite[marker] = true;
			}//end for marker
		
		}//end if !isComposite

	}//end for

	for (int cycle = upperBoundSquareRoot; cycle <= upperBound; cycle++){
		if (!isComposite[cycle])
			arrayCreation.insert(cycle);	

	}//end for cycle2

	delete [] isComposite;

 }//end insertEratosthenesSieve
Exemplo n.º 4
0
/**
 Operator overload for -. It will create a returning difference SortSetArray.
 The difference will contain numbers that removes first array to second array
 @param bSet the target array that you want to have the integers removed.
 @retun differenceSet that contains the difference of the two arrays.
 */
SortSetArray SortSetArray::operator-(const SortSetArray& bSet)const {
    SortSetArray differenceSet = *this;
    
    for (int i=0; i < bSet.getSize(); i++) {
        if (bSet.setArray[i] >= 0) {
            differenceSet.remove(bSet.setArray[i]);
        }
    }
    return differenceSet;
}
Exemplo n.º 5
0
/**
 Operator overload for *. It will create a returning intersection SortSetArray.
 The intersection will contain the numbers that appears in both the given arrays.
 @param bSet the target array that you want to have a intersection with.
 @retun intersectionSet that contains the intersection of the two arrays.
 */
SortSetArray SortSetArray::operator*(const SortSetArray& bSet)const {
    
    SortSetArray intersectionSet;
    
    for (int i=0; i < bSet.getSize(); i++) {
        if (bSet.setArray[i] >= 0 && bSet.setArray[i] == this->setArray[i]) {
            intersectionSet.insert(bSet.setArray[i]);
        }
    }
    return intersectionSet;
}
Exemplo n.º 6
0
/**
 Operator overload for +. It will create a returning unionSet SortSetArray.
 The union will contain union of all numbers in the two arrays.
 @param bSet the target array that you want to have a union with.
 @retun unionSet that contains the union of the two arrays.
 */
SortSetArray SortSetArray::operator+(const SortSetArray& bSet)const {

    SortSetArray unionSet = *this;
    
    for (int i=0; i < bSet.getSize(); i++) {
        if (bSet.setArray[i] >= 0 || this->setArray[i] >= 0) {
            unionSet.insert(this->setArray[i]);
            unionSet.insert(bSet.setArray[i]);
        }
    }
    return unionSet;
}
Exemplo n.º 7
0
/**
 Constructor that creates a copy array. Copy constructor
 @param other the target array want to be copied
 */
SortSetArray::SortSetArray (const SortSetArray &other) {
    setArray = new int[832040];
    size = 832041;
    for (int i=0; i < other.getSize(); i++) {
        this->setArray[i] = other.setArray[i];
   }
}
Exemplo n.º 8
0
/**
 Operator overload for !=. give a boolean for whether the two SortSetArray is not equal
 @param bSet the target array that you want to have the content checked
 @retun false if equal, true if not
 */
bool SortSetArray::operator!=(const SortSetArray& bSet)const {
    
    for (int i=0;i < bSet.getSize(); i++) {
        if(this->setArray[i] != bSet.setArray[i]) {
            return false;
        }
    }
    return true;
}
Exemplo n.º 9
0
/**
 Operator overload for -=. It will assign the union array to given array
 @param bSet the target array that you want to have the content combined
 @retun original array with the new content union with the bSet
 */
SortSetArray SortSetArray::operator-=(const SortSetArray& bSet) {
    
    for (int i=0; i < bSet.getSize(); i++) {
        if (bSet.setArray[i] >= 0) {
            this->remove(bSet.setArray[i]);
        }
    }
    return *this;
}
Exemplo n.º 10
0
void insertFibs(const int maxEntered, SortSetArray &emptyList){

	for (int cycle = 0; cycle <= maxEntered; cycle++)
	{
		int calculatedFib = fib(cycle);
		emptyList.insert(calculatedFib);

	}//end for
}//end insertFibs
Exemplo n.º 11
0
/**
 Operator overload for =. It will assign the inserted array to the given array
 @param bSet the target array that you want to have the content copied.
 @retun original array with the new content being same as bSet.
 */
SortSetArray SortSetArray::operator=(const SortSetArray& bSet) {
    for (int i=0; i < bSet.getSize(); i++) {
        this->setArray[i] = bSet.setArray[i];
    }
    return *this;
}