BitsetsNET.RoaringBitset.Or C# (CSharp) Method

Or() public method

Creates a new bitset that is the bitwise OR of this bitset with another
public Or ( IBitset otherSet ) : IBitset
otherSet IBitset Other bitset
return IBitset
        public IBitset Or(IBitset otherSet)
        {
            if (!(otherSet is RoaringBitset))
            {
                throw new ArgumentOutOfRangeException("otherSet must be a RoaringBitSet");
            }

            RoaringBitset answer = new RoaringBitset();
            RoaringBitset x2 = (RoaringBitset) otherSet;

            int pos1 = 0, pos2 = 0;
            int thisSize = this.containers.Size;
            int otherSetSize = x2.containers.Size;

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

                while (true)
                {
                    if (s1 == s2)
                    {
                        Container newContainer = this.containers.GetContainerAtIndex(pos1)
                                                     .Or(x2.containers.GetContainerAtIndex(pos2));
                        answer.containers.Append(s1, newContainer);
                        pos1++;
                        pos2++;
                        if ((pos1 == thisSize) || (pos2 == otherSetSize))
                        {
                            break;
                        }
                        s1 = this.containers.GetKeyAtIndex(pos1);
                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                    else if (s1 < s2)
                    {
                        answer.containers.AppendCopy(this.containers, pos1);
                        pos1++;
                        if (pos1 == thisSize)
                        {
                            break;
                        }
                        s1 = this.containers.GetKeyAtIndex(pos1);
                    }
                    else // s1 > s2
                    {
                        answer.containers.AppendCopy(x2.containers, pos2);
                        pos2++;
                        if (pos2 == otherSetSize)
                        {
                            break;
                        }
                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                }
            }

            if (pos1 == thisSize)
            {
                answer.containers.AppendCopy(x2.containers, pos2, otherSetSize);
            }
            else if (pos2 == otherSetSize)
            {
                answer.containers.AppendCopy(this.containers, pos1, thisSize);
            }

            return answer;
        }

Usage Example

Example #1
0
 public static RoaringBitset Or(RoaringBitset x1, RoaringBitset x2)
 {
     return((RoaringBitset)x1.Or(x2));
 }