Resize() 공개 메소드

Logically resizes the Roaring Array after an in-place operation. Fills all keys and values after its new last index with zeros and null, respectively, and changes the size to the new size.
public Resize ( int newSize ) : void
newSize int the new size of the roaring array
리턴 void
예제 #1
0
        /// <summary>
        /// Performs an in-place intersection of two Roaring Bitsets.
        /// </summary>
        /// <param name="other">the second Roaring Bitset to intersect</param>
        private void AndWith(RoaringBitset other)
        {
            int thisLength = containers.Size;
            int otherLength = other.containers.Size;
            int pos1 = 0, pos2 = 0, intersectionSize = 0;

            while (pos1 < thisLength && pos2 < otherLength)
            {
                ushort s1 = containers.GetKeyAtIndex(pos1);
                ushort s2 = other.containers.GetKeyAtIndex(pos2);

                if (s1 == s2)
                {
                    Container c1 = containers.GetContainerAtIndex(pos1);
                    Container c2 = other.containers.GetContainerAtIndex(pos2);
                    Container c  = c1.IAnd(c2);

                    if (c.GetCardinality() > 0)
                    {
                        containers.ReplaceKeyAndContainerAtIndex(intersectionSize++, s1, c);
                    }

                    ++pos1;
                    ++pos2;
                }
                else if (s1 < s2)
                {
                    // s1 < s2
                    pos1 = containers.AdvanceUntil(s2, pos1);
                }
                else
                {
                    // s1 > s2
                    pos2 = other.containers.AdvanceUntil(s1, pos2);
                }
            }

            containers.Resize(intersectionSize);
        }
예제 #2
0
        /// <summary>
        /// Finds members of this bitset that are not in the other set (ANDNOT).
        /// Modifies current bitset in place.
        /// </summary>
        /// <param name="otherSet">The set to compare against</param>
        public void IAndNot(RoaringBitset otherSet)
        {
            int pos1 = 0, pos2 = 0, intersectionSize = 0;
            int thisSize     = containers.Size;
            int otherSetSize = otherSet.containers.Size;

            while (pos1 < thisSize && pos2 < otherSetSize)
            {
                ushort s1 = containers.GetKeyAtIndex(pos1);
                ushort s2 = otherSet.containers.GetKeyAtIndex(pos2);
                if (s1 == s2)
                {
                    Container c1 = containers.GetContainerAtIndex(pos1);
                    Container c2 = otherSet.containers.GetContainerAtIndex(pos2);
                    Container c  = c1.IAndNot(c2);
                    if (c.GetCardinality() > 0)
                    {
                        containers.ReplaceKeyAndContainerAtIndex(intersectionSize++, s1, c);
                    }
                    ++pos1;
                    ++pos2;
                }
                else if (Utility.CompareUnsigned(s1, s2) < 0)
                { // s1 < s2
                    if (pos1 != intersectionSize)
                    {
                        Container c1 = containers.GetContainerAtIndex(pos1);
                        containers.ReplaceKeyAndContainerAtIndex(intersectionSize, s1, c1);
                    }
                    ++intersectionSize;
                    ++pos1;
                }
                else
                { // s1 > s2
                    pos2 = otherSet.containers.AdvanceUntil(s1, pos2);
                }
            }
            if (pos1 < thisSize)
            {
                containers.CopyRange(pos1, thisSize, intersectionSize);
                intersectionSize += thisSize - pos1;
            }
            containers.Resize(intersectionSize);
        }