public static void Write <[Primitive] T>(this Span <byte> slice, T value) where T : struct { Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length); Span <T> castedSlice = slice.Cast <byte, T>(); castedSlice[0] = value; }
public static ReadOnlySpan <char> Slice(this string str, int start, int length) { Contract.Requires(str != null); Contract.RequiresInInclusiveRange(start, length, (uint)str.Length); return(new ReadOnlySpan <char>( str, new UIntPtr((uint)(SpanHelpers.OffsetToStringData + (start * sizeof(char)))), length )); }
public ReadOnlySpan(T[] array, int start, int length) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, length, (uint)array.Length); if (start < array.Length) { Object = array; Offset = UnsafeUtilities.GetElementAddress <T>((UIntPtr)SpanHelpers <T> .OffsetToArrayData, (UIntPtr)start); Length = length; } else { Object = null; Offset = UIntPtr.Zero; Length = 0; } }
/// <summary> /// Creates a new slice over the portion of the target array beginning /// at 'start' index and ending at 'end' index (exclusive). /// </summary> /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the slice.</param> /// <param name="end">The index at which to end the slice (exclusive).</param> /// <exception cref="System.ArgumentException"> /// Thrown if the 'array' parameter is null. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified start or end index is not in range (<0 or >&eq;length). /// </exception> public Slice(T[] array, int start, int end) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, array.Length); if (start < array.Length) { m_object = array; m_offset = new UIntPtr( (uint)(SliceHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>()))); Length = end - start; } else { m_object = null; m_offset = UIntPtr.Zero; Length = 0; } }
public ReadOnlySpan(T[] array, int start, int length) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, length, (uint)array.Length); if (start < array.Length) { Object = array; Offset = new UIntPtr( (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>()))); Length = length; } else { Object = null; Offset = UIntPtr.Zero; Length = 0; } }
/// <summary> /// Creates a new span over the portion of the target array beginning /// at 'start' index. /// </summary> /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the span.</param> /// <exception cref="System.ArgumentException"> /// Thrown if the 'array' parameter is null. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified start index is not in range (<0 or >&eq;length). /// </exception> // TODO: Should we have this overload? It is really confusing when you also have Span(T* array, int length) // While with Slice it makes sense it might not in here. internal Span(T[] array, int start) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, array.Length); if (start < array.Length) { _object = array; _offset = new UIntPtr( (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>()))); Length = array.Length - start; } else { _object = null; _offset = UIntPtr.Zero; Length = 0; } }
internal Span(T[] array, int start) { Contract.Requires(array != null); Contract.Requires(default(T) != null || array.GetType() == typeof(T[])); Contract.RequiresInInclusiveRange(start, (uint)array.Length); if (start < array.Length) { Object = array; Offset = UnsafeUtilities.GetElementAddress <T>((UIntPtr)SpanHelpers <T> .OffsetToArrayData, (UIntPtr)start); Length = array.Length - start; } else { Object = null; Offset = UIntPtr.Zero; Length = 0; } }
internal ReadOnlySpan(T[] array, int start) { Contract.Requires(array != null); Contract.RequiresInInclusiveRange(start, (uint)array.Length); if (start < array.Length) { Object = array; Offset = new UIntPtr( (uint)(SpanHelpers <T> .OffsetToArrayData + (start * UnsafeUtilities.SizeOf <T>()))); Length = array.Length - start; } else { Object = null; Offset = UIntPtr.Zero; Length = 0; } }
internal Span(T[] array, int start) { Contract.Requires(array != null); Contract.Requires(default(T) != null || array.GetType() == typeof(T[])); Contract.RequiresInInclusiveRange(start, (uint)array.Length); if (start < array.Length) { Object = array; Offset = new UIntPtr( (uint)(SpanHelpers <T> .OffsetToArrayData + (start * PtrUtils.SizeOf <T>()))); Length = array.Length - start; } else { Object = null; Offset = UIntPtr.Zero; Length = 0; } }
public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice) where T : struct { Contract.RequiresInInclusiveRange(PtrUtils.SizeOf <T>(), (uint)slice.Length); return(PtrUtils.Get <T>(slice.Object, slice.Offset, (UIntPtr)0)); }
public Span <T> Slice(int start) { Contract.RequiresInInclusiveRange(start, (uint)Length); return(new Span <T>(Object, Offset + (start * UnsafeUtilities.SizeOf <T>()), Length - start)); }
public Span <T> Slice(uint start, uint length) { Contract.RequiresInInclusiveRange(start, length, (uint)Length); return(new Span <T>( Object, UnsafeUtilities.GetElementAddress <T>(Offset, (UIntPtr)start), (int)length)); }
public Span <T> Slice(uint start) { Contract.RequiresInInclusiveRange(start, (uint)Length); return(new Span <T>(Object, Offset + (((int)start) * PtrUtils.SizeOf <T>()), Length - (int)start)); }
public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice) where T : struct { Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length); return(Unsafe.As <byte, T>(ref slice.DangerousGetPinnableReference())); }
public ReadOnlySpan <T> Slice(uint start, uint length) { Contract.RequiresInInclusiveRange(start, length, (uint)Length); return(new ReadOnlySpan <T>( Object, Offset + (((int)start) * PtrUtils.SizeOf <T>()), (int)length)); }
public ReadOnlySpan <T> Slice(uint start) { Contract.RequiresInInclusiveRange(start, (uint)Length); return(new ReadOnlySpan <T>(Object, UnsafeUtilities.GetElementAddress <T>(Offset, (UIntPtr)start), Length - (int)start)); }
public Span <T> Slice(int start, int length) { Contract.RequiresInInclusiveRange(start, length, (uint)Length); return(new Span <T>( Object, Offset + (start * PtrUtils.SizeOf <T>()), length)); }
/// <summary> /// Forms a slice out of the given span, beginning at 'start', and /// ending at 'end' (exclusive). /// </summary> /// <param name="start">The index at which to begin this slice.</param> /// <param name="end">The index at which to end this slice (exclusive).</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified start or end index is not in range (<0 or >&eq;length). /// </exception> public Span <T> Slice(int start, int end) { Contract.RequiresInInclusiveRange(start, end, Length); return(new Span <T>( m_object, m_offset + (start * PtrUtils.SizeOf <T>()), end - start)); }
public static void Write <[Primitive] T>(this Span <byte> slice, T value) where T : struct { Contract.RequiresInInclusiveRange(PtrUtils.SizeOf <T>(), (uint)slice.Length); PtrUtils.Set(slice.Object, slice.Offset, (UIntPtr)0, value); }
public Span <T> Slice(uint start, uint length) { Contract.RequiresInInclusiveRange(start, length, (uint)Length); return(new Span <T>( Object, Offset + (((int)start) * UnsafeUtilities.SizeOf <T>()), (int)length)); }
public ReadOnlySpan <T> Slice(int start) { Contract.RequiresInInclusiveRange(start, (uint)Length); return(new ReadOnlySpan <T>( Object, Offset + (start * PtrUtils.SizeOf <T>()), Length - start)); }
public ReadOnlySpan <T> Slice(int start, int length) { Contract.RequiresInInclusiveRange(start, length, (uint)Length); return(new ReadOnlySpan <T>( Object, Offset + (start * UnsafeUtilities.SizeOf <T>()), length)); }
public static T Read <[Primitive] T>(this ReadOnlySpan <byte> slice) where T : struct { Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length); return(slice.Cast <byte, T>()[0]); }
public static void Write <[Primitive] T>(this Span <byte> slice, T value) where T : struct { Contract.RequiresInInclusiveRange(Unsafe.SizeOf <T>(), (uint)slice.Length); Unsafe.WriteUnaligned <T>(ref slice.DangerousGetPinnableReference(), value); }