public override Container Flip(ushort x)
{
int loc = Utility.UnsignedBinarySearch(Content, 0, Cardinality, x);
if (loc < 0)
{
// Transform the ArrayContainer to a BitmapContainer
// when cardinality = DEFAULT_MAX_SIZE
if (Cardinality >= DEFAULT_MAX_SIZE)
{
BitsetContainer a = this.ToBitsetContainer();
a.Add(x);
return a;
}
if (Cardinality >= this.Content.Length)
{
IncreaseCapacity();
}
// insertion : shift the elements > x by one position to
// the right
// and put x in it's appropriate place
Array.Copy(Content, -loc - 1, Content, -loc, Cardinality + loc + 1);
Content[-loc - 1] = x;
++Cardinality;
}
else
{
Array.Copy(Content, loc + 1, Content, loc, Cardinality - loc - 1);
--Cardinality;
}
return this;
}