public IBitset AndNot(RoaringBitset otherSet)
{
RoaringBitset answer = new RoaringBitset();
int pos1 = 0, pos2 = 0;
int length1 = containers.Size, length2 = otherSet.containers.Size;
while (pos1 < length1 && pos2 < length2)
{
ushort s1 = containers.GetKeyAtIndex(pos1);
ushort s2 = otherSet.containers.GetKeyAtIndex(pos2);
if (s1 == s2)
{
Container c1 = containers.GetContainerAtIndex(pos1);
Container c2 = otherSet.containers.GetContainerAtIndex(pos2);
Container c = c1.AndNot(c2);
if (c.GetCardinality() > 0)
{
answer.containers.Append(s1, c);
}
++pos1;
++pos2;
}
else if (Utility.CompareUnsigned(s1, s2) < 0)
{ // s1 < s2
int nextPos1 = containers.AdvanceUntil(s2, pos1);
answer.containers.AppendCopy(containers, pos1, nextPos1);
pos1 = nextPos1;
}
else
{ // s1 > s2
pos2 = otherSet.containers.AdvanceUntil(s1, pos2);
}
}
if (pos2 == length2)
{
answer.containers.AppendCopy(containers, pos1, length1);
}
return answer;
}