예제 #1
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 length1 = containers.size, length2 = otherSet.containers.size;

            while (pos1 < length1 && pos2 < length2)
            {
                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 < length1)
            {
                containers.copyRange(pos1, length1, intersectionSize);
                intersectionSize += length1 - pos1;
            }
            containers.resize(intersectionSize);
        }