public override Container Add(ushort x)
{
int loc = Utility.UnsignedBinarySearch(Content, 0, Cardinality, x);
// if the location is positive, it means the number being added already existed in the
// array, so no need to do anything.
// if the location is negative, we did not find the value in the array. The location represents
// the negative value of the position in the array (not the index) where we want to add the value
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 its appropriate place
Array.Copy(Content, -loc - 1, Content, -loc, Cardinality + loc + 1);
Content[-loc - 1] = x;
++Cardinality;
}
return this;
}