예제 #1
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);
        }