Example #1
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, "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);
        }
Example #2
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);
        }