BitsetsNET.ArrayContainer.Add C# (CSharp) Метод

Add() публичный Метод

Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
public Add ( ushort x ) : Container
x ushort Other container
Результат Container
        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;
        }

Same methods

ArrayContainer::Add ( ushort rangeStart, ushort rangeEnd ) : Container

Usage Example

Пример #1
0
        /// <summary>
        /// Adds the specified value to the current bitmap
        /// </summary>
        /// <param name="x">Value to be added</param>
        public void Add(int x)
        {
            ushort highBits       = Utility.GetHighBits(x);
            int    containerIndex = containers.GetIndex(highBits);

            if (containerIndex >= 0)
            {
                // a container exists at this index already.
                // find the right container, get the low order bits to add to the container and add them
                containers.SetContainerAtIndex(containerIndex, containers.GetContainerAtIndex(containerIndex).Add(Utility.GetLowBits(x)));
            }
            else
            {
                // no container exists for this index
                // create a new ArrayContainer, since it will only hold one integer to start
                // get the low order bits and att to the newly created container
                // add the newly created container to the array of containers
                ArrayContainer ac = new ArrayContainer();
                containers.InsertNewKeyValueAt(-containerIndex - 1, highBits, ac.Add(Utility.GetLowBits(x)));
            }
        }
All Usage Examples Of BitsetsNET.ArrayContainer::Add