Example #1
0
 public Builder Set(int index, bool value)
 {
     CheckIndex(index);
     BitUtility.SetBit(ValueBuffer.Span, index, value);
     BitUtility.SetBit(ValidityBuffer.Span, index, true);
     return(this);
 }
Example #2
0
 public Builder Toggle(int index)
 {
     CheckIndex(index);
     BitUtility.ToggleBit(ValueBuffer.Span, index);
     BitUtility.SetBit(ValidityBuffer.Span, index, true);
     return(this);
 }
Example #3
0
            /// <summary>
            /// Set the bit at a particular index to 1.
            /// </summary>
            /// <param name="index">Index of bit to set.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Set(int index)
            {
                CheckIndex(index);
                bool priorValue = BitUtility.GetBit(Span, index);

                SetBitCount += priorValue ? 0 : 1;
                BitUtility.SetBit(Span, index);
                return(this);
            }
Example #4
0
            /// <summary>
            /// Set the bit at a particular index to a given value.
            /// </summary>
            /// <param name="index">Index of bit to set/unset.</param>
            /// <param name="value">Value of bit.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Set(int index, bool value)
            {
                CheckIndex(index);
                bool priorValue = BitUtility.GetBit(Span, index);

                SetBitCount -= priorValue ? 1 : 0;
                SetBitCount += value ? 1 : 0;
                BitUtility.SetBit(Span, index, value);
                return(this);
            }
Example #5
0
            /// <summary>
            /// Swap the bits at two given indices.
            /// </summary>
            /// <param name="i">First index.</param>
            /// <param name="j">Second index.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Swap(int i, int j)
            {
                CheckIndex(i);
                CheckIndex(j);
                bool bi = BitUtility.GetBit(Span, i);
                bool bj = BitUtility.GetBit(Span, j);

                BitUtility.SetBit(Span, i, bj);
                BitUtility.SetBit(Span, j, bi);
                return(this);
            }
Example #6
0
 public Builder Append(bool value)
 {
     if (Length % 8 == 0)
     {
         // append a new byte to the buffer when needed
         ValueBuffer.Append(0);
     }
     BitUtility.SetBit(ValueBuffer.Span, Length, value);
     Length++;
     return(this);
 }
Example #7
0
            public Builder Swap(int i, int j)
            {
                CheckIndex(i);
                CheckIndex(j);
                var bi = BitUtility.GetBit(ValueBuffer.Span, i);
                var bj = BitUtility.GetBit(ValueBuffer.Span, j);

                BitUtility.SetBit(ValueBuffer.Span, i, bj);
                BitUtility.SetBit(ValueBuffer.Span, j, bi);
                return(this);
            }
Example #8
0
            /// <summary>
            /// Append a single bit.
            /// </summary>
            /// <param name="value">Bit to append.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Append(bool value)
            {
                if (Length % 8 == 0)
                {
                    // Append a new byte to the buffer when needed.
                    EnsureAdditionalCapacity(1);
                }

                BitUtility.SetBit(Span, Length, value);
                Length++;
                SetBitCount += value ? 1 : 0;
                return(this);
            }
Example #9
0
 private Builder NullableAppend(bool?value)
 {
     if (Length % 8 == 0)
     {
         // append a new byte to the buffer when needed
         ValueBuffer.Append(0);
         ValidityBuffer.Append(0);
     }
     BitUtility.SetBit(ValueBuffer.Span, Length, value.GetValueOrDefault());
     BitUtility.SetBit(ValidityBuffer.Span, Length, value.HasValue);
     NullCount += value.HasValue ? 0 : 1;
     Length++;
     return(this);
 }
Example #10
0
 public void Set(int index)
 {
     BitUtility.SetBit(
         Buffer.GetSpan <byte>(), index);
 }
Example #11
0
 public Builder Set(int index)
 {
     CheckIndex(index);
     BitUtility.SetBit(ValueBuffer.Span, index);
     return(this);
 }