/// <summary> /// Initializes new instance of <see cref="SASLChallengeArguments"/> with given parameters. /// </summary> /// <param name="readArray">The array where to read the response sent by remote. May be <c>null</c> if no response was received yet.</param> /// <param name="readOffset">The offset in <paramref name="readArray"/> where the remote response starts.</param> /// <param name="readCount">The amount of bytes in <paramref name="readArray"/> reserved by remote response.</param> /// <param name="writeArray">The <see cref="ResizableArray{T}"/> where to write the response by the challenge. May not be <c>null</c>.</param> /// <param name="writeOffset">The offset in <paramref name="writeArray"/> where to start writing response by this challenge.</param> /// <param name="encoding">The <see cref="IEncodingInfo"/> used by the protocol. May be <c>null</c> if protocol is not textual.</param> /// <param name="credentials">The protocol specific credentials object. May be <c>null</c>.</param> /// <exception cref="ArgumentNullException">If <paramref name="writeArray"/> is <c>null</c>.</exception> public SASLChallengeArguments( Byte[] readArray, Int32 readOffset, Int32 readCount, ResizableArray <Byte> writeArray, Int32 writeOffset, IEncodingInfo encoding, Object credentials ) { if (readArray == null) { this.ReadArray = Empty <Byte> .Array; this.ReadOffset = this.ReadCount = -1; } else { this.ReadArray = readArray; this.ReadOffset = readOffset; this.ReadCount = readCount; } this.WriteArray = ArgumentValidator.ValidateNotNull(nameof(writeArray), writeArray); this.WriteOffset = writeOffset; this.Encoding = encoding; this.Credentials = credentials; }
public RenderCompositorLayer(int number, SpriteSheet baseSheet) { LayerNumber = number; _baseSheetArr = new ResizableArray <GPUDrawable>(); _baseSheet = baseSheet; SpriteSorted.Add(baseSheet, _baseSheetArr); }
/// <summary> /// Starting at given offset, writes given amount of elements from <paramref name="sourceArray"/> into this <see cref="ResizableArray{T}" /> /// </summary> /// <typeparam name="T">The type of elements in the <paramref name="array"/>.</typeparam> /// <param name="array">The <see cref="ResizableArray{T}" /></param> /// <param name="idx">The offset at which to start copying elements into the <paramref name="array"/>.</param> /// <param name="sourceArray">The array to read elements from.</param> /// <param name="offset">The offset at which to start reading elements from <paramref name="sourceArray"/>.</param> /// <param name="count">The amount of elements to write.</param> /// <returns>The <paramref name="array"/>.</returns> public static ResizableArray <T> WriteArray <T>(this ResizableArray <T> array, ref Int32 idx, T[] sourceArray, Int32 offset, Int32 count) { array.EnsureThatCanAdd(idx, count); Array.Copy(sourceArray, offset, array.Array, idx, count); idx += count; return(array); }
public static ResizableArray <Byte> WriteSByteToBytes(this ResizableArray <Byte> array, ref Int32 idx, SByte value) { array .EnsureThatCanAdd(idx, 1) .Array.WriteSByteToBytes(ref idx, value); return(array); }
private static ResizableArray <float> _softmaxBuffer(int ndim) { switch (ndim) { case 1: if (_softmaxBuffer1 == null) { _softmaxBuffer1 = new ResizableArray <float>(-1); } return(_softmaxBuffer1); case 2: if (_softmaxBuffer2 == null) { _softmaxBuffer2 = new ResizableArray <float>(-1, -1); } return(_softmaxBuffer2); default: if (_softmaxBuffer3 == null) { _softmaxBuffer3 = new ResizableArray <float>(-1, -1, -1); } return(_softmaxBuffer3); } }
/// <summary> /// Drops the actual item and stops the ability. /// </summary> private void DropItem() { // DropItem may be triggered by the animation event even when the ability isn't active. if (!IsActive) { return; } // Drop each item. If a drop prefab is specified then the item will be dropped. if (m_DroppedItems == null) { m_DroppedItems = new ResizableArray <GameObject>(); } else { m_DroppedItems.Clear(); } for (int i = 0; i < m_Items.Length; ++i) { if (m_Items[i] != null) { var droppedItem = m_Inventory.RemoveItem(m_Items[i].ItemIdentifier, m_Items[i].SlotID, 1, true); if (droppedItem != null) { m_DroppedItems.Add(droppedItem); } m_Items[i] = null; } } StopAbility(); }
public void AddLastRange(ReadOnlySpan <T> items) { lock (SyncRoot) { if (capacity <= buffer.Count + items.Length) { // calc remove count var remCount = Math.Min(buffer.Count, buffer.Count + items.Length - capacity); using (var ys = new ResizableArray <T>(remCount)) { for (int i = 0; i < remCount; i++) { ys.Add(buffer.RemoveFirst()); } CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs <T> .Remove(ys.Span, 0)); } } var index = buffer.Count; var span = items; if (span.Length > capacity) { span = span.Slice(span.Length - capacity); } foreach (var item in span) { buffer.AddLast(item); } CollectionChanged?.Invoke(NotifyCollectionChangedEventArgs <T> .Add(span, index)); } }
protected override void WriteMessageToBuffer(BackendABIHelper args, ResizableArray <Byte> array) { var idx = 0; array.Array .WriteByteToBytes(ref idx, (Byte)(this._isStatement ? 'S' : 'P')) .WritePgString(ref idx, args.Encoding, this._name); }
public void InitTests() { var array = new ResizableArray <int>(); Assert.AreEqual(0, array.Count); array = new ResizableArray <int>(20); Assert.AreEqual(20, array.Count); }
protected override void WriteMessageToBuffer(BackendABIHelper args, ResizableArray <Byte> array) { var idx = 0; array.Array .WritePgString(ref idx, args.Encoding, this._portalName) .WritePgInt32(ref idx, this._maxRows); }
/// <summary> /// Reads specific amount of bytes from <see cref="System.IO.Stream"/> into this resizable array, and returns the actual byte array. /// </summary> /// <param name="array">The <see cref="ResizableArray{T}"/>.</param> /// <param name="stream">The <see cref="System.IO.Stream"/>.</param> /// <param name="count">The amount of bytes to read.</param> /// <returns>The actual byte array containing the bytes read (and possibly any other data following after this, if the <see cref="ResizableArray{T}"/>'s array had that before calling this method).</returns> public static Byte[] ReadIntoResizableArray(this ResizableArray <Byte> array, System.IO.Stream stream, Int32 count) { array.CurrentMaxCapacity = count; var retVal = array.Array; stream.ReadSpecificAmount(retVal, 0, count); return(retVal); }
protected override void WriteMessageToBuffer(BackendABIHelper args, ResizableArray <Byte> array) { var idx = 0; array.Array .BlockCopyFrom(ref idx, this._pw) .WriteByteToBytes(ref idx, 0); }
public static Span <T> Flatten <T>(this ISpanSequence <T> sequence) { var position = Position.First; Span <T> firstSpan; // if sequence length == 0 if (!sequence.TryGet(ref position, out firstSpan, advance: true)) { return(Span <T> .Empty); } Span <T> secondSpan; // if sequence length == 1 if (!sequence.TryGet(ref position, out secondSpan, advance: true)) { return(firstSpan); } // allocate and copy Span <T> result; // if we know the total size of the sequence if (sequence.TotalLength != null) { result = new T[sequence.TotalLength.Value]; result.Set(firstSpan); result.Slice(firstSpan.Length).Set(secondSpan); int copied = firstSpan.Length + secondSpan.Length; Span <T> nextSpan; while (sequence.TryGet(ref position, out nextSpan, advance: true)) { nextSpan.CopyTo(result.Slice(copied)); copied += nextSpan.Length; } return(result); } else { var capacity = (firstSpan.Length + secondSpan.Length) * 2; var resizableArray = new ResizableArray <T>(capacity); firstSpan.CopyTo(ref resizableArray); secondSpan.CopyTo(ref resizableArray); Span <T> nextSpan; int copied = firstSpan.Length + secondSpan.Length; while (sequence.TryGet(ref position, out nextSpan, advance: true)) { while (copied + nextSpan.Length > resizableArray.Capacity) { var newLength = resizableArray.Capacity * 2; resizableArray.Resize(newLength); } nextSpan.CopyTo(ref resizableArray); copied += nextSpan.Length; } return(resizableArray._array.Slice(0, copied)); } }
public static ResizableArray <Byte> ZeroOut(this ResizableArray <Byte> array, ref Int32 idx, Int32 count) { if (count > 0) { array.FillWithOffsetAndCount(idx, count, (Byte)0); idx += count; } return(array); }
private readonly ResizableArray <Byte> _clientMessage; // Temporary storage for data to be preserved between Challenge invocations public SASLMechanismSCRAMForClient( BlockDigestAlgorithm algorithm, Func <Byte[]> clientNonceGenerator ) { this._algorithm = ArgumentValidator.ValidateNotNull(nameof(algorithm), algorithm); this._nonceGenerator = clientNonceGenerator; this._clientMessage = new ResizableArray <Byte>(exponentialResize: false); }
protected override async Task PerformSendAfterWriteAsync( BackendABIHelper args, Stream stream, Int32 size, CancellationToken token, ResizableArray <Byte> array ) { await stream.WriteAsync(this._data, this._offset, this._count, token); }
public void OldToSpan() { SequencePosition position = Sequence.Start; ResizableArray <byte> array = new ResizableArray <byte>(1024); while (Sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer)) { array.AddAll(buffer.Span); } var Result = array.Span; }
/// <summary> /// Get all materials of a mesh. /// </summary> static public Graphics.Materials.MaterialAPI[] GetMaterials(this ModelMesh mesh) { ResizableArray <Graphics.Materials.MaterialAPI> ret = new ResizableArray <Graphics.Materials.MaterialAPI>(); foreach (Effect effect in mesh.Effects) { ret.Add(effect.Tag as Graphics.Materials.MaterialAPI); } ret.Trim(); return(ret.InternalArray); }
public static ReadOnlySpan <byte> ToSpan(this ReadOnlySequence <byte> sequence) { SequencePosition position = sequence.Start; ResizableArray <byte> array = new ResizableArray <byte>(1024); while (sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer)) { array.AddAll(buffer.Span); } return(array.Span); }
public static ReadOnlySpan <byte> ToSingleSpan <T>(this T memorySequence) where T : ISequence <ReadOnlyMemory <byte> > { Position position = Position.First; ReadOnlyMemory <byte> memory; ResizableArray <byte> array = new ResizableArray <byte>(1024); // TODO: could this be rented from a pool? while (memorySequence.TryGet(ref position, out memory)) { array.AddAll(memory.Span); } return(array.Items.Slice(0, array.Count)); }
public DataRowColumnSUKSWithConnectionFunctionality( DataColumnMetaData metadata, Int32 thisStreamIndex, ResizableArray <Byte> byteArray, DataRowColumnSUKS[] allDataRowStreams, TConnectionFunctionality connectionFunctionality, ReservedForStatement reservedForStatement ) : base(metadata, thisStreamIndex, byteArray, allDataRowStreams) { this.ConnectionFunctionality = ArgumentValidator.ValidateNotNull(nameof(connectionFunctionality), connectionFunctionality); this.ReservedForStatement = ArgumentValidator.ValidateNotNull(nameof(reservedForStatement), reservedForStatement); }
public static ReadOnlySpan <byte> ToSpan <T>(this T sequence) where T : ISequence <ReadOnlyMemory <byte> > { SequencePosition position = sequence.Start; ResizableArray <byte> array = new ResizableArray <byte>(1024); while (sequence.TryGet(ref position, out ReadOnlyMemory <byte> buffer)) { array.AddAll(buffer.Span); } array.Resize(array.Count); return(array.Span.Slice(0, array.Count)); }
public StringFormatter(int characterCapacity = 32, ArrayPool <byte> pool = null) { if (pool == null) { _pool = ArrayPool <byte> .Shared; } else { _pool = pool; } _buffer = new ResizableArray <byte>(_pool.Rent(characterCapacity * 2)); }
private ResizableArray <T> InitializeVertexAttribute <T>(T[] attributeValues) { if (attributeValues != null && attributeValues.Length == vertices.Length) { var newArray = new ResizableArray <T>(0); newArray.Resize(attributeValues.Length); var newArrayData = newArray.Data; Array.Copy(attributeValues, 0, newArrayData, 0, attributeValues.Length); return(newArray); } return(null); }
public DataRowColumnSUKS( DataColumnMetaData metadata, Int32 thisStreamIndex, ResizableArray <Byte> byteArray, DataRowColumnSUKS[] allDataRowStreams ) : base(metadata, thisStreamIndex) { this.ByteArray = ArgumentValidator.ValidateNotNull(nameof(byteArray), byteArray); this._totalBytesRead = 0; this._byteCount = new ReadOnlyResettableAsyncLazy <Int32>(async() => await this.ReadByteCountAsync()); this._allStreams = ArgumentValidator.ValidateNotEmpty(nameof(allDataRowStreams), allDataRowStreams); this._transitionFunc = async unused => await this.ReadByteCountAsync(); }
public static ReadOnlySpan <byte> ToSpan <T>(this T bufferSequence) where T : ISequence <ReadOnlyBuffer <byte> > { Position position = Position.First; ReadOnlyBuffer <byte> buffer; ResizableArray <byte> array = new ResizableArray <byte>(1024); while (bufferSequence.TryGet(ref position, out buffer)) { array.AddAll(buffer.Span); } array.Resize(array.Count); return(array.Items.Slice(0, array.Count)); }
public static ReadOnlySpan <byte> ToSpan <T>(this T memorySequence) where T : ISequence <ReadOnlyMemory <byte> > { Position position = Position.First; ReadOnlyMemory <byte> memory; ResizableArray <byte> array = new ResizableArray <byte>(memorySequence.Length.GetValueOrDefault(1024)); while (memorySequence.TryGet(ref position, out memory)) { array.AddAll(memory.Span); } array.Resize(array.Count); return(array.Items.Slice(0, array.Count)); }
/// <summary> /// Decimates the mesh without losing any quality. /// </summary> public override void DecimateMeshLossless() { int deletedTris = 0; ResizableArray <bool> deleted0 = new ResizableArray <bool>(0); ResizableArray <bool> deleted1 = new ResizableArray <bool>(0); var triangles = this.triangles.Data; int triangleCount = this.triangles.Length; int startTrisCount = triangleCount; var vertices = this.vertices.Data; ReportStatus(0, startTrisCount, startTrisCount, -1); for (int iteration = 0; iteration < 9999; iteration++) { // Update mesh constantly UpdateMesh(iteration); triangles = this.triangles.Data; triangleCount = this.triangles.Length; vertices = this.vertices.Data; ReportStatus(iteration, startTrisCount, triangleCount, -1); // Clear dirty flag for (int i = 0; i < triangleCount; i++) { triangles[i].dirty = false; } // All triangles with edges below the threshold will be removed // // The following numbers works well for most models. // If it does not, try to adjust the 3 parameters double threshold = DoubleEpsilon; if (verbose) { Logging.LogVerbose("Lossless iteration {0}", iteration); } // Remove vertices & mark deleted triangles RemoveVertexPass(startTrisCount, 0, threshold, deleted0, deleted1, ref deletedTris); if (deletedTris <= 0) { break; } deletedTris = 0; } CompactMesh(); }
public void ArrayAppend() { var values1 = new[] { 1, 2, 3, 4 }; var values2 = new[] { 5, 6 }; var array = new ResizableArray <int>(values1); array.Append(values2); var combined = values1.ToList(); combined.AddRange(values2); CollectionAssert.AreEqual(combined, array); }
protected sealed override async Task PerformSendAfterWriteAsync( BackendABIHelper args, Stream stream, Int32 size, CancellationToken token, ResizableArray <Byte> array ) { // Given size includes the integer that already has been written size -= sizeof(Int32); array.CurrentMaxCapacity = size; this.WriteMessageToBuffer(args, array); await stream.WriteAsync(array.Array, 0, size, token); }
public ArrayFormatter(int capacity, EncodingData encoding, ArrayPool<byte> pool = null) { _pool = pool != null ? pool : ArrayPool<byte>.Shared; _encoding = encoding; _buffer = new ResizableArray<byte>(_pool.Rent(capacity)); }
public StringFormatter(int characterCapacity = 32, ArrayPool<byte> pool = null) { if (pool == null) _pool = ArrayPool<byte>.Shared; else _pool = pool; _buffer = new ResizableArray<byte>(_pool.Rent(characterCapacity * 2)); }