コード例 #1
0
    /// <summary>Copies the items of the stack to a span.</summary>
    /// <param name="destination">The span to which the items will be copied.</param>
    /// <exception cref="ArgumentOutOfRangeException"><see cref="Count" /> is greater than the length of <paramref name="destination" />.</exception>
    public readonly void CopyTo(UnmanagedSpan <T> destination)
    {
        var count = Count;

        if (count != 0)
        {
            ThrowIfNotInInsertBounds(count, destination.Length);
            CopyArrayUnsafe(destination.GetPointerUnsafe(0), _items.GetPointerUnsafe(0), count);
        }
    }
コード例 #2
0
    /// <summary>Copies the items in the span to a given destination.</summary>
    /// <param name="destination">The destination array where the items should be copied.</param>
    /// <exception cref="ArgumentNullException"><paramref name="destination" /> is <c>null</c>.</exception>
    /// <exception cref="ArgumentOutOfRangeException"><see cref="Length" /> is greater than <paramref name="destination" />.</exception>
    public void CopyTo(UnmanagedArray <T> destination)
    {
        var items  = _items;
        var length = _length;

        ThrowIfNull(destination);
        ThrowIfNotInInsertBounds(length, destination.Length);

        CopyArrayUnsafe(destination.GetPointerUnsafe(0), items, length);
    }
コード例 #3
0
    /// <summary>Copies the items in the array to a given destination.</summary>
    /// <param name="destination">The destination array where the items should be copied.</param>
    /// <exception cref="ArgumentNullException"><paramref name="destination" /> is <c>null</c>.</exception>
    /// <exception cref="ArgumentOutOfRangeException"><see cref="Length" /> is greater than <paramref name="destination" />.</exception>
    public void CopyTo(UnmanagedArray <T> destination)
    {
        AssertNotNull(this);

        var items  = &_data->Item;
        var length = _data->Length;

        ThrowIfNull(destination);
        ThrowIfNotInInsertBounds(length, destination.Length);

        CopyArrayUnsafe(destination.GetPointerUnsafe(0), items, length);
    }
コード例 #4
0
 /// <summary>Initializes a new instance of the <see cref="UnmanagedSpan{T}" /> struct.</summary>
 /// <param name="array">The array to create the span for.</param>
 public UnmanagedSpan(UnmanagedArray <T> array)
 {
     if (!array.IsNull)
     {
         _length = array.Length;
         _items  = array.GetPointerUnsafe(0);
     }
     else
     {
         this = Empty;
     }
 }
コード例 #5
0
    /// <summary>Copies the items of the queue to a span.</summary>
    /// <param name="destination">The span to which the items will be copied.</param>
    /// <exception cref="ArgumentOutOfRangeException"><see cref="Count" /> is greater than the length of <paramref name="destination" />.</exception>
    public readonly void CopyTo(UnmanagedSpan <T> destination)
    {
        var count = Count;

        if (count != 0)
        {
            ThrowIfNotInInsertBounds(count, destination.Length);

            var head = _head;
            var tail = _tail;

            if ((head < tail) || (tail == 0))
            {
                CopyArrayUnsafe(destination.GetPointerUnsafe(0), _items.GetPointerUnsafe(head), count);
            }
            else
            {
                var headLength = count - head;
                CopyArrayUnsafe(destination.GetPointerUnsafe(0), _items.GetPointerUnsafe(head), headLength);
                CopyArrayUnsafe(destination.GetPointerUnsafe(headLength), _items.GetPointerUnsafe(0), tail);
            }
        }
    }
コード例 #6
0
    /// <summary>Initializes a new instance of the <see cref="UnmanagedSpan{T}" /> struct.</summary>
    /// <param name="array">The array to create the span for.</param>
    /// <param name="start">The index of <paramref name="array" /> at which the span should start.</param>
    /// <exception cref="ArgumentOutOfRangeException"><paramref name="start" /> is greater than or equal to the length of <paramref name="array" />.</exception>
    /// <exception cref="ArgumentOutOfRangeException"><paramref name="array" /> is null and <paramref name="start" /> is not <c>zero</c>.</exception>
    public UnmanagedSpan(UnmanagedArray <T> array, nuint start)
    {
        if (!array.IsNull)
        {
            ThrowIfNotInBounds(start, array.Length);

            _length = array.Length - start;
            _items  = array.GetPointerUnsafe(start);
        }
        else
        {
            ThrowIfNotZero(start);
            this = Empty;
        }
    }
コード例 #7
0
    /// <summary>Initializes a new instance of the <see cref="UnmanagedValueStack{T}" /> struct.</summary>
    /// <param name="array">The array that is used to populate the stack.</param>
    /// <param name="takeOwnership"><c>true</c> if the stack should take ownership of the array; otherwise, <c>false</c>.</param>
    /// <exception cref="ArgumentNullException"><paramref name="array" /> is <c>null</c>.</exception>
    /// <remarks>By default ownership of <paramref name="array" /> is given to the value stack.</remarks>
    public UnmanagedValueStack(UnmanagedArray <T> array, bool takeOwnership = true)
    {
        ThrowIfNull(array);

        if (takeOwnership)
        {
            _items = array;
        }
        else
        {
            var items = new UnmanagedArray <T>(array.Length, array.Alignment);
            CopyArrayUnsafe(items.GetPointerUnsafe(0), array.GetPointerUnsafe(0), array.Length);
            _items = items;
        }

        _count = array.Length;
    }
コード例 #8
0
        /// <summary>Initializes a new instance of the <see cref="UnmanagedValueList{T}" /> struct.</summary>
        /// <param name="array">The array that is used to populate the list.</param>
        /// <param name="takeOwnership"><c>true</c> if the list should take ownership of the array; otherwise, <c>false</c>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="array" /> is <c>null</c>.</exception>
        public unsafe UnmanagedValueList(UnmanagedArray <T> array, bool takeOwnership = false)
        {
            ThrowIfNull(array, nameof(array));

            if (takeOwnership)
            {
                _items = array;
            }
            else
            {
                var items = new UnmanagedArray <T>(array.Length, array.Alignment, zero: false);
                CopyArrayUnsafe <T>(items.GetPointerUnsafe(0), array.GetPointerUnsafe(0), array.Length);
                _items = items;
            }

            _count   = array.Length;
            _version = 0;
        }
コード例 #9
0
    /// <summary>Initializes a new instance of the <see cref="UnmanagedValueStack{T}" /> struct.</summary>
    /// <param name="span">The span that is used to populate the stack.</param>
    /// <param name="alignment">The alignment, in bytes, of the items in the stack or <c>zero</c> to use the system default.</param>
    /// <exception cref="ArgumentOutOfRangeException"><paramref name="alignment" /> is not a <c>power of two</c>.</exception>
    public UnmanagedValueStack(UnmanagedReadOnlySpan <T> span, nuint alignment = 0)
    {
        if (span.Length != 0)
        {
            var items = new UnmanagedArray <T>(span.Length, alignment);
            CopyArrayUnsafe(items.GetPointerUnsafe(0), span.GetPointerUnsafe(0), span.Length);
            _items = items;
        }
        else
        {
            if (alignment != 0)
            {
                ThrowIfNotPow2(alignment);
            }
            _items = UnmanagedArray <T> .Empty;
        }

        _count = span.Length;
    }
コード例 #10
0
        /// <summary>Initializes a new instance of the <see cref="UnmanagedValueList{T}" /> struct.</summary>
        /// <param name="span">The span that is used to populate the list.</param>
        /// <param name="alignment">The alignment, in bytes, of the items in the list or <c>zero</c> to use the system default.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="alignment" /> is not a <c>power of two</c>.</exception>
        public unsafe UnmanagedValueList(UnmanagedReadOnlySpan <T> span, nuint alignment = 0)
        {
            if (span.Length != 0)
            {
                var items = new UnmanagedArray <T>(span.Length, alignment, zero: false);
                CopyArrayUnsafe <T>(items.GetPointerUnsafe(0), span.GetPointerUnsafe(0), span.Length);
                _items = items;
            }
            else
            {
                if (alignment != 0)
                {
                    ThrowIfNotPow2(alignment, nameof(alignment));
                }
                _items = UnmanagedArray <T> .Empty;
            }

            _count   = span.Length;
            _version = 0;
        }