コード例 #1
0
ファイル: BitList.cs プロジェクト: zyj0021/Cyjb
        /// <summary>
        /// 将指定集合中的元素插入 <see cref="BitList"/> 的指定索引处。
        /// </summary>
        /// <param name="index">应在此处插入新元素的从零开始的索引。</param>
        /// <param name="collection">一个集合,应将其元素插入到
        /// <see cref="BitList"/> 中。</param>
        /// <exception cref="ArgumentNullException"><paramref name="collection"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> 小于 <c>0</c>。</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> 大于 <see cref="Count"/>。</exception>
        public void InsertRange(int index, IEnumerable <bool> collection)
        {
            CommonExceptions.CheckArgumentNull(collection, "collection");
            if (index < 0)
            {
                throw CommonExceptions.ArgumentNegative("index", index);
            }
            if (index > this.count)
            {
                throw CommonExceptions.ArgumentOutOfRange("index", index);
            }
            Contract.EndContractBlock();
            IList <uint> uintList;
            int          length = 0;
            BitList      bList  = collection as BitList;

            if (bList != null)
            {
                length   = bList.count;
                uintList = bList.items;
            }
            else
            {
                uintList = new List <uint>();
                uint value = 0U;
                int  j     = 0;
                foreach (bool b in collection)
                {
                    if (b)
                    {
                        value |= 1U << j;
                    }
                    j++;
                    length++;
                    if (j == UnitSize)
                    {
                        uintList.Add(value);
                        value = 0U;
                        j     = 0;
                    }
                }
                if (j > 0)
                {
                    uintList.Add(value);
                }
            }
            this.InsertRange(index, length, uintList);
        }
コード例 #2
0
ファイル: BitList.cs プロジェクト: zyj0021/Cyjb
        /// <summary>
        /// 对当前 <see cref="BitList"/> 中的元素和指定的
        /// <see cref="BitList"/> 中的相应元素执行按位“异或”运算。
        /// </summary>
        /// <param name="list">要对其执行按位“异或”运算的
        /// <see cref="BitList"/>。</param>
        /// <returns>当前实例,包含对当前 <see cref="BitList"/>
        /// 中的元素和指定的 <see cref="BitList"/>
        /// 中的相应元素执行按位“异或”运算的结果。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="list"/>
        /// 为 <c>null</c>。</exception>
        /// <exception cref="System.ArgumentException"><paramref name="list"/>
        /// 和当前 <see cref="BitList"/> 的元素数不同。</exception>
        public BitList Xor(BitList list)
        {
            CommonExceptions.CheckArgumentNull(list, "list");
            if (list.count != this.count)
            {
                throw CommonExceptions.CollectionCountDiffer("list");
            }
            Contract.EndContractBlock();
            int cnt = this.count >> IndexShift;

            for (int i = 0; i <= cnt; i++)
            {
                this.items[i] ^= list.items[i];
            }
            return(this);
        }
コード例 #3
0
        /// <summary>
        /// 对当前 <see cref="BitList"/> 中的元素和指定的
        /// <see cref="BitList"/> 中的相应元素执行按位“异或”运算。
        /// </summary>
        /// <param name="list">要对其执行按位“异或”运算的
        /// <see cref="BitList"/>。</param>
        /// <returns>当前实例,包含对当前 <see cref="BitList"/>
        /// 中的元素和指定的 <see cref="BitList"/>
        /// 中的相应元素执行按位“异或”运算的结果。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="list"/>
        /// 为 <c>null</c>。</exception>
        /// <exception cref="System.ArgumentException"><paramref name="list"/>
        /// 和当前 <see cref="BitList"/> 的元素数不同。</exception>
        public BitList Xor(BitList list)
        {
            CommonExceptions.CheckArgumentNull(list, nameof(list));
            if (list._count != _count)
            {
                throw CommonExceptions.CollectionCountDiffer(nameof(list));
            }
            Contract.EndContractBlock();
            var cnt = _count >> IndexShift;

            for (var i = 0; i <= cnt; i++)
            {
                _items[i] ^= list._items[i];
            }
            return(this);
        }
コード例 #4
0
ファイル: BitList.cs プロジェクト: zyj0021/Cyjb
        /// <summary>
        /// 判断与其它的列表是否内容相同。
        /// </summary>
        /// <param name="list">要判断的列表。</param>
        /// <returns>如果内容相同,则为 <c>true</c>;否则为 <c>false</c>。</returns>
        public bool ContentEquals(BitList list)
        {
            if (list == null || this.count != list.count)
            {
                return(false);
            }
            int end = this.count >> IndexShift;

            for (int i = 0; i < end; i++)
            {
                if (this.items[i] != list.items[i])
                {
                    return(false);
                }
            }
            uint value  = this.items[end];
            uint value2 = list.items[end];

            end = this.count - (end << IndexShift);
            uint mask = GetMask(end);

            return((value & mask) == (value2 & mask));
        }
コード例 #5
0
        /// <summary>
        /// 判断与其它的列表是否内容相同。
        /// </summary>
        /// <param name="list">要判断的列表。</param>
        /// <returns>如果内容相同,则为 <c>true</c>;否则为 <c>false</c>。</returns>
        public bool ContentEquals([CanBeNull] BitList list)
        {
            if (list == null || _count != list._count)
            {
                return(false);
            }
            var end = _count >> IndexShift;

            for (var i = 0; i < end; i++)
            {
                if (_items[i] != list._items[i])
                {
                    return(false);
                }
            }
            var value  = _items[end];
            var value2 = list._items[end];

            end = _count - (end << IndexShift);
            var mask = GetMask(end);

            return((value & mask) == (value2 & mask));
        }