BitsetsNET.ArrayContainer.Flip C# (CSharp) Method

Flip() public method

If elements is present in container, add it. Otherwise, remove it.
public Flip ( ushort x ) : Container
x ushort Element to add
return Container
        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;
        }