Exemplo n.º 1
0
        public bool?GetBoolean(int index)
        {
            if (IsNull(index))
            {
                return(null);
            }

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

                ValueBuffer.Reserve(BitUtility.ByteCount(capacity));
                return(this);
            }
Exemplo n.º 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);
            }
Exemplo n.º 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);
            }
Exemplo n.º 6
0
            public Builder Resize(int length)
            {
                if (length < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(length));
                }

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

            var span = GetSpan();

            return(BitUtility.GetBit(span, index));
        }
Exemplo n.º 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);
            }
Exemplo n.º 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);
 }
Exemplo n.º 14
0
            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));
            }
Exemplo n.º 15
0
 public void Set(int index)
 {
     BitUtility.SetBit(
         Buffer.GetSpan <byte>(), index);
 }
Exemplo n.º 16
0
 public bool IsValid(int index) =>
 NullCount == 0 || NullBitmapBuffer.IsEmpty || BitUtility.GetBit(NullBitmapBuffer.Span, index);
Exemplo n.º 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;
 }
Exemplo n.º 18
0
 public Builder Toggle(int index)
 {
     CheckIndex(index);
     BitUtility.ToggleBit(ValueBuffer.Span, index);
     return(this);
 }
Exemplo n.º 19
0
 public Builder Set(int index, bool value)
 {
     CheckIndex(index);
     BitUtility.SetBit(ValueBuffer.Span, index, value);
     return(this);
 }
Exemplo n.º 20
0
 public bool GetBoolean(int index)
 {
     return(BitUtility.GetBit(Values, index));
 }
Exemplo n.º 21
0
 public void Clear(int index)
 {
     BitUtility.ClearBit(
         Buffer.GetSpan <byte>(), index);
 }
Exemplo n.º 22
0
 public bool?GetValue(int index)
 {
     return(IsNull(index)
         ? (bool?)null
         : BitUtility.GetBit(ValueBuffer.Span, index + Offset));
 }
Exemplo n.º 23
0
 public bool IsSet(int index)
 {
     return(BitUtility.GetBit(
                Buffer.GetSpan <byte>(), index));
 }