SetContainerAtIndex() public method

public SetContainerAtIndex ( int i, Container c ) : void
i int
c Container
return void
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)));
            }
        }
Example #2
0
        /// <summary>
        /// Remove from the current bitmap all integers in [rangeStart,rangeEnd).
        /// </summary>
        /// <param name="rangeStart">inclusive beginning of range</param>
        /// <param name="rangeEnd">exclusive ending of range</param>
        public void Remove(int rangeStart, int rangeEnd)
        {
            if (rangeStart >= rangeEnd)
            {
                return; // empty range
            }

            ushort hbStart = Utility.GetHighBits(rangeStart);
            ushort lbStart = Utility.GetLowBits(rangeStart);
            ushort hbLast  = Utility.GetHighBits(rangeEnd - 1);
            ushort lbLast  = Utility.GetLowBits(rangeEnd - 1);

            if (hbStart == hbLast)
            {
                int containerIndex = containers.GetIndex(hbStart);

                if (containerIndex < 0)
                {
                    return;
                }

                Container c = containers.GetContainerAtIndex(containerIndex)
                              .Remove(lbStart, (ushort)(lbLast + 1));

                if (c.GetCardinality() > 0)
                {
                    containers.SetContainerAtIndex(containerIndex, c);
                }
                else
                {
                    containers.RemoveAtIndex(containerIndex);
                }
                return;
            }

            int ifirst = containers.GetIndex(hbStart);
            int ilast  = containers.GetIndex(hbLast);

            if (ifirst >= 0)
            {
                if (lbStart != 0)
                {
                    Container c = containers.GetContainerAtIndex(ifirst)
                                  .Remove(lbStart, ushort.MaxValue);

                    if (c.GetCardinality() > 0)
                    {
                        containers.SetContainerAtIndex(ifirst, c);
                        ifirst++;
                    }
                }
            }
            else
            {
                ifirst = -ifirst - 1;
            }

            if (ilast >= 0)
            {
                if (lbLast != ushort.MaxValue)
                {
                    Container c = containers.GetContainerAtIndex(ilast)
                                  .Remove(0, (ushort)(lbLast + 1));

                    if (c.GetCardinality() > 0)
                    {
                        containers.SetContainerAtIndex(ilast, c);
                    }
                    else
                    {
                        ilast++;
                    }
                }
                else
                {
                    ilast++;
                }
            }
            else
            {
                ilast = -ilast - 1;
            }

            containers.RemoveIndexRange(ifirst, ilast);
        }