BitsetsNET.RoaringBitset.OrWith C# (CSharp) Method

OrWith() public method

Computes the in-place bitwise OR of this bitset with another
public OrWith ( IBitset otherSet ) : void
otherSet IBitset Other bitset
return void
        public void OrWith(IBitset otherSet)
        {
            if (!(otherSet is RoaringBitset))
            {
                throw new ArgumentOutOfRangeException("otherSet must be a RoaringBitSet");
            }

            RoaringBitset x2 = (RoaringBitset)otherSet;

            int pos1 = 0, pos2 = 0;
            int length1 = this.containers.Size, length2 = x2.containers.Size;

            if (pos1 < length1 && pos2 < length2)
            {
                ushort s1 = this.containers.GetKeyAtIndex(pos1);
                ushort s2 = x2.containers.GetKeyAtIndex(pos2);

                while (true)
                {
                    if (s1 == s2)
                    {
                        Container newContainer = this.containers.GetContainerAtIndex(pos1)
                                                     .IOr(x2.containers.GetContainerAtIndex(pos2));
                        this.containers.SetContainerAtIndex(pos1,newContainer);
                        pos1++;
                        pos2++;
                        if ((pos1 == length1) || (pos2 == length2))
                        {
                            break;
                        }
                        s1 = this.containers.GetKeyAtIndex(pos1);
                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                    else if (s1 < s2)
                    {
                        pos1++;
                        if (pos1 == length1)
                        {
                            break;
                        }
                        s1 = this.containers.GetKeyAtIndex(pos1);
                    }
                    else
                    { // s1 > s2
                        this.containers.InsertNewKeyValueAt(pos1, s2, x2.containers.GetContainerAtIndex(pos2));
                        pos1++;
                        length1++;
                        pos2++;
                        if (pos2 == length2)
                        {
                            break;
                        }
                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                }
            }

            if (pos1 == length1)
            {
                this.containers.AppendCopy(x2.containers, pos2, length2);
            }
        }