Ejemplo n.º 1
0
        /// <summary>
        /// Add to 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 add(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);

            for (ushort hb = hbStart; hb <= hbLast; ++hb)
            {

                // first container may contain partial range
                ushort containerStart = 0;
                if (hb == hbStart) { containerStart = lbStart; }

                // last container may contain partial range
                ushort containerLast = (hb == hbLast) ? lbLast : ushort.MaxValue;
                int containerIndex = containers.getIndex(hb);

                if (containerIndex >= 0)
                {
                    Container c = containers.getContainerAtIndex(containerIndex).add(
                                   containerStart, (ushort)(containerLast + 1));
                    containers.setContainerAtIndex(containerIndex, c);
                }
                else {
                    Container newContainer = new ArrayContainer(100);
                    newContainer = newContainer.add(lbStart, lbLast);
                    containers.insertNewKeyValueAt(-containerIndex - 1, hb, newContainer);
                }
            }
        }
Ejemplo n.º 2
0
        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 newac = new ArrayContainer();
                containers.insertNewKeyValueAt(-containerIndex - 1, highBits, newac.add(Utility.GetLowBits(x)));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add to 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 add(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);

            for (ushort hb = hbStart; hb <= hbLast; ++hb)
            {
                // first container may contain partial range
                ushort containerStart = 0;
                if (hb == hbStart)
                {
                    containerStart = lbStart;
                }

                // last container may contain partial range
                ushort containerLast  = (hb == hbLast) ? lbLast : ushort.MaxValue;
                int    containerIndex = containers.getIndex(hb);

                if (containerIndex >= 0)
                {
                    Container c = containers.getContainerAtIndex(containerIndex).add(
                        containerStart, (ushort)(containerLast + 1));
                    containers.setContainerAtIndex(containerIndex, c);
                }
                else
                {
                    Container newContainer = new ArrayContainer(100);
                    newContainer = newContainer.add(lbStart, lbLast);
                    containers.insertNewKeyValueAt(-containerIndex - 1, hb, newContainer);
                }
            }
        }
Ejemplo n.º 4
0
        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 newac = new ArrayContainer();
                containers.insertNewKeyValueAt(-containerIndex - 1, highBits, newac.add(Utility.GetLowBits(x)));
            }

        }
Ejemplo n.º 5
0
        public void Flip(int x)
        {
            ushort hb = Utility.GetHighBits(x);
            int i = containers.getIndex(hb);

            if (i >= 0)
            {
                Container c = containers.getContainerAtIndex(i).flip(Utility.GetLowBits(x));
                if (c.getCardinality() > 0)
                {
                    containers.setContainerAtIndex(i, c);
                }
                else
                {
                    containers.removeAtIndex(i);
                }
            }
            else
            {
                ArrayContainer newac = new ArrayContainer();
                containers.insertNewKeyValueAt(-i - 1, hb, newac.add(Utility.GetLowBits(x)));
            }
        }