Пример #1
0
 /// <summary>
 /// Performs a bitwise XOR between the bits of this
 /// <see cref="BitArrayNeo"/> and <paramref name="x"/>,
 /// modifying the former.
 /// </summary>
 /// <param name="x">The other bit array.</param>
 /// <returns>Whether the content of this bit array actually changed.</returns>
 /// <exception cref="ArgumentException">The bit arrays have different <see cref="BitCapacity"/>ies.</exception>
 public bool Xor(BitArrayNeo x)
 {
     if (_bitCapacity != x._bitCapacity)
     {
         ThrowDifferentCapacity(nameof(x));
     }
     return(BitAlgorithms.Xor(_data.AsSpan(), x._data.AsSpan()));
 }
Пример #2
0
        /// <summary>
        /// Compares this <see cref="BitArrayNeo"/>
        /// with a <see cref="BitSet"/> to see if they are equal.
        /// </summary>
        /// <param name="other">The bit set.</param>
        /// <returns>Whether they are equal.</returns>
        /// <remarks>The <see cref="BitCapacity"/> of this
        /// bit array is not taken into account.</remarks>
        public bool Equals(BitSet other)
        {
            if (_data.Length == 0)
            {
                return(other.IsEmpty);
            }
            ReadOnlySpan <ulong> extra = _data.AsSpan(1);

            extra = BitAlgorithms.TrimTrailingZeroes(extra);
            return(_data[0] == other.Data && extra.SequenceEqual(other.Extra));
        }
Пример #3
0
        /// <summary>
        /// Converts this <see cref="BitArrayNeo"/> to a <see cref="BitSet"/>.
        /// </summary>
        public BitSet ToBitSet()
        {
            if (_data.Length == 0)
            {
                return(BitSet.Empty);
            }
            ReadOnlySpan <ulong> extra = _data.AsSpan(1);

            extra = BitAlgorithms.TrimTrailingZeroes(extra);
            return(new BitSet(_data[0], extra.ToArray()));
        }
Пример #4
0
 /// <summary>
 /// Inverts all the bits of this <see cref="BitArrayNeo"/>.
 /// </summary>
 public void Not()
 {
     if (_data.Length == 0)
     {
         return;
     }
     BitAlgorithms.Not(_data.AsSpan());
     // The unused bits at the last cell are reset to zero.
     // This allows easy comparison and conversion to BitSet
     // and they cannot be changed from any other place.
     _data[_data.Length - 1] &= (1ul << _bitCapacity) - 1;
 }
Пример #5
0
 /// <inheritdoc/>
 public override string ToString() =>
 _data.Length == 0 ? string.Empty : BitAlgorithms.FormatBitArray(_data[0], _data.AsSpan(1));