int main()
{
    srand(1337);

    IntSet s;
    for(int i = 1; i != 20; i++) {
        s.insert(rand() % 30);
    }

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl;
        if (i % 2 == 0) {
            s.remove(i);
        }
    }

    cout << endl;

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl;
    }

    for(int i = 0; i != 100000; i++) {
        s.insert(rand() % 55789127);
    }

    cout << "Done inserting" << endl;

    for(int i = 0; i != 1000000; i++) {
        s.contains(i);
    }
}
int main()
{
    IntSet s;
    for(int i = 0; i != 10; i++) {
        s.insert(i * 1337 % 29);
    }

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl;
        if (i % 2 == 0) {
            s.remove(i);
        }
    }
    cout << endl;

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl;
    }

    for(int i = 0; i != 100000; i++) {
        s.insert(i * 1337 % 55789127);
    }

    cout << "Done inserting" << endl;

    for(int i = 0; i != 1000000; i++)
    {
        s.contains(i);
    }
}
Example #3
0
int main() {
    srand(137872);

    IntSet* s = new BsVectorIntSet();
    for(int i = 0; i != 20; i++) {
        s->insert(rand() % 30);
    }

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s->contains(i) ? "Yes" : "No") << endl;
        if (i % 2 == 0) {
            s->remove(i);
        }
    }
    cout << endl;

    for(int i = 0; i != 30; i++) {
        cout << i << ": " << (s->contains(i) ? "Yes" : "No") << endl;
    }

    clock_t start = clock();

    for(int i = 0; i != 1000000; i++) {
        s->insert(rand());
    }

    for(int i = 0; i != 1000000; i++) {
        s->remove(rand());
    }

    cout << "Done inserting" << endl;
    cout << "Time: " << ((clock()- start) / (double) CLOCKS_PER_SEC) << "s" << endl;

    cout << "Querying" << endl;

    start = clock();

    for(int i = 0; i != 1000000; i++) {
        s->contains(i);
    }

    cout << "Done querying" << endl;
    cout << "Time: " << ((clock()- start) / (double) CLOCKS_PER_SEC) << "s" << endl;
    delete s;
}
Example #4
0
/*********************************************************************************************************
** Description: Calculates the difference of two or more sets, returning the set that represents 
** that difference.
**********************************************************************************************************/
IntSet IntSet::getDifference(const IntSet& obj) const
{
	IntSet diffSet = *this; //initialize a new set with the elements of the calling set

	for (int i = 0; i < obj.size(); i++) //loop through the set given as an argument
	{
		if (diffSet.contains(obj.set[i])) //if the current element is in the difference set...
		{
			diffSet.remove(obj.set[i]); //then remove that element from the difference set
		}
	}

	return diffSet; //return the difference set
}
IntSet IntSet::intersect(const IntSet& otherIntSet) const
{
    IntSet tempArray;	 // create a temp IntSet object 
			 // to hold the intersection values
    int tempIndex = 0;
    int strikeCount = 0; // var to count # times that
			 // a value in IntSet does not
			 // match a value in otherIntSet
    bool removeSuccess;  // flag handle to call remove()

    // copy this IntSet into tempArray
    for( int i = 0; i < this->size(); i ++ )
    {
        tempArray.data[tempIndex] = this->data[i];
	tempArray.used ++;
        tempIndex ++;
    }
    
    // remove the contents of tempArray if they're not contained
    // in the intersection of thisIntSet and otherIntSet
    for( int i = 0; i < this->size(); i ++ )
    {
	for( int i2 = 0; i2 < otherIntSet.size(); i2 ++ )
	{
	    if( this->data[i] != otherIntSet.data[i2] )
	        strikeCount ++;
	}

	if( strikeCount == otherIntSet.size() )
	{
	    // strikeCount == otherIntSet.size(), then the
	    // IntSet value was not found in otherIntSet, so
	    // it's not part of the intersection and should be
	    // removed. . . 
	    removeSuccess = ( tempArray.remove(this->data[i]) ); // remove the value
	}

	if( removeSuccess )  // here, i'm just using var f in a statement
	                     // in order to get rid of a compiler warning; 
	    strikeCount = 0; // reset the strike count for the next iteration
	else
	    strikeCount = 0;
        }    
          
    return tempArray; // return intersection values
}