public override bool Equals(object obj) {
// assume the same type
if (obj != null) {
if (this == obj) {
return true;
}
BitSet other = (BitSet) obj;
int bitsLength = bits.Length;
int setLength = other.bits.Length;
int n = (bitsLength > setLength) ? setLength : bitsLength;
for (int i = n ; i-- > 0 ;) {
if (bits[i] != other.bits[i]) {
return false;
}
}
if (bitsLength > n) {
for (int i = bitsLength ; i-- > n ;) {
if (bits[i] != 0) {
return false;
}
}
}
else {
for (int i = setLength ; i-- > n ;) {
if (other.bits[i] != 0) {
return false;
}
}
}
return true;
}
return false;
}