#ifndef _UINTSET_h
#define _UINTSET_h
#include <iostream>
#include "bitvect.h"
class UIntSet
{
public:
UIntSet(unsignedlong = 64); // construct an empty set of specified element size range
UIntSet(const UIntSet&);
~UIntSet();
void Insert(unsignedlong n); // inserts n into set
void Remove(unsigned longn); // removes n from set
void Clear() const; // makes set empty
bool Member(unsignedlong n) const; // returns true iff n is in set
bool Empty() const; // true iff set is empty;
size_t Size() const; // returns number of elements in set
size_t Range() const; // returns upper bound of range/universe [0, ub]
UIntSet& operator = (const UIntSet& s); // set = s (assignment operator)
UIntSet& operator += (const UIntSet& s); // set = set union s
UIntSet& operator *= (const UIntSet& s); // set intersection s
UIntSet& operator -= (const UIntSet& s); // set = set difference s
private:
size_t size_; // the size of current set
fsu::BitVector bv_; // bit vector representing set
};
// Global Operators:
UIntSet operator + (const UIntSet& s1, const UIntSet& s2); // returns s1 union s2
UIntSet operator * (const UIntSet& s1, const UIntSet& s2); // returns s1 intersection s2
UIntSet operator - (const UIntSet& s1, const UIntSet& s2); // returns s1 difference s2
std::ostream& operator<< (std::ostream os, const UIntSet& s); // output operator
#endif
The first error I'm getting is that I can't delete [] bv_
Then for bv_ = new unsigned char[size_], it's telling me no viable overload for =....isn't that what I'm trying to do here? How can it already be there if I'm trying to create it?
I tried starting this assignment in a couple different places, but a I was trying to implement functions, I kept getting errors about operator= overload, so I started over and I'm guessing I need to start with this implementation. Any advice would be greatly appreciated, as I am lost.
void BitVector::Unset (size_t index)
// make bit = 0: AND with inverted mask
{
byteArray_[ByteNumber(index)] &= ~ Mask(index);
}
void BitVector::Flip ()
// change all bit values
{
for (size_t i = 0; i < byteArraySize_; ++i)
byteArray_[i] ^= 0xFF;
}
void BitVector::Flip (size_t index)
// change bit value: XOR with mask
{
byteArray_[ByteNumber(index)] ^= Mask(index);
}
bool BitVector::Test (size_t index) const
// return bit value
{
return 0 != (byteArray_[ByteNumber(index)] & Mask(index));
}
// private methods
size_t BitVector::ByteNumber (size_t index) const
{
// return index / 8
// shift right 3 is equivalent to, and faster than, dividing by 8
index = index >> 3;
if (index >= byteArraySize_)
{
std::cerr << "** BitVector error: index out of range\n";
exit (EXIT_FAILURE);
}
return index;
}
unsignedchar BitVector::Mask (size_t index)
{
// return mask for index % 8
// the low order 3 bits is the remainder when dividing by 8
size_t shiftamount = index & (size_t)0x07; // low order 3 bits
return (unsignedchar)0x01 << shiftamount;
}
} // namespace fsu
#endif