AppendCopy() public method

Append copy of the one value from another array
public AppendCopy ( RoaringArray sa, int index ) : void
sa RoaringArray Other array
index int Index in the other array
return void
コード例 #1
0
        /// <summary>
        /// Computes the in-place bitwise OR of this bitset with another
        /// </summary>
        /// <param name="otherSet">Other bitset</param>
        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 = containers.Size, length2 = x2.containers.Size;

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

                while (true)
                {
                    if (s1 == s2)
                    {
                        Container newContainer = containers.GetContainerAtIndex(pos1).IOr(x2.containers.GetContainerAtIndex(pos2));
                        containers.SetContainerAtIndex(pos1, newContainer);
                        pos1++;
                        pos2++;
                        if (pos1 == length1 || pos2 == length2)
                        {
                            break;
                        }

                        s1 = containers.GetKeyAtIndex(pos1);
                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                    else if (s1 < s2)
                    {
                        pos1++;
                        if (pos1 == length1)
                        {
                            break;
                        }

                        s1 = containers.GetKeyAtIndex(pos1);
                    }
                    else
                    {
                        // s1 > s2
                        containers.InsertNewKeyValueAt(pos1, s2, x2.containers.GetContainerAtIndex(pos2));
                        pos1++;
                        length1++;
                        pos2++;
                        if (pos2 == length2)
                        {
                            break;
                        }

                        s2 = x2.containers.GetKeyAtIndex(pos2);
                    }
                }
            }

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