Beispiel #1
0
        public bool?GetBoolean(int index)
        {
            if (IsNull(index))
            {
                return(null);
            }

            return(BitUtility.GetBit(Values, index));
        }
Beispiel #2
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);
            }
Beispiel #3
0
            public Builder Reserve(int capacity)
            {
                if (capacity < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(capacity));
                }

                ValueBuffer.Reserve(BitUtility.ByteCount(capacity));
                return(this);
            }
Beispiel #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);
            }
Beispiel #5
0
            /// <summary>
            /// Resize the buffer to a given size.
            /// </summary>
            /// <remarks>
            /// Note that if the required capacity is larger than the current length of the populated buffer so far,
            /// the buffer's contents in the new, expanded region are undefined.
            /// </remarks>
            /// <remarks>
            /// Note that if the required capacity is smaller than the current length of the populated buffer so far,
            /// the buffer will be truncated and items at the end of the buffer will be lost.
            /// </remarks>
            /// <remarks>
            /// Note also that a negative capacity will result in the buffer being resized to zero.
            /// </remarks>
            /// <param name="capacity">Number of bits of required capacity.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Resize(int capacity)
            {
                capacity = capacity < 0 ? 0 : capacity;
                EnsureCapacity(capacity);
                Length = capacity;

                SetBitCount = BitUtility.CountBits(Span, 0, Length);

                return(this);
            }
Beispiel #6
0
            public Builder Resize(int length)
            {
                if (length < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(length));
                }

                ValueBuffer.Resize(BitUtility.ByteCount(length));
                Length = length;
                return(this);
            }
Beispiel #7
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);
 }
Beispiel #8
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);
            }
Beispiel #9
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);
            }
Beispiel #10
0
        public bool?GetBoolean(int index)
        {
            if (IsNull(index))
            {
                return(null);
            }

            var span = GetSpan();

            return(BitUtility.GetBit(span, index));
        }
Beispiel #11
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);
            }
            /// <summary>
            /// Resize the buffer to a given size.
            /// </summary>
            /// <remarks>
            /// Note that if the required capacity is larger than the current length of the populated buffer so far,
            /// the buffer's contents in the new, expanded region are undefined.
            /// </remarks>
            /// <remarks>
            /// Note that if the required capacity is smaller than the current length of the populated buffer so far,
            /// the buffer will be truncated and items at the end of the buffer will be lost.
            /// </remarks>
            /// <param name="capacity">Number of bits of required capacity.</param>
            /// <returns>Returns the builder (for fluent-style composition).</returns>
            public BitmapBuilder Resize(int capacity)
            {
                if (capacity < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be non-negative");
                }

                EnsureCapacity(capacity);
                Length = capacity;

                SetBitCount = BitUtility.CountBits(Span, 0, Length);

                return(this);
            }
Beispiel #13
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);
 }
            private ArrowBuffer ConcatenateBitmapBuffer(int bufferIndex)
            {
                var builder = new ArrowBuffer.BitmapBuilder(_totalLength);

                foreach (ArrayData arrayData in _arrayDataList)
                {
                    int length = arrayData.Length;
                    ReadOnlySpan <byte> span = arrayData.Buffers[bufferIndex].Span;

                    for (int i = 0; i < length; i++)
                    {
                        builder.Append(span.IsEmpty || BitUtility.GetBit(span, i));
                    }
                }

                return(builder.Build(_allocator));
            }
Beispiel #15
0
 public void Set(int index)
 {
     BitUtility.SetBit(
         Buffer.GetSpan <byte>(), index);
 }
Beispiel #16
0
 public bool IsValid(int index) =>
 NullCount == 0 || NullBitmapBuffer.IsEmpty || BitUtility.GetBit(NullBitmapBuffer.Span, index);
Beispiel #17
0
 /// <summary>
 /// Creates an instance of the <see cref="BitmapBuilder"/> class.
 /// </summary>
 /// <param name="capacity">Number of bits of initial capacity to reserve.</param>
 public BitmapBuilder(int capacity = DefaultBitCapacity)
 {
     Memory   = new byte[BitUtility.ByteCount(capacity)];
     Capacity = capacity;
 }
Beispiel #18
0
 public Builder Toggle(int index)
 {
     CheckIndex(index);
     BitUtility.ToggleBit(ValueBuffer.Span, index);
     return(this);
 }
Beispiel #19
0
 public Builder Set(int index, bool value)
 {
     CheckIndex(index);
     BitUtility.SetBit(ValueBuffer.Span, index, value);
     return(this);
 }
Beispiel #20
0
 public bool GetBoolean(int index)
 {
     return(BitUtility.GetBit(Values, index));
 }
Beispiel #21
0
 public void Clear(int index)
 {
     BitUtility.ClearBit(
         Buffer.GetSpan <byte>(), index);
 }
Beispiel #22
0
 public bool?GetValue(int index)
 {
     return(IsNull(index)
         ? (bool?)null
         : BitUtility.GetBit(ValueBuffer.Span, index + Offset));
 }
Beispiel #23
0
 public bool IsSet(int index)
 {
     return(BitUtility.GetBit(
                Buffer.GetSpan <byte>(), index));
 }