BitsetsNET.BitsetContainer.Flip C# (CSharp) Method

Flip() public method

Add a short to the container if it is not present, otherwise remove it. May generate a new container.
public Flip ( ushort i ) : Container
i ushort short to be added
return Container
        public override Container Flip(ushort i)
        {
            int x = Utility.ToIntUnsigned(i);
            int index = x / 64;
            long bef = Bitmap[index];
            long mask = 1L << x;
            if (Cardinality == ArrayContainer.DEFAULT_MAX_SIZE + 1)
            {// this is
             // the
             // uncommon
             // path
                if ((bef & mask) != 0)
                {
                    --Cardinality;
                    Bitmap[index] &= ~mask;
                    return this.ToArrayContainer();
                }
            }
            // TODO: check whether a branchy version could be faster
            Cardinality += 1 - 2 * (int)((bef & mask) >> x);
            Bitmap[index] ^= mask;
            return this;
        }